|
Post by megatondan on Feb 5, 2017 16:07:46 GMT
Hi all!
I have a question that I'm sure is really easy but my coding skills are not what they used to be. Hopefully that makes it an easy one to answer....
All I want to happen is to replace the player sprite on collision with an enemy. I've been trying this in a veriety of events and places (type 0 at the top or after the spriteleft, kill, sprite 1) with this code: If collision 1 let image =7 animate endif
It's a default patrolling U/D enemy. Maybe that's bad code or I'm not understanding where to place it.
This is my first game for any platform! It's been (mostly) easy with Paul's tutorial vids and some willingness to experiment. The game is a simple JSW platformer. I kept it to 3 screens just to finish the project and I'm nearly there!
Thanks Dan
|
|
|
Post by andrewvanbeck on Feb 7, 2017 7:38:13 GMT
I'm not seeing anything that should stop it working, maybe you need to add a little logic for what happens when the player is using image 7. Like say you wanted the player to drop out of the screen when they die: IF IMAGE 7 ANIMATE ADD 3 TO X IF X > 180 KILL ENDIF EXIT ENDIF
So after you collide with 1, just set the image to 7 and EXIT - then the player will start dropping, and when they get delow X 180 they die properly.
|
|
|
Post by alessandro on Feb 7, 2017 14:16:20 GMT
You must use a different sprite type for the "sprite destroyed" event, not just change the appearance of the player character sprite. Otherwise it will continue to behave like the character itself, e.g. moving at the key press etc.
When the player character sprite - or any other character - must "die", just SPAWN a "death animation" sprite at the character sprite's position and REMOVE the latter.
For example, let's suppose that the "death animation" sprite is set to type 8 and image number 6, and the enemy's sprite is set to type 3:
IF COLLISION = 3 ; if the player character sprite collides with sprite type 3 SPAWN 8 6 ; spawn the "death animation" sprite REMOVE ; remove the player character sprite ENDIF
Remember to insert a counter and a RESTART command, and possibly a DELAY, in the "death animation" sprite event so that after displaying the animation for a short while, and maybe a small pause, the screen restarts.
|
|
|
Post by andrewvanbeck on Feb 7, 2017 14:36:02 GMT
It is safe, so long as you remember an EXIT command, so the actual control logic gets ignored. Like a check at the start of the player event, if the image is 7 then handle the death but exit before any other code that might interfere. I do this in a current project, when the player collides with an enemy, I set the image to 2, and at the start of my event 0 code I check for image 2, and have the sprite drop off the screen, only killing the player once they reach the bottom. I often use the image to decide how to handle an object, different enemies with slightly different behaviour I mean. I do tend to always have an effects event, that just plays the animation then removes the sprite, but it can get fiddly to ensure that a death animation plays through before the screen is restarted, so I would tend to only KILL the player once the death sequence is complete.
|
|
|
Post by megatondan on Feb 7, 2017 16:35:16 GMT
Ah, this makes sense, I will try the respawn method tonight. I had noticed that it worked if I removed all KILL instructions. But that's no use!
Thanks for the tips everyone.
|
|