LoginLogin

Deleting a sprite

Root / Programming Questions / [.]

ChaseCZCreated:
SpoilerLet's say you have a game that uses touch screen. there is a strawberry and a plate, if you grab the strawberry, it'll spawn another strawberry with which you can move however you want, if you let it go, it will go back to the strawberry you took it from and then disappears, but if the strawberry touches the plate and you let it go, it will go to the middle of the plate. So now let's talk about the problem... To spawn another strawberry i use code that looks somehow like this:
O=SPSET(0)
That means when you spawn a strawberry the management number goes up. I already made so O goes to 0 after goijg back to the base strawberry, but that didn't change anything at all. Everytime i spawn another one, the management number is 1 time bigger than before, it basically skips the number that is already used. When i try SPCLRing the O it finds many errors because i use O in SPOFS,SPANIM etc. So what should i do to fix it? I'll try to tell you as much information about my program as you need to know

Well, the basic answer is to just design your code in a way that you aren't using SPOFS, etc. on deleted sprites. The simplest just-make-it-work solution would be to wrap those commands in an IF SPUSED(O) THEN. However, you may want to look into SPFUNC when it comes to designing more complex programs.

Yeah, thanks. I tried looking at SPFUNC before, but i didn't understand it at all, but that's because i was looking at it in someone's program

SPFUNC just lets you attach a function to a sprite and run it with CALL SPRITE. Example:
SPSET 0,1
SPFUNC 0,"TEST"
SPHOME 0,8,8

WHILE 1
 VSYNC
 CALL SPRITE
WEND

DEF TEST
 SPOFS CALLIDX,200+SIN(6.2831*(MAINCNT/90))*32,120
END

Ooooohhhh... Yeeeaaah... 🤔 And what exactly does CALLIDX do?

CALLIDX is a variable that stores the ID of the sprite that called the function.

Oh... Looks like i'm gonna use it