|
Post by daveysloan on Apr 17, 2024 6:18:56 GMT
Hi,
I'm making a simple platform game & looking to give my character 2 or 3 frames of animation when they're standing still. Does anyone know of an efficient way to do this? Thanks
|
|
mas
Processing Plant
Posts: 28
|
Post by mas on Apr 17, 2024 16:13:47 GMT
I think you probably need 2 alternate sprites (one for facing left, one for right - unless the sprite faces towards the screen), a timer (so it triggers after a few seconds of inactivity) and way of tracking a key has been pressed.
If you're having a standard timer to count the seconds, on a keypress I'd zero an inactivity count. If the inactivity count gets > 3 seconds I'd switch the image to the "bored sprite" animation. I'd then, if the player image is the "bored sprite image" I'd animate slow until a key is pressed. On keypress, you zero the inactivity timer, change the sprite back to the correct left or right image and carry on.
Or you could do the standard "death animation thing" if you want the sequence to play out and change the sprite type... but I'd probably just swap images.
|
|
mas
Processing Plant
Posts: 28
|
Post by mas on Apr 18, 2024 14:41:44 GMT
Expanding a bit on the previous.
If we have a timer running with M, S, and F (Minutes, Seconds, Frames - assuming 25/second) running on the mainevent1 for "whatever reason" we can set another variable, say P, for "player inactivity in seconds"
If we assume IMAGE 0 and IMAGE 1 are your left right sprite images, and IMAGE 2 is your bored animation, you'll have something like the following in the player event. (typed from brain, not 100% checked)
IF IMAGE <> 2 ; don't respond if the sprite is bored IF KEY LEFT LET DIRECTION = LEFT LET IMAGE = 0 ANIMATE SLOW IF CANGOLEFT SPRITELEFT ENDIF LET P = 0 ; player inactivity reset ENDIF
IF KEY RIGHT LET DIRECTION = RIGHT LET IMAGE = 1 ANIMATE SLOW IF CANGORIGHT SPRITERIGHT ENDIF LET P = 0 ENDIF ENDIF
IF F > 23 ; I'm assuming a 25 fps loop, just updating P everytime it hits 23 to avoid reset of F clashes ADD 1 TO P ENDIF
IF P > 2 LET IMAGE = 2 ANIMATE IF P > 5 LET P = 0 ; reset after a couple of seconds of the animation IF DIRECTION = LEFT LET IMAGE = 0 LET FRAME = 0 ELSE LET IMAGE = 1 LET FRAME = 0 ENDIF ENDIF ENDIF
|
|
|
Post by daveysloan on Apr 18, 2024 21:04:50 GMT
This is fantastic, thanks so much for this.
|
|