Weirdness with spritetranslate - what am i missing?

Started by jaymzjulian, October 29, 2019, 02:32:59 AM

Previous topic - Next topic

jaymzjulian

I was having all sorts of weird problems with 2d sprites (you'd think 3d would be harder than 2d, right?!), So i made a simple test to try and do a set of sprites in a straight line - and even that I couldn't seem to manage, but I feel like I'm missing some fundamental concept, because my understanding indicates that this should work:


' set our lines
dim grid_row_gridentry[64]

call ScaleSprite(64)

' define these in a row
for c = 1 to 64
  ' define Move then draw - this obv sucks, but POC, yo.
  grid_row_gridentry[c] = LinesSprite({ _
      {MoveTo, 0,0}, _
      {DrawTo, 5,5} _
      })
  ' and translate them to be all in a row
  call SpriteTranslate(grid_row_gridentry[c], {c-32, 0})
next

display_line = 0
controls = WaitForFrame(JoystickNone, Controller1, JoystickNone)
while controls[1,3] = 0
  controls = WaitForFrame(JoystickNone, Controller1, JoystickNone)
endwhile


It has the MoveTo to start at 0,0, and there is no y translate at all - so I don't fully understand why it's also y-translating each line (I acutally end up with kind of an arc on the screen....).  Weirder still, if i do this:

call ScaleSprite(64)
q = LinesSprite({{MoveTo, 0,0}, {DrawTo, 5,5}})
r = LinesSprite({{MoveTo, 0,0}, {DrawTo, 5,5}})                                                                         
display_line = 0
controls = WaitForFrame(JoystickNone, Controller1, JoystickNone)
while controls[1,3] = 0
  display_line = ( display_line + 1 ) mod 64
  controls = WaitForFrame(JoystickNone, Controller1, JoystickNone)
  call SpriteTranslate(q, {display_line, 0})                                                                              call SpriteTranslate(r, {display_line-32, 0})                                                                         endwhile


You'd think I'd get two sprites chasing each other, right..... but instead I get two sprites offset from each other, and one goes at double the speed of the other.  So clearly SpriteTranslate does NOT do what i think it does.... it almost seems to be global? 

I'm quite sure there is something fundamental...




Vectrex32

For the first sprite, you move to (0, 0) and draw to (5,5). At this point, the pen is at (5,5). The second sprite is translated relative from there, i.e. translated from (5, 5) not from (0, 0).

If your sprite were a closed object, i.e. the last line ended at the same point the first line started, you would not have noticed a problem.

Hope this helps.

- Bob

jaymzjulian

Quote from: Vectrex32 on October 29, 2019, 08:49:19 AM
For the first sprite, you move to (0, 0) and draw to (5,5). At this point, the pen is at (5,5). The second sprite is translated relative from there, i.e. translated from (5, 5) not from (0, 0).

If your sprite were a closed object, i.e. the last line ended at the same point the first line started, you would not have noticed a problem.

Hope this helps.

- Bob

Ahh, So the thing I missed is that MoveTo is not absolute, but relative, right?  Cool, I can totally work with that.  thanks!

Vectrex32


jaymzjulian

Awesome.  Got it.  Thanks for the clarification - on second reading of the manual, it's totally spelled out in there too, but somehow I managed to get it flipped in my brain :).

Vectrex32

Well, the two manuals add up to 120 pages, so if some part of it slipped your mind, we'll allow it. This time.

;)

- Bob