It looks like you're new here. If you want to get involved, click one of these buttons!

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

Tagged:

## Comments

@andresac You need 2 speeds, one for the x direction and one for the y direction. The up button should set the plus y speed and 0 x speed. The left button a minus x speed and a 0 y speed. The right button a plus x speed and a 0 y speed

@andresac Do a forum search on jump. There a several examples of jumping.

Here's one

Obviously forgot to add the appropriate values in the y direction.

@techdojo +1

@andresac Here's your code modified a little with a simple jump routine.