It looks like you're new here. If you want to get involved, click one of these buttons!
function scene:addControls(x,y) local texture = Texture.new("ptex.png") local leftButtonRegion = TextureRegion.new(texture,0,0,100,100) local rightButtonRegion = TextureRegion.new(texture,0,100,100,100) local leftButton = Bitmap.new(leftButtonRegion) local rightButton = Bitmap.new(rightButtonRegion) leftButton.name = "leftButton" rightButton.name = "rightButton" leftButton:setPosition(x,y) rightButton:setPosition(x+120, y) self:addChild(leftButton) self:addChild(rightButton) rightButton:addEventListener(Event.MOUSE_DOWN, onMouseDown, scene.rightButton) rightButton:addEventListener(Event.MOUSE_UP, onMouseUp, scene.rightButton) leftButton:addEventListener(Event.MOUSE_DOWN, onMouseDown, scene.leftButton) leftButton:addEventListener(Event.MOUSE_UP, onMouseUp, scene.leftButton) end function onMouseDown(event) local target = event:getTarget() print(target.name) if target.name == "leftButton" then print("Left Press") end if target.name == "rightButton" then print("Right Press") end end |
Likes: kamcknig
Comments
Website: http://www.castlegateinteractive.com
https://play.google.com/store/apps/developer?id=Castlegate+Interactive
OK @twistap, here is code that works in my current project. As you can see it is doing exactly what you want it to do so
Website: http://www.castlegateinteractive.com
https://play.google.com/store/apps/developer?id=Castlegate+Interactive
@Scouser your example is perfect for what to do, but you didn't include the textButton function which is going to become pretty confusing really quick for some people on the forum otherwise @twisttap be sure to take a look at his code, it's more complex but does some nice things as well--like save them for later to update, etc
Change your onMouseDown function to the following and you should see the results you want--of course this is assuming that you have this code in a scene class of some kind:
The example comes with Gideros Studio on how to use it and can be accessed by clicking on the Buttons option int he Examples box. It does what I changed your example to do and more as it supports up and down states automatically and you don't have to do the hitTestPointas it does it internally as well.
Happy coding!
Eli
Website: http://www.castlegateinteractive.com
https://play.google.com/store/apps/developer?id=Castlegate+Interactive