LoginLogin

CALL SPRITE

Root / Programming Questions / [.]

ProKukuCreated:
I’d like to know how to use CALL SPRITE, along with commands that go with it like SPFUNC and CALLIDX. I got some help from someone a while ago and they used CALL SPRITE, SPFUNC and CALLIDX, but I never really figured out how they work together. I didn’t see another forum post addressing this exact topic yet, so I decided I should make one, rather than asking on chat like I always do.

http://smilebasicsource.com/forum?fpid=19365#post_19365
'initialize some sprites
SPSET 0,1
SPSET 1,2

'a function that will serve as our sprite callback, 
'evaluated each time CALL SPRITE is executed
DEF MYFUNC
  'log the current ID
  'note that it alternates, going through both id 0 and 1 each call
  '(you can use additional logging to verify this)
  ?CALLIDX

  VAR X, Y
  'use OUT form of SPOFS to get position
  'special var CALLIDX represents sprite ID being evaluated
  SPOFS CALLIDX OUT X, Y

  'normal SPOFS using CALLIDX
  SPOFS CALLIDX, X+1, Y+1+CALLIDX 'just to differentiate sprites
END

'attach MYFUNC to sprites
SPFUNC 0, "MYFUNC"
SPFUNC 1, "MYFUNC

WHILE 1
  VSYNC

  'evaluate sprite callbacks in a loop
  CALL SPRITE
  'since we attached MYFUNC which moves the sprite every frame
  'the two sprites will move across the screen
WEND

http://smilebasicsource.com/forum?fpid=19365#post_19365
I saw that post already, it just wasn’t as in-depth as I was wanting. Thanks anyway for the source code though.

DYK that
FOR I = 0 TO 511
SPSET I,0
SPVAR I,0,20
SPVAR I,1,50
SPVAR I,2,12
SPFUNC I, "WP"
NEXT
DEF WP
VAR X = SPVAR(CALLIDX,0),Y=SPVAR(CALLIDX,1),Z=SPVAR(CALLIDX,2)
 SPOFS CALLIDX, 200+(X/Z),120+(Y/Z)
SPSCALE CALLIDX,1/Z,1/Z
END
CALL SPRITE
Is a LOT faster than
DEF WP ID,X,Y,Z
 SPOFS ID, 200+(X/Z),120+(Y/Z)
SPSCALE ID,1/Z,1/Z
END
'--initialize sprites, doesn't count
FOR I = 0 TO 511
SPSET I,0
NEXT
'THIS counts because it is the doing the same thing as CALL SPRITE
FOR I = 0 TO 511
WP I,20,50,12
NEXT
I think it would be useful in 3D engines EDIT: CALL sprite is faster than a FOR loop, basically