modify object bounds when scaled

hi, i have an object that i scale, but the contentBounds stay the same, i know this is one of the “gotcha’s” from scaling an object… but how can i scale the bounds as well? i tried setting a shape to the object, but when i print the bounds, they are still the same…

here is the code im talking about:

playerShape = { -25,70, 25,70, 25,-35, -25,-35 }--#####the object shape physics.addBody(player, {bounce=0, friction=0.5, density=5.0}, {isSensor=true, shape=playerShape} ) player.name="player" --#########code ommited to show you a simpler code :) player:scale(1,2) -- //TODO scale player bounds player:play() --########## bounds always print the same, no matter the shape ###### print("player.ymin"..player.contentBounds.yMin) print("player.ymax"..player.contentBounds.yMax)

thanks for the help! and sorry if this is a noob question

There is no way to do it by modifying parameters. You must remove physics body and create new one. Before it you should remember original properties as eg velocity and asign it to copy.

isn’t that the same as creating de physics body after you scaled the object? because i tried that and didn’t work either, can i have an example of how this is done? i tried this but no luck:

playerShape = { -25,70, 25,70, 25,-35, -25,-35 }--#####the object shape physics.addBody(player, {bounce=0, friction=0.5, density=5.0}, {isSensor=true, shape=playerShape} ) player.name="player" --#########code ommited to show you a simpler code :) player:scale(1,2) -- //TODO scale player bounds player:play() physics.removeBody(player) --remove physics body and recreate it physics.addBody(player, {bounce=0, friction=0.5, density=5.0}, {isSensor=true, shape=playerShape} ) --########## bounds always print the same, no matter the shape ###### print("player.ymin"..player.contentBounds.yMin) print("player.ymax"..player.contentBounds.yMax)

thanks for the help!

Ah sorry. DOESN’T contentbounds refer always to original image size? Check in documentation.

Ps.
I dont know why but some properties such as bounds, have it’s value fluctuate (it may be pixel or two but when I was testing it on simulator it was frustrating)

Yes, i know contentbounds refer to the original image size, it’s one of the gotcha’s, i read it in the documentation when i encountered this problem, and i didn’t find any workarounds in the documentation… but i want to change the contentbounds, isn’t there a way of doing this? or the only way is scaling the image in photoshop so you don’t have to scale it in the code? (haven’t tried it, but i guess it should work)

i want to belive there is a way of doing this by code :slight_smile:

thanks for your help!

Ps. i have seen what you mean by the value fluctuation, fortunately that does not affect my code in this case    :)

Ah, what is player an how you create it?

player is a sprite, here is the code:

------------------------------------------------------------------------------ -- Create Player ------------------------------------------------------------------------------ -- 1st image sheet local sheetData1 = { width=53, height=50, numFrames=8, sheetContentWidth=427, sheetContentHeight=50 } local sheet1 = graphics.newImageSheet( "tilesets/luffyRunning.png", sheetData1,53,50 ) -- 2nd image sheet local sheetData2 = { width=45, height=50, numFrames=6, sheetContentWidth=272, sheetContentHeight=56 } local sheet2 = graphics.newImageSheet( "tilesets/luffyStanding.png", sheetData2 ) local sequenceData = { { name="seq1", sheet=sheet1, start=1, count=8, time=600, loopCount=0 }, { name="seq2", sheet=sheet2, start=1, count=6, time=600, loopCount=0 } } local player = display.newSprite( sheet2, sequenceData )

right after this, comes the code in my first post

Hmm… when using sprite I have seen some subtele differences compared to normal image when using scaling.
Take one frame from your sheet and save it as image. Next make player to be normal image - using display.newImage and second player using newImageRect. On both use code you provided. Tell how it behaves when using static images. You can try to create static image form sheet too. Maybe sheets or sprites really behaves in slightly different way.

Hi all,

If you haven’t read it already, you should inspect the guide on image sheets. There is specifically a section about how trimming settings can affect the overall size of the image pulled from the sheet. It occasionally causes confusion, but the guide should straighten it all out:

http://docs.coronalabs.com/guide/media/imageSheets/index.html

Brent

There is no way to do it by modifying parameters. You must remove physics body and create new one. Before it you should remember original properties as eg velocity and asign it to copy.

isn’t that the same as creating de physics body after you scaled the object? because i tried that and didn’t work either, can i have an example of how this is done? i tried this but no luck:

playerShape = { -25,70, 25,70, 25,-35, -25,-35 }--#####the object shape physics.addBody(player, {bounce=0, friction=0.5, density=5.0}, {isSensor=true, shape=playerShape} ) player.name="player" --#########code ommited to show you a simpler code :) player:scale(1,2) -- //TODO scale player bounds player:play() physics.removeBody(player) --remove physics body and recreate it physics.addBody(player, {bounce=0, friction=0.5, density=5.0}, {isSensor=true, shape=playerShape} ) --########## bounds always print the same, no matter the shape ###### print("player.ymin"..player.contentBounds.yMin) print("player.ymax"..player.contentBounds.yMax)

thanks for the help!

Ah sorry. DOESN’T contentbounds refer always to original image size? Check in documentation.

Ps.
I dont know why but some properties such as bounds, have it’s value fluctuate (it may be pixel or two but when I was testing it on simulator it was frustrating)

Yes, i know contentbounds refer to the original image size, it’s one of the gotcha’s, i read it in the documentation when i encountered this problem, and i didn’t find any workarounds in the documentation… but i want to change the contentbounds, isn’t there a way of doing this? or the only way is scaling the image in photoshop so you don’t have to scale it in the code? (haven’t tried it, but i guess it should work)

i want to belive there is a way of doing this by code :slight_smile:

thanks for your help!

Ps. i have seen what you mean by the value fluctuation, fortunately that does not affect my code in this case    :)

Ah, what is player an how you create it?

player is a sprite, here is the code:

------------------------------------------------------------------------------ -- Create Player ------------------------------------------------------------------------------ -- 1st image sheet local sheetData1 = { width=53, height=50, numFrames=8, sheetContentWidth=427, sheetContentHeight=50 } local sheet1 = graphics.newImageSheet( "tilesets/luffyRunning.png", sheetData1,53,50 ) -- 2nd image sheet local sheetData2 = { width=45, height=50, numFrames=6, sheetContentWidth=272, sheetContentHeight=56 } local sheet2 = graphics.newImageSheet( "tilesets/luffyStanding.png", sheetData2 ) local sequenceData = { { name="seq1", sheet=sheet1, start=1, count=8, time=600, loopCount=0 }, { name="seq2", sheet=sheet2, start=1, count=6, time=600, loopCount=0 } } local player = display.newSprite( sheet2, sequenceData )

right after this, comes the code in my first post

Hmm… when using sprite I have seen some subtele differences compared to normal image when using scaling.
Take one frame from your sheet and save it as image. Next make player to be normal image - using display.newImage and second player using newImageRect. On both use code you provided. Tell how it behaves when using static images. You can try to create static image form sheet too. Maybe sheets or sprites really behaves in slightly different way.

Hi all,

If you haven’t read it already, you should inspect the guide on image sheets. There is specifically a section about how trimming settings can affect the overall size of the image pulled from the sheet. It occasionally causes confusion, but the guide should straighten it all out:

http://docs.coronalabs.com/guide/media/imageSheets/index.html

Brent