Discuss Scratch

AcademicNinja
Scratcher
44 posts

Strange Thing Happening When I'm Switching the Costumes of a Character

Hello! I'm working on a platformer game. Right now, I want to get my character to change costumes when I press Space. However, when I do that and the costume changes, the character freezes, unable to move left or right until it switches back to the normal costume. Could you take a look at it and let me know what the problem is?

scratch.mit.edu/projects/170554708

Last edited by AcademicNinja (Aug. 6, 2017 09:48:19)

Scratch-Minion
Scratcher
1000+ posts

Strange Thing Happening When I'm Switching the Costumes of a Character

That is the way you have coded it.
Moving left or right and changing costumes are in the same loop. When you wait 0.2 seconds while changing costumes, the whole loop waits and doesn't get back to check arrow keys.

There are a few ways to solve this. Here are some:

1) Use a broadcast if the space key has been pressed. Then the changing costumes and wait 0.2s is in a separate script which will not hold up your loop. (Do not use “broadcast and wait” or nothing will change).

2) Put the code testing for space in a separate loop.

3) Use a “When space key pressed” block.
AcademicNinja
Scratcher
44 posts

Strange Thing Happening When I'm Switching the Costumes of a Character

Thank you very much, I used the “broadcast” method, and now it works perfectly!
mstone326
Scratcher
1000+ posts

Strange Thing Happening When I'm Switching the Costumes of a Character

Also, to simplify your costume changes. You don't need left and right facing costumes. You are already pointing in direction in your scripts. So you only need a costume that faces right and a costume that faces right punching. Let the point in direction handle pointing left and right. Then you can simplify the punch script to, if key space pressed, broadcast punch.

Wanted to throw this out there in case you started creating leg movement with the animation, didn't want you to create all the sprites costumes for facing left and right. Just note that using this method, when you draw your sprite they have to face the right.

https://scratch.mit.edu/projects/170611368/

Last edited by mstone326 (Aug. 6, 2017 14:55:12)


High School Athletic Director / Middle School Tech Teacher / High School Baseball Coach
Kung Fu by Nintendo 1984 - https://scratch.mit.edu/projects/369994801/
Taco Defense - Speed Typing - https://scratch.mit.edu/projects/316795450/
Halloween Boss Battle - Taking Back our Woods - https://scratch.mit.edu/projects/257155118/
Almost Pong - https://scratch.mit.edu/projects/656276979/
Studio - My Best Projects - https://scratch.mit.edu/studios/4125978/
Forum Help Project Examples - https://scratch.mit.edu/studios/4133335
AcademicNinja
Scratcher
44 posts

Strange Thing Happening When I'm Switching the Costumes of a Character

Ah, I didn't think about that, thank you again, @mstone326! Looks like I'll have to add you to the credits again XD
And, as a note, I was actually planning in making leg movement, thank you for telling me before I went on with that!

P.S - Do you have any idea how I could make a combo of punches, when space is pressed repeatedly? Right now I have two punches in a row, but they are triggered by a single space.

Last edited by AcademicNinja (Aug. 7, 2017 09:31:38)

Powered by DjangoBB