Discuss Scratch

Cypher56
Scratcher
100+ posts

Sprites messing up

the sprite moves to the end of the screen when I press a or d, this is the script i'm using:
when green flag clicked
forever
if <key [a v] pressed?> then

set x to (Xv)
change x by ((-3) - (Xv))
switch costume to [left v]
change [Xv v] by (-3)
end

if <key [d v] pressed?> then

set x to (Xv)
change x by ((3) - (Xv))
switch costume to [right v]
change [Xv v] by (3)

AonymousGuy
Scratcher
1000+ posts

Sprites messing up

Hmmm… well you are setting it to Xv, and then changing it by Xv. This means it first will go to (if “a” key is pressed, assuming Xv starts at 0) -3, then -6, then -12, then -24, then -48, then -96, then -192, then -384, then - 786, and so forth, meaning after 8 loops it will be at one side of the screen.
Cypher56
Scratcher
100+ posts

Sprites messing up

AonymousGuy wrote:

Hmmm… well you are setting it to Xv, and then changing it by Xv. This means it first will go to (if “a” key is pressed, assuming Xv starts at 0) -3, then -6, then -12, then -24, then -48, then -96, then -192, then -384, then - 786, and so forth, meaning after 8 loops it will be at one side of the screen.
Thanks!

Powered by DjangoBB

Standard | Mobile