Discuss Scratch

nilskris
New Scratcher
4 posts

Move a Sprite horizontally without keyboard

Hey! I want to make a Scratch game compatible on both desktop and phone. On the desktop version you use the arrow keys, and on the phone version you can press the left side or righ side of the screen respectively to make the Sprite move either left or right. I already know how to do the arrow keys, but is the latter do-able?


Any help would be appreciated!


mstone326
Scratcher
1000+ posts

Move a Sprite horizontally without keyboard

Yes, the later is doable just note that tapping the screen counts as a mouse down event. So you can't press multiple sprites at once with When this sprite clicked events. But definitely doable
chipm0nk
Scratcher
100+ posts

Move a Sprite horizontally without keyboard

Yes, this is definitely doable;
To make the Sprite move on an i-Pad or phone, put this bit of code into the Sprite (unless you are making a side-scrolling game, in which case this will probably not work.)
when green flag clicked
forever
if <mouse down?> then
if <(mouse x) > (x position)> then
change x by (5)
else
change x by (-5)
end
end
end

To change the speed at which your sprite moves you can increase or decrease the values in the Change X blocks.
Hope this helps, and good luck with your project!
nilskris
New Scratcher
4 posts

Move a Sprite horizontally without keyboard

chipm0nk wrote:

Yes, this is definitely doable;
To make the Sprite move on an i-Pad or phone, put this bit of code into the Sprite (unless you are making a side-scrolling game, in which case this will probably not work.)
when green flag clicked
forever
if <mouse down?> then
if <(mouse x) > (x position)> then
change x by (5)
else
change x by (-5)
end
end
end

To change the speed at which your sprite moves you can increase or decrease the values in the Change X blocks.
Hope this helps, and good luck with your project!

Fantastic! Thanks for the help.
chipm0nk
Scratcher
100+ posts

Move a Sprite horizontally without keyboard

No problem, glad I could help you!
Ayaan-yay
Scratcher
1 post

Move a Sprite horizontally without keyboard

umm well you can just add some arrow keys to your project and when the person presses on them it will go up, down, right or left


For example

when you press the arrow that's pointing up the sprite goes up
AbHiLoVe_10
Scratcher
1 post

Move a Sprite horizontally without keyboard

how do i make a sprite move by itself without touching my keyborad left and right continusally without followin my other sprite

Last edited by AbHiLoVe_10 (April 6, 2024 23:29:32)

-Nether_Portal-
Scratcher
55 posts

Move a Sprite horizontally without keyboard

when green flag clicked
set [ foov] to [0]
forever
change x by (foo)
change [foo v] by (1)
end
DashDav
Scratcher
14 posts

Move a Sprite horizontally without keyboard

chipm0nk wrote:

Yes, this is definitely doable;
To make the Sprite move on an i-Pad or phone, put this bit of code into the Sprite (unless you are making a side-scrolling game, in which case this will probably not work.)
when green flag clicked
forever
if <mouse down?> then
if <(mouse x) > (x position)> then
change x by (5)
else
change x by (-5)
end
end
end

To change the speed at which your sprite moves you can increase or decrease the values in the Change X blocks.
Hope this helps, and good luck with your project!
One of my projects actually uses a very similar, albeit more complex code.
ThreeHP
Scratcher
88 posts

Move a Sprite horizontally without keyboard

In order to make this you can make an arrow sprite(right and left) and make another sprite move whenever one of the arrows are pressed
when this sprite clicked
broadcast [Move left/right v]

when I receive [Move left/right v]
move (-10/10) steps
Pickle1314
Scratcher
2 posts

Move a Sprite horizontally without keyboard

-Nether_Portal- wrote:

when green flag clicked
set [ foo] to [0]
forever
change x by (foo)
change [foo v] by (1)
end

Powered by DjangoBB