Enemies with their own attack hitbox

Root / Programming Questions / [.]

Hi I need help adding an multiple spawned enemies to have there sprite hitbox when attacking player. The hitbox would only last a second clearing itself. Thanks

I’m not sure exactly what you’re asking for.

Hi, well I have multiple enemies on screen lets say 3 enemies. I chose a spdef to spawn to indicate an attack hitbox sprite. It works with sprite id I give, but if 2 characters are attacking at the same time it doesn't spawn their own copy of the hitbox sprite even with "spset id out" is set. Right now I have all the characters spawning that same sprite id. Another example is have multiple enemies shoot the same projectile sprite at the same time. The enemies are being ran by spfunc. Thanks

What it seems like you’re saying is that whenever a new sprite is created, it uses the same sprite id. But you can only have one sprite with a specific id. So you have SPSET ID,IMG. You have to change ID for every sprite. IMG can stay the same but if ID is reused it will delete the previous sprite that had that id. But SPSET has multiple ways it can be used. The one I think you’d need is SPSET R1,R2,IMG OUT ID. R1 is the lowest ID can be, and R2 is the highest. IMG is what the sprite should look like and ID is a variable that gets set to whatever ID the function chooses for you. This allows you to select a range of different IDs, say 0-31 for example, and it’ll pick one for you. That way you can set sprites with the same “settings” but a different ID so it doesn’t remove other sprites. Example:

DEF SPAWN'Spawns a sprite
 SPSET 0,31,0 OUT ID

 IF ID==-1 THEN RETURN'This function returns -1 if every sprite in the range is already being used

 SPOFS ID,200,120'Set initial stuff for the sprite, in this case the position

 'Store position with SPVAR
 SPVAR ID,0,200
 SPVAR ID,1,120


DEF MOVE'Doesn't actually move things lol
 'Do your logic here
 'Changing the sprite’s position
Hope I didn’t just confuse you. If you have questions, let me know.

Thanks rando, I was heading in this direction. I'm not sure if this makes a difference.. I have a DEF that spawns the enemies and another "DEF Move" that does all of the enemies movements and attack. Can I call a DEF to spawn more sprites within the "DEF Move" function? In other words can spawned objects also spawn objects. Thanks again

You mean like if a monster wanted to shoot a bullet? You can do that for sure. You might have to figure out how to do that, like timing and stuff, but you can definitely call a spawn function inside a movement function.

Oh ok thanks