Problem with rectangle button

Hello everybody, I’m having a really strange problem with my game, I can’t manage to fix it.

In my code, I’m creating a rectangle at the top of the screen, then I add a touch listener to it.

The problem is that I can only touch the left part of the button, because the right part just doesn’t react.

But when I place the button at the bottom of the screen it works nicely.

Here’s how to reproduce the “bug” :

module(..., package.seeall) new = function ( params ) local localGroup = display.newGroup() --================================== --Forward functions --================================== local onTouchButton --================================== --Create variables & displays --================================== local background local button --================================== --Functions --================================== onTouchButton = function(e) if e.phase == "began" then display.currentStage:setFocus(button) button.alpha = 0.6 button:setFillColor(80/255,80/255,80/255) elseif e.phase == "ended" then display.currentStage:setFocus(nil) button.alpha = 0.3 button:setFillColor(200/255,200/255,200/255) end end --================================== --Image Displays --================================== button = display.newRect(display.contentWidth/2,100, display.contentWidth,100) button:setFillColor(200/255,200/255,200/255) button.alpha = 0.3 button:addEventListener("touch",onTouchButton) --================================== --Functions --================================== button:addEventListener("touch",onTouchButton) return localGroup end

Oh, and also, I would like to say that I’m using the Director class.

Thanks you for your support,

Ulysse.

I did a quick test copying your code to a blank project, eliminating Director.  The button spans the whole width of my screen and I can click on it anywhere.

I don’t believe Director has been updated to support Graphics 2.0.  Corona Labs officially supports the storyboard.* API’s as our scene manager and we can’t make 3rd party producers update their code.  

You might have some success by adding:

graphicsCompatibility = 1

into your config.lua where you define the width and height.  This will tell Corona SDK to revert to using G1.0 style positioning which should make Director happy.

Rob

Thanks you for your answer, I finally found the solution on another thread :

http://forums.coronalabs.com/topic/43375-touch-events-in-graphic-20/

All I had to do was to comment a few lines in director.lua.

Have a nice day !

I did a quick test copying your code to a blank project, eliminating Director.  The button spans the whole width of my screen and I can click on it anywhere.

I don’t believe Director has been updated to support Graphics 2.0.  Corona Labs officially supports the storyboard.* API’s as our scene manager and we can’t make 3rd party producers update their code.  

You might have some success by adding:

graphicsCompatibility = 1

into your config.lua where you define the width and height.  This will tell Corona SDK to revert to using G1.0 style positioning which should make Director happy.

Rob

Thanks you for your answer, I finally found the solution on another thread :

http://forums.coronalabs.com/topic/43375-touch-events-in-graphic-20/

All I had to do was to comment a few lines in director.lua.

Have a nice day !