Touch questions

Is there anyway, like if you delete your project you have to hold it, how to make t.state = Hold?

You use t.state==BEGAN and t.state==ENDED. If you tap on the screen, you get a t.state==BEGAN and you’re in a hold state until you get a t.state==ENDED.

Unless you move.

@Mark It doesn’t matter if you move. As long as you don’t get ENDED, your finger is still on the screen, so I still consider that a hold. If you want to get specific as a hold on a button, then you need to check that your finger is still on the button. if it’s not then you can consider the hold over even though you haven’t received an ENDED.

This is the function:

function World:touched(t)
    if t.state == BEGAN or t.state == MOVING then
        if t.x>25 and t.x<75 and t.y>25 and t.y<75 then
            self.body:move(-3, 0)
        elseif t.x<150 and t.x>100 and t.y<75 and t.y>25 then
            self.body:move(0, -3)
        elseif t.x>175 and t.x<225 and t.y>25 and t.y<75 then
            self.body:move(3, 0)
        elseif t.x>100 and t.x<150 and t.y>100 and t.y<150 then
            self.body:move(0, 3)
        end
    end
end

@TokOut You should apply what @dave1707 told you. Make a variable hold which becomes true when touch.state == BEGAN and becomes false when touch.state == ENDED or the touch leaves the button. Make sure it’s the same touch every time by tracking its touch.id.

@TokOut Here’s an example of a button being pushed. As long as you hold it, you’re in a hold state. If you move your finger off the button, it’s released. Also, you can’t slide your finger onto the button, you have to push it.

function setup()
    hold=false
    x,y=WIDTH/2,HEIGHT/2
    w,h=100,50
    rectMode(CENTER) 
end

function draw()
    background(0)
    fill(255,0,0)
    rect(x,y,w,h)    
    fill(255)   
    if hold then
        text("Button being pushed.",WIDTH/2,HEIGHT-100)    
    end  
end

function touched(t)
    if t.x>x-w/2 and t.x<x+w/2 and t.y>y-h/2 and t.y<y+h/2 then
        if t.state==BEGAN then
            hold=true
        end
    elseif t.state==MOVING then
        hold=false
    end
    if t.state==ENDED then
        hold=false
    end
end

Ok, Thx

How to make two touch points so what I mean, that you touch with one finger one point and with the other an other point like Touchline where two touches are

Look at the multitouch example project