Discuss Scratch

joshly50
Scratcher
81 posts

How to make your sprite move left and right

To make your sprite move left and right follow this script

To move right

Go to events and drag block called (When space key pressed) change it to (When right arrow key pressed)
Then go to motion and drag move 10 steps and change it to 30 and snap the blocks together.

To move left

Go to events and drag block called (When space key pressed) change it to (When left arrow key pressed)
Then go to motion and drag move 10 steps and change it to -30 and snap the blocks together.
andre_rifaut_tests
Scratcher
90 posts

How to make your sprite move left and right

This is correct.
But you can add some fun.

For instance just try with the cat:
whenright arrowkeypressedrepeat10move3stepsnextcostume

The cat will move 30 steps but you will see it move its feet.
joshly50
Scratcher
81 posts

How to make your sprite move left and right

That's quite a good way.
KermitMC
Scratcher
100+ posts

How to make your sprite move left and right

andre_rifaut_tests wrote:

This is correct.
But you can add some fun.

For instance just try with the cat:
whenright arrowkeypressedrepeat10move3stepsnextcostume

The cat will move 30 steps but you will see it move its feet.
There is a much better way than that.

whenclickedforeverifkeypressedleftchangexby-5nextcostumeifkeypressedrightchangexby5nextcostume

Hope this helps

Last edited by KermitMC (Nov. 30, 2013 15:12:11)

GadgetAndyMan
Scratcher
100+ posts

How to make your sprite move left and right

Yes the if key pressed option allows for a faster response. If that isn't needed or not suitable for your project, then the when key pressed block does the job.
lolman67
Scratcher
6 posts

How to make your sprite move left and right

whenarow[quote=KermitMCquote=andre_rifaut_testsThisiscorrect.Butyoucanaddsomefun.Forinstancejusttrywiththecat:scratchblockswhenright arrowkeypressedrepeat10move3stepsnextcostume/scratchblocksThecatwillmove30stepsbutyouwillseeitmoveitsfeet./quoteThereisamuchbetterwaythanthat.scratchblockswhenclickedforeverifkeypressedleftchangexby-5nextcostumeifkeypressedrightchangexby5nextcostume/scratchblocksHopethishelps/quotev]keypressedmove10steps
digthebone
Scratcher
500+ posts

How to make your sprite move left and right

whenclickedforeverifkeyleft arrowpressed?thensetmoving directiontoleftifkeyright arrowpressed?thensetmoving directiontorightwhenclickedforeverifmovingdirection=rightthenchangexby5ifmovingdirection=leftthenchangexby-5

hopefully that helped

and always remember
whenclickedforeverifgothelpfromdigthebone.thenknowheisawesome
digthebone
Scratcher
500+ posts

How to make your sprite move left and right

digthebone wrote:

whenclickedforeverifkeyleft arrowpressed?thensetmoving directiontoleftifkeyright arrowpressed?thensetmoving directiontorightwhenclickedforeverifmovingdirection=rightthenchangexby5ifmovingdirection=leftthenchangexby-5ifmovingdirection=leftthenchangexby-5

hopefully that helped

and always remember
whenclickedforeverifgothelpfromdigthebone.thenknowheisawesome
turkey3
Scratcher
1000+ posts

How to make your sprite move left and right

digthebone wrote:

whenclickedforeverifkeyleft arrowpressed?thensetmoving directiontoleftifkeyright arrowpressed?thensetmoving directiontorightwhenclickedforeverifmovingdirection=rightthenchangexby5ifmovingdirection=leftthenchangexby-5

hopefully that helped

and always remember
whenclickedforeverifgothelpfromdigthebone.thenknowheisawesome
]
Those could be combined into one, more efficient script.
Scratching_Vornado
Scratcher
14 posts

How to make your sprite move left and right

Using

movesteps

isn't very good as it doesn't work very well. Sometimes it moves once, stops, then moves forward again. As other people said, you should do something like this:

whenclickedforeverifkeyright arrowpressed?thenchangexby30ifkeyleft arrowpressed?thenchangexby-30

Maybe through in a
wait0.01secs

in there.
typemaster
Scratcher
100+ posts

How to make your sprite move left and right

X and Y are the coordinates of the location of the sprite as you probably already know.
Here is the most efficient way to make a sprite move left and right:
whenright arrowkeypressedchangexby5this is for moving rightwhenleft arrowkeypressedchangexby-5this is the script for moving left

Hope I helped you!
You will find that most of my projects use those scripts that I gave you.
csonic6
Scratcher
4 posts

How to make your sprite move left and right

Like this!
when-->keypressedmove10steps
r123a
Scratcher
1000+ posts

How to make your sprite move left and right

whenleftkeypressedendchangexby-10end
r123a
Scratcher
1000+ posts

How to make your sprite move left and right

sorry, I made a mistake.
Nyan_Banana
Scratcher
14 posts

How to make your sprite move left and right

You just need When Flag Clicked change x by (how ever much you want). If you want it to go left make it a minus number

Last edited by Nyan_Banana (March 17, 2015 13:46:36)

blazingames
Scratcher
22 posts

How to make your sprite move left and right

We all know how.
whenright keykeypressedmove1steps
Starvia
Scratcher
17 posts

How to make your sprite move left and right

How do you make scratchblocks?
GyroscopeBill
Scratcher
500+ posts

How to make your sprite move left and right

Starvia wrote:

How do you make scratchblocks?
When you make a post, look at the icons above the bit where you type. One of those is a small blue block with a down arrow next to it. Click on there and you can then click on the blocks. Alternatively, you can do what I do and type them manually.

Happyscratchblocks
minecrafternotch
Scratcher
3 posts

How to make your sprite move left and right

In the latest version of scratch it's easy.Two ways are with a mouse,and by arrow keys

Mouse
whenthisspriteclicked
glide1secstox:mousexy:mousey


Arrows:
whenright arrowkeypressed
repeatuntiltouchingother block?move3steps

end


whenIreceiveFame and Glory
gotoThe moon and live life
gaoj5892
Scratcher
3 posts

How to make your sprite move left and right

whenclickedforeverifkey left arrowpressed?thenmove5steps

Powered by DjangoBB