Howdy, Stranger!

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

CurrentTouch

Why cx=CurrentTouch.x doesn't work if CurrentTouch.x< 50?

Comments

  • @zoptopf Can you please expand on what the problem is. I can't really help you if I don't know what's wrong

  • dave1707dave1707 Mod
    Posts: 7,605

    @zoptopf Using the code below, I can get cx to be 0.0 and cy to be 6.5 in portrait mode, and cx to be 0.0 and cy to be 7.5 in landscape mode.

    function setup()
    end
    
    function draw()
        background(40, 40, 50)
        fill(255)
        cx=CurrentTouch.x
        cy=CurrentTouch.y
        text("x="..cx.."  cy="..cy,WIDTH/2,HEIGHT/2)
    end
    
  • edited February 2017 Posts: 3

    Try this


    function setup() touchHandled=false cx,cy=100,100 displayMode(FULLSCREEN) textMode(CORNER) end function draw() background(40, 40, 50) if CurrentTouch.state == BEGAN and not touchHandled then touchHandled = true cx=CurrentTouch.x cy=CurrentTouch.y elseif CurrentTouch.state==ENDED then touchHandled=false end fill(227, 227, 39, 255) font("ArialMT") fontSize(15) text("touch screen at x> 50 and x< 50 and see ", 50,800) text("CurrentTouch.x " .. CurrentTouch.x .. " CurrentTouch.y " .. CurrentTouch.y, CurrentTouch.x,CurrentTouch.y) text(" cx " .. cx .. " cy " .. cy,CurrentTouch.x,CurrentTouch.y+20) end
  • dave1707dave1707 Mod
    edited February 2017 Posts: 7,605

    @zoptopf I think I see what you're saying now. If you tap the screen when x is greater than 50, the values for cx,cy and CurrentTouch.x and CurrentTouch.y show the same. But if you tap the screen when x is less than 50, sometimes the values are different. Is that what you're saying. I'm getting ready to walk out the door, so I can't look into this right now.

  • Yes it is.

  • dave1707dave1707 Mod
    Posts: 7,605

    @zoptopf Maybe this code will explain it. If you touch the black part of the screen, you'll see the text touch began. When you lift your finger, you'll see the text touch ended. If you touch the green area along the left side of the screen, you'll see no response. The green area is 25 pixels wide. Now, if you put your finger off the screen on the left and drag your finger to the right, it will start to split the screen and show you the Codea editor. So the area that's about 25 pixels wide on the left side of the screen is a dead area for CurrentTouch and used for the split screen. Does that help.

    displayMode(FULLSCREEN)  
    
    function setup()
        str="touch screen"
    end
    
    function draw()
        background(0)
        fill(0, 255, 32, 255)
        rect(0,0,25,HEIGHT)
        if CurrentTouch.state==BEGAN then
            str="touch began"
        end
        if CurrentTouch.state==ENDED then
            str="touch ended"
        end
        text(str,WIDTH/2,HEIGHT/2)
    end
    
Sign In or Register to comment.