Hello, all. This should be a straightforward issue that doesn't require me posting blocks, but if I'm wrong, please tell me. I'll subsequently post my coding.
I'm creating a basic platformer. Strangely, my biggest problem that has arisen is in the form of playing an animation on cue. I have set up a broadcast that will switch the character's sprite between the running costumes. When my character moves left or right (using an 'if key pressed? statement'), that broadcast is carried out - for every single frame. So, the running animation isn't actually played - only the first costume is shown because the broadcast is run every single frame. Then, whenever the keys are released, the character begins the running animation and does so indefinitely (and when I try to put an 'else' regarding if the key is not pressed, the character won't move at all). I've tried countless rectifications, all to no avail. It is very frustrating.
There has to be a straightforward fix to this; I know it. Any suggestions?
Here's an example of my blocks, using the right arrow key command:
forever if key [right arrow] pressed? point in direction (90) move [runSpeed] steps if [nowRunning] = (0) set [nowRunning] to (1) broadcast [running] end end when I receive [running] repeat until [nowrunning] = (0) wait [runanimDelay] secs switch to costume [run1] repeat (3) wait [runanimDelay] secs next costume end end
Offline
JohntheDreamer wrote:
Hello, all. This should be a straightforward issue that doesn't require me posting blocks, but if I'm wrong, please tell me. I'll subsequently post my coding.
forever if (key [right arrow v] pressed?) point in direction (90) move [runSpeed v] steps if <(nowRunning ) = (0)> set [nowRunning v] to (1) broadcast [running v] end end when I receive [running v] repeat until <(nowrunning) = (0)> wait (runanimDelay) secs switch to costume [run1 v] repeat (3) wait (runanimDelay) secs next costume end end
Fixed.
Anyway, the problems I see is that nothing is resetting nowrunning when you're not running. So, maybe try this instead:
forever if (key [right arrow v] pressed?) point in direction (90) move [runSpeed v] steps if <(nowRunning ) = (0)> set [nowRunning v] to (1) broadcast [running v] end else set [running v] to (0) end when I receive [running v] repeat until <(nowrunning) = (0)> wait (runanimDelay) secs switch to costume [run1 v] repeat (3) wait (runanimDelay) secs next costume end endAbout the broadcasts being repeated over and over, I can see nothing in the scripts you posted that could cause this, so I think that the problem is else where. Is there some way for you to show the rest of your scripts?
Last edited by ErnieParke (2012-10-29 15:41:50)
Offline
Here's a screenshot of all the blocks and variables...the block that's cut off is the same as the one above it.
Still having problems at this point. I want nowRunning to equal 0 when the keys aren't pressed, but they instead cancel out the other key. The animation won't play at all now.
http://oi49.tinypic.com/119mbg9.jpg
Offline