Endless moving when touching across boundries

When I swipe left to right and go across the middle “boundary” (WIDTH / 2)of the screen the sprite just keeps on moving instead of stopping like it should. What is wrong? Thanks!
video of problem: https://www.dropbox.com/s/eom2hvzs7crwjl3/IMG_0186.MOV

-- test

-- Use this function to perform your initial setup
function setup()
    print("Hello World!")
    sx = WIDTH / 2
    sy = HEIGHT / 2
    x,y = 0,0
    tx, ty = 0,0

end

-- This function gets called once every frame
function draw()
    background(127, 127, 127, 255)
    fill(0, 0, 0, 255)
    player()
    if move then
            sx=sx+(tx - x)/25
            sy=sy+(ty - y)/25
        end
       
    
end

function touched(t)
    if t.x < WIDTH / 2 then
            if t.state == BEGAN then
                x = t.x
                y = t.y
                tx = x
                ty = y
                move = true
            elseif t.state == MOVING then
                tx = t.x
                ty = t.y
                move = true
            elseif t.state == ENDED then
                x,y = 0, 0
                tx, ty = 0,0
                move = false
            end
   
   elseif t.x > WIDTH / 2 then
       print "Right"
   end  
end
function player()
    playerc = physics.body(CIRCLE, 50)
    playerc.x = sx
    playerc.y = sy
    playerc.info = "player"
    sprite("Platformer Art:Guy Standing", playerc.x, playerc.y)
    sprite("Platformer Art:Guy Standing",playerc.x,playerc.y)
end

@compactbear Don’t create multiple post for the same program.

Sorry it was a different problem :frowning:

@compactbear It’s easier to keep track of what’s happening when questions for the same program are kept in the same post.

I don’t really understand what i’m seeing. What’s up with the cryptic 2 letter variable names? Why are you dividing by 25? Etc, etc, this would be easier to fix if we actually knew the intention of the code.

Sorry my bad the sx and sy are the x and y for the sprite, x and y are the initial touch and tx and ty are the x and y value s while moving your finger. The math for sx and sy are divided by 25 to slow it down

Well, you are checking if the touch is on a side of the screen before checking if it’s state is ended. There a few ways you can fix this - I’d suggest you move the “elseif t.state == ENDED” to happen regardless of what side of the screen it is on (and change it ofc from elseif to if)

@Causeless This discussion is pretty much over. This same program, shown in another post, is beyond what’s discussed here. That’s why I said above to not create multiple posts for the same program. See the discussion “Collisions”.