I’m just new, and I’m trying to do a simple up and down, left and right sprite. I have these “arrows”, which are just boxes. The thing is that I have a lot of variables, like “x=x+speed”, but when that line is in the code, the UP button just moves the sprite left, vut when I add the text “y=y+speed” everything moves diagonally. Help please? Thanks
Code:
displayMode(FULLSCREEN)
function setup()
speed=0
direction=100
x=WIDTH/2
y=HEIGHT/2
rx1=450
rx2=550
rx3=500
ry1=50
ry2=130
end
function draw()
background(40, 40, 50)
fill(255)
text("touch the right or left side of the screen",WIDTH/2,HEIGHT-50)
sprite("Planet Cute:Heart",x,y,direction,150)
rect(450,50,70,70)
rect(550,50,70,70)
rect(500,130,70,70)
x=x+speed
y=y+speed
if x>WIDTH+50 then
x=-50
end
if x<-50then
x=WIDTH+50
end
end
function touched(t)
if t.state == BEGAN and
t.x>400 and t.x<500 and
t.y>30 and t.y <130 then
speed=-3
direction=-100
else if t.state == ENDED then
speed=0
direction=-100
end
if t.state == BEGAN and
t.x>500 and t.x<600 and
t.y>30 and t.y<130 then
speed=3
direction=100
else if t.state == ENDED then
speed=0
direction=100
end
end
if t.state == BEGAN and
t.x>450 and t.x<550 and
t.y>80 and t.y<180 then
speed=3
direction=100
else if t.state == ENDED then
speed=0
direction=100
end
end
end
end