Quick Links: Download Gideros Studio | Gideros Documentation | Gideros community chat | DONATE
Basic touch — Gideros Forum

Basic touch

Unknown Member
edited April 2013 in General questions

local player = Bitmap.new(Texture.new("Sprites/gundam.png"))
stage:addChild(player)

function player:onTouch(event)

print("aa");

end

player:addEventListener(Event.MOUSE_DOWN, player.onTouch)


When i touch anywhere in the screen it prints "aa" instead of only printing when i touch my player.
I tried to read some articles but its really annoying me this problem.
Can anyone help me?

Comments

  • ar2rsawseenar2rsawseen Maintainer
    The right approach would be:
    local player = Bitmap.new(Texture.new("Sprites/gundam.png"))
    stage:addChild(player)
     
    function player:onTouch(event)
        if self:hitTestPoint(event.x, event.y) then
            print("aa")
        end
    end
     
    player:addEventListener(Event.MOUSE_DOWN, player.onTouch, player)
  • OZAppsOZApps Guru
    edited April 2013
    @Freedow, the touch event fires an event upon touch, you will have to check and see if the touch is (inside) on the player or outside the player. So you will have get the co-ordinates using the hitTestPoint function before you print("aa")
    twitter: @ozapps | http://www.oz-apps.com | http://howto.oz-apps.com | http://reviewme.oz-apps.com
    Author of Learn Lua for iOS Game Development from Apress ( http://www.apress.com/9781430246626 )
    Cool Vizify Profile at https://www.vizify.com/oz-apps
Sign In or Register to comment.