Recently one of my apps are experimenting a rare behaviour. In the main scene of my game, display.contentCenterX is not returning the same value in two different places. I mean, in the create event of my game it returns the proper value, but inside the show event it returns an inproper value. I have created a red circle inside the show event to show this behaviour.
The red circle is positioned in display.contentCenterX, display.contentCenterY, but their ‘x’ position is not in the center of the screen. I’ve atteched a screenshot:
I’ve check my code and I don’t implement nothing that could be changing this value.
try to use this code in your simulator to check the value of contentCenterX instead of the circle itself
sometimes objects are anchored by code or added to containers or display objects which might change the location of the object
I mean if you create a circle and give its x position the value of display.contentCenterX then its location on the screen will depened on the container it resides in (containers, display groups, scroll views etc)
function scene:create( event )
local sceneGroup = self.view
print( 1,display.contentCenterX )
end
function scene:show( event )
local sceneGroup = self.view
local phase = event.phase
if phase == "will" then
print( 2,display.contentCenterX )
elseif phase == "did" then
print( 3,display.contentCenterX )
end
end
when i ran the above code in the simulator it gave exact values for all of the three print commands
you can add your lines of code to print the circle.x value and compare it to display.contentCenterX value