This is a read-only archive of the old Scratch 1.x Forums.
Try searching the current Scratch discussion forums.

#1 2011-09-14 01:12:58

cr3al
New Scratcher
Registered: 2011-09-13
Posts: 2

Issues with Using arrow keys to move sprite

Im trying to make a pac man clone, writing a script for my pacman sprite to move in the direction of the arrow key pressed. the issue im having is the costumes are not switching correctly and when i use the point in direction block it moves the sprite diagonal a little bit before pointing in the direction. I want him to change to the right direction but i dont want to sprite to shift slightly every time you do.  so when i do this with all 4 arrow keys only 2 change costumes and they dont change to the correct costume specified in the block, it does move in the correct direction 10 steps but like i said early it moves diagonal first.  i checked out the different costumes and when i cycle through them they seem to be ontop of one another so i dont think it has to do with a costume sprite being in a slightly different position.

script is
when (left arrow) clicked
switch costume (sprite right)
point direction (right)
move (15) steps

any ideas?

Offline

 

#2 2011-09-14 14:16:56

slammer111
New Scratcher
Registered: 2011-09-01
Posts: 33

Re: Issues with Using arrow keys to move sprite

cr3al wrote:

Im trying to make a pac man clone, writing a script for my pacman sprite to move in the direction of the arrow key pressed. the issue im having is the costumes are not switching correctly and when i use the point in direction block it moves the sprite diagonal a little bit before pointing in the direction. I want him to change to the right direction but i dont want to sprite to shift slightly every time you do.  so when i do this with all 4 arrow keys only 2 change costumes and they dont change to the correct costume specified in the block, it does move in the correct direction 10 steps but like i said early it moves diagonal first.  i checked out the different costumes and when i cycle through them they seem to be ontop of one another so i dont think it has to do with a costume sprite being in a slightly different position.

script is
when (left arrow) clicked
switch costume (sprite right)
point direction (right)
move (15) steps

any ideas?

i tried this out, and i looked like most pac-man games:

when green flag clicked

forever
move 10 steps (less if you want it slower)
if: ... key is pressed, point in direction 90, 0 -90, 180
switch to next costume (end if)
then do the ifs for the other keys,
hope this works for you

Offline

 

#3 2011-09-14 15:29:28

CustomEevee
New Scratcher
Registered: 2011-09-13
Posts: 8

Re: Issues with Using arrow keys to move sprite

You will have to use seperate scripts. One script for the costume changing and 1 or 4 script(s) for the movement, because some people use hat blocks (the "when key ____ pressed" block).

To find out the solution quickest, i would look at the wiki or look how other people make the scipt that works.

Anywho, I hope you succeed in your Pacman game! Good luck!  smile

Offline

 

Board footer