Howdy, Stranger!

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

Touch question

edited June 2014 in Questions Posts: 3

Hi !
I'm totally new to codea (and to prog globally), so I have a problem which might seem stupid but here it is :
I would like an action to be made if someone touch the screen in a particular spot and to stop when he releases his finger.

At the moment I'm using :

if CurrentTouch.state==MOVING then
  print("pressed")
end

So when I move my finger around it works, but I'd like it to work with a still finger in a particular spot (a button for example)...

If anyone can help me with this, that'd be great !!
Thanks

Comments

  • dave1707dave1707 Mod
    Posts: 7,604

    @Toufalex Here's a simple example of a button.


    function setup() str="" end function draw() background(40, 40, 50) fill(255) text(str,WIDTH/2,HEIGHT-100) rect(200,300,100,50) fill(255,0,0) text("Press",250,325) end function touched(t) if t.state==BEGAN then if t.x>200 and t.x<300 and t.y>300 and t.y<350 then str="Button pressed" end end if t.state==ENDED then str="" end end
  • dave1707dave1707 Mod
    Posts: 7,604

    @Toufalex Here's an example that allows you press or to slide your finger across the button.


    function setup() str="" end function draw() background(40, 40, 50) fill(255) text(str,WIDTH/2,HEIGHT-100) rect(200,300,100,50) fill(255,0,0) text("Press",250,325) end function touched(t) if t.state==BEGAN or t.state==MOVING then if t.x>200 and t.x<300 and t.y>300 and t.y<350 then str="Button pressed" else str="" end end if t.state==ENDED then str="" end end
  • Posts: 3

    Great ! Thanks for the quick answer !
    I'll have a try and let you know if it worked :)

  • Posts: 3

    Hey !
    It worked like a charm ! Thanks

  • The user and all related content has been deleted.
  • Posts: 1,976

    @NatTheCoder You removed one line of code, and tweaked some text?

  • The user and all related content has been deleted.
Sign In or Register to comment.