I have a dynamic object in my game of which is my main character. When I start the game, I need the sprite to stay in the center of the screen but it instead floats to the top of the screen even though I specified x and y coordinates for the sprite. The gravity in my game is set to 0. I’m not sure what is causing the sprite to immediately go to the top of the screen. Does anyone know?
Hey,
Are you able to provide any sample code? Usually the issue can be that you haven’t turned the gravity off causing the object to drop to the bottom of the screen rather than float to the top… If you need to use physics and dynamic objects that aren’t affected by gravity then one thing you could try doing is turning off the gravity on the specific object by doing this:
local physics = require( “physics” )
physics.start()
local _W = display.contentWidth
local _H = display.contentHeight
local rect = display.newRect( _W *0.5, _H *0.5, 50, 50 )
physics.addBody( rect, “dynamic” )
rect.gravityScale = 0
However, it might be better to find out what is causing the objects to float to the top first, so provide some code for that
Rich
Hey,
Are you able to provide any sample code? Usually the issue can be that you haven’t turned the gravity off causing the object to drop to the bottom of the screen rather than float to the top… If you need to use physics and dynamic objects that aren’t affected by gravity then one thing you could try doing is turning off the gravity on the specific object by doing this:
local physics = require( “physics” )
physics.start()
local _W = display.contentWidth
local _H = display.contentHeight
local rect = display.newRect( _W *0.5, _H *0.5, 50, 50 )
physics.addBody( rect, “dynamic” )
rect.gravityScale = 0
However, it might be better to find out what is causing the objects to float to the top first, so provide some code for that
Rich