Discuss Scratch
- Discussion Forums
- » Help with Scripts
- » how can i make buttons to go left/right on mobile.
- TOLZofficial
-
Scratcher
4 posts
how can i make buttons to go left/right on mobile.
i want to make buttons that if you press on mobile, the sprite will move.
- HopperSpaniel
-
Scratcher
60 posts
how can i make buttons to go left/right on mobile.
Hi there! Try this:
(make sure to set the my block to “run without screen refresh.” and set cloneID to “for this sprite only”)
WARNING: This code has its flaws!!! I whipped it up really fast so you can get a general idea. A much simpler way of doing this would be to make separate sprites for each button and have a simple when this sprite clicked event block to change the appropriate variable by the correct value.
(make sure to set the my block to “run without screen refresh.” and set cloneID to “for this sprite only”)
WARNING: This code has its flaws!!! I whipped it up really fast so you can get a general idea. A much simpler way of doing this would be to make separate sprites for each button and have a simple when this sprite clicked event block to change the appropriate variable by the correct value.
define make (#) clones at x: (x) y: (y)
hide
go to x: (x) y: (y)
set [cloneID v] to [1]
repeat (#)
create clone of [button v]
change [cloneID v] by (1)
end
when green flag clicked
make (4) clones at x: (100) y: (-50)
when I start as a clone
if <(cloneID) = [1]> then
switch costume to [up arrow button v]
show
forever
if <touching [mouse pointer v] ?> then
if <mouse down?> then
jump or change variable y for the player by a positive value
end
end
end
end
if <(cloneID) = [2]> then
switch costume to [down arrow button v]
change y by (-40)
show
forever
if <touching [mouse pointer v] ?> then
if <mouse down?> then
if applicable change player y variable by a negative value
end
end
end
end
if <(cloneID) = [3]> then
switch costume to [right arrow button v]
change x by (-40)
change y by (40)
show
forever
if <touching [mouse pointer v] ?> then
if <mouse down?> then
change [player x v] by (5)
end
end
end
end
if <(cloneID) = [4]> then
switch costume to [left arrow button v]
change y by (-40)
change x by (-40)
show
forever
if <touching [mouse pointer v] ?> then
if <mouse down?> then
change [player y v] by (-5)
end
end
end
end
- TOLZofficial
-
Scratcher
4 posts
how can i make buttons to go left/right on mobile.
yo bro, ive tried it but how do i get the player to move when player x changes?
- HopperSpaniel
-
Scratcher
60 posts
how can i make buttons to go left/right on mobile.
Hi! Just do this for the player sprite:
when green flag clicked
forever
set x to (player x)
set y to (player y)
end
- TOLZofficial
-
Scratcher
4 posts
how can i make buttons to go left/right on mobile.
yo bro, ive tried it but how do i get the player to move when player x changes?
nevermind, im done! thanks
- Discussion Forums
- » Help with Scripts
-
» how can i make buttons to go left/right on mobile.

