Movement

function setup()
    sx = 0
    sy = 400
    cx = 10
    cy = 0
    end

function draw()
    rect(sx,sy,60)
    rect(WIDTH-150,150,100,50)
    end


   function touched(t) 
    if t.state==BEGAN then
        if t.x>WIDTH-150 and t.x<WIDTH-50 and t.y>150 and t.y<200 then
            sx=sx+cx
            sy=sy+cy
            end
        end
    if t.state==MOVING then
        if t.x>WIDTH-150 and t.x<WIDTH-50 and t.y>150 and t.y<200 then
            sx=sx+cx
            sy=sy+cy
            end
    end
end

So I made this code, just for testing, although for some reason t.state==MOVING is extremely buggy and it adds squares behind the one in front. I am attempting to make it only move 1 square. It also does more of a teleport then move. Think of a. 2D game where you control a low effort car. Smooth, and doesn’t randomly spawn in cars behind it. This is what I am trying to do.

@Valurim You need

    background(0)

as the next line after function draw(). That will stop the trails.

Also, the movement is buggy because it only moves while you finger is moving. If you stop moving your finger, the rect will stop. If you just tap the rect then the other rect will move a little. If you keep moving your finger, the rect will keep moving.