Discuss Scratch
- Discussion Forums
- » Help with Scripts
- » help with walking animations
- gUuaAc
-
Scratcher
6 posts
help with walking animations
yo so I've been working on a project where it's one of those top down pixel art games. I mean it's been going pretty well, as I've already completed the animation and just need to code it. to give you some context of what i have so far, I have sprites for four directions and a idle animation with two sprites for each direction. for example, lets say that i want to move left. as you obviously know what happens next, i succeed in doing so. and then i stop. the idle animation for the LEFT triggers because i stopped my character facing LEFT. same applys when going forward, back, and right. anyways, these sprites interchange repeatedly until the character moves. However, i've been trying to make it so when i move another direction than the one i originally faced, the other idle animations for the other directions dont play. its been bugging me that if i wanna move right lets say, then the idle animations for the other directions play since i put the code liek this (if not pressed? then: wait .10 seconds, switch costume to idle 1, wait .10 seconds, switch costume to idle2. if you dont get a clue at what im saying, then check out my project link below. https://scratch.mit.edu/projects/891024774
- MasterofTheBrick
-
Scratcher
1000+ posts
help with walking animations
Currently you’re forcing the animation loops to run simultaneously in separate loops which explains why they’re constantly overriding one another. A more systematic way would be to assign a value to a variable storing the last key pressed by the user (under userMove), and only running the top-down-left-right animations when the variable matches the assigned keys respectively (e.g. a conditional under userLeft).
- gUuaAc
-
Scratcher
6 posts
help with walking animations
OMG TYSM YOU'RE A LIVE-SAVER, MASTER OF BRICK! I'm really new to scratch and I never knew it had this much of a community.
- gUuaAc
-
Scratcher
6 posts
help with walking animations
Currently you’re forcing the animation loops to run simultaneously in separate loops which explains why they’re constantly overriding one another. A more systematic way would be to assign a value to a variable storing the last key pressed by the user (under userMove), and only running the top-down-left-right animations when the variable matches the assigned keys respectively (e.g. a conditional under userLeft).Yeah so i kinda got this thing where the last sprite of the idle animation from the last direction plays after you go to a different one. Once you see my game link, you'll see what I mean
–> https://scratch.mit.edu/projects/891024774
- gUuaAc
-
Scratcher
6 posts
help with walking animations
actually im fine i just fixed the bug sorry for bothering you so muchCurrently you’re forcing the animation loops to run simultaneously in separate loops which explains why they’re constantly overriding one another. A more systematic way would be to assign a value to a variable storing the last key pressed by the user (under userMove), and only running the top-down-left-right animations when the variable matches the assigned keys respectively (e.g. a conditional under userLeft).Yeah so i kinda got this thing where the last sprite of the idle animation from the last direction plays after you go to a different one. Once you see my game link, you'll see what I mean
–> https://scratch.mit.edu/projects/891024774
- MasterofTheBrick
-
Scratcher
1000+ posts
help with walking animations
Your code could be cleaned up, it’s slightly redundant the last I checked. There’s no need to have four separate ‘if’ control blocks, neither is there a need for an additional 4 variables (left right up down) just to store a fixed value, directly inputting the key’s value into lastkeypressed is sufficient.
Likewise under the assigned custom block:
… ::grey
if <key [w v] pressed?> then
change y by [4]
set [lastkey v] to [w]
end
… ::grey
Likewise under the assigned custom block:
if <(Lastkey)=[w]> then
switch costume to [ups.1 v]
…::grey
end
- Discussion Forums
- » Help with Scripts
-
» help with walking animations

