Sprite vs Image using Physics

A have a question.

I have two objects:

1) Image

2) Sprite

Both have the same size.

Why when I use applyforce , the sprite move less than the Image? ( I’m talking only about Y, the X value is zero in applyforce function).

Follow the CODE:

local function touch( event )

if ( event.phase == “began” ) then

personagemSprite:applyForce( 0, -9, personagemSprite.x, personagemSprite.y)

image:applyForce( 0, -9, image.x, image.y)

end

end

local screenW, screenH, halfW = display.contentWidth, display.contentHeight, display.contentWidth*0.5

function scene:create( event )

local sceneGroup = self.view

local background = display.newRect( 0, 0, screenW, screenH )

background.anchorX = 0

background.anchorY = 0

background:setFillColor( .5 )

local grass = display.newImageRect( “grass.png”, screenW, 82 )

grass.anchorX = 0

grass.anchorY = 1

grass.x, grass.y = 0, display.contentHeight

physics.addBody( grass, “static”, { friction=0, bounce = 0 } )

image = display.newImage(“spriteNatanMorrendo.png”)

image:scale( display.contentWidth*0.1 / 55, display.contentWidth*0.1 / 61)

image.x = display.contentWidth*0.5

image.y = grass.y - grass.height/2 - image.height/2

physics.addBody( image, “dynamic”, { friction=0, bounce = 0 } )

local spriteOptionsParado = { width = 55, height = 61, numFrames = 7 }

local spriteParado = graphics.newImageSheet( “spriteNatanCorrendo.png”, spriteOptionsParado )

local spriteSequence = {

   { name=“parado”, sheet = spriteParado, time = 500, start = 1, count = 7, loopCount= 0 }

    }

    personagemSprite = display.newSprite( spriteParado, spriteSequence )

personagemSprite:scale( display.contentWidth*0.1 / 55, display.contentWidth*0.1 / 61)

personagemSprite.x = display.contentWidth*0.3

personagemSprite.y = grass.y - grass.height/2 - image.height/2

physics.addBody( personagemSprite, “dynamic”, { friction=0, bounce = 0 } )

sceneGroup:insert( background )

sceneGroup:insert( grass)

Runtime:addEventListener(“touch”, touch)

end

Up

:frowning:

try running with physics:setDisplayMode(“hybrid”) - does it give any clues?

can’t run your code as is, so just a guess, but physics body sizes might not match your visual display.  physics doesn’t respect scale() - it’s a visual effect only.  try commenting out your two scale() calls and reexamine the hybrid display, any difference?  once you can identify the cause then perhaps the solution will become evident.

As @davebollinger says, you should not scale objects which will use physics. The effect will only be visual, not representative of the physics behavior.

Once you do that, and examine the real “physical size” of the objects, there will almost certainly be some difference, which is why your application of force is different. Bodies possess an inherent “mass” which is dependant on their size, and applying force is directly related to the mass of the object. So, heavier objects obviously will move less.

Hope this helps,

Brent

Up

:frowning:

try running with physics:setDisplayMode(“hybrid”) - does it give any clues?

can’t run your code as is, so just a guess, but physics body sizes might not match your visual display.  physics doesn’t respect scale() - it’s a visual effect only.  try commenting out your two scale() calls and reexamine the hybrid display, any difference?  once you can identify the cause then perhaps the solution will become evident.

As @davebollinger says, you should not scale objects which will use physics. The effect will only be visual, not representative of the physics behavior.

Once you do that, and examine the real “physical size” of the objects, there will almost certainly be some difference, which is why your application of force is different. Bodies possess an inherent “mass” which is dependant on their size, and applying force is directly related to the mass of the object. So, heavier objects obviously will move less.

Hope this helps,

Brent