Howdy, Stranger!

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

Touch help, making a cursor follow the finger

edited June 2012 in Questions Posts: 2

Hi, I'm new to lua and all this coding business and starting to learn via Codea.
Just a quick question, I am trying to create a cursor that follows your finger when you touch the screen, and when you remove your finger the cursor disappears.

So far this is my code, it is simple but Im not sure how to get the image to go after the touch ha been removed.

function touch()
    if touch.state == ENDED then touching = false
    else touching = true

function setup()

function draw()
    background(0, 0, 0, 255)
    fill(127, 122, 132, 255)
    ellipse( CurrentTouch.x, CurrentTouch.y, 15)
    if touching == true then draw = ellipse( CurrentTouch.x, CurrentTouch.y, 15)

Thanks for your help



  • edited June 2012 Posts: 122

    how about something like this...

    function setup()
       cursorPosition = nil
       cursorActive = false
    function touched(touch)
       if touch.state == BEGAN or touch.state == MOVING then
             cursorPosition = vec2(x,y)
             cursorActive = true
       elseif touch.state == ENDED then
             cursorPosition = nil
             cursorActive = false
    function draw()
       if cursorActive == true then

    Try that out and see if it works.

  • edited June 2012 Posts: 13

    But why cant you just use

    -- Use this function to perform your initial setup function setup()     displayMode(FULLSCREEN)          cursorsize = 15             x = 200 y = 570 end   -- This function gets called once every frame function draw()          background(0, 0, 0, 255)     fill(127, 122, 132, 255)     -- This sets the line thickness     --strokeWidth(thickness)     ellipse(x,y, cursorsize)      if CurrentTouch.state == BEGAN or CurrentTouch.state == MOVING then  x = CurrentTouch.x y = CurrentTouch.y cursorsize =15 else cursorsize =0 end                 -- Do your drawing here       end
  • Posts: 122

    You could do that too. I just like handling touches in a touch function. Makes it easier to handle as a project gets more complex.

  • Posts: 2

    Thanks guys for your help, sorry for a late response.

  • @skullagepk,
    the only problem with yours is that he wants an ellipse, not a sprite.

  • Also this topic is over a year old...

  • @skullagepk, Sorry I didn't notice that, and Please don't ad things to ild discussion unless you MUST ask something, and in which case you should PM the person, not bump the thread.

  • Can I just ask why hasn't this been closed?

  • @TheRogueBatcher, forum mods don't have time to close every single topic, and it isn't nescessary, please don't bring this topic back up the main page by posting comments like this please

This discussion has been closed.