Physics + New Sprite API

In the past, I’ve had no problem using either the old sprite API and a sprite sheet or SpriteLoq to create animated physics objects in my games. For my new games I am switching to a combination of TexturePacker and the new sprite API.

Unfortunately, I can’t seem to get these two things to play together the way I envision they should (probably because I am using these new APIs with the same mindset that I used when doing the old stuff!)

The result I am looking for is that the sprite has a simple physics rectangle around him whether he is being animated or not. My code is below (with the caveat that I’ve already tried things like changing reference points and scaling). There are two problems:

  1. The physics rectangle is to the top left of the sprite.
  2. If I adjust the weight and height of the sprite object, it goes away the moment I play any animation. (In other words, the original size of the sprite frames override the height and width I set on the sprite object)
 local dummySprite = require("objects.dummySprite")  
 local dummySheet = graphics.newImageSheet(\_G.IMAGEPATH.."DummySprite.png", dummySprite:getSheet())  
  
 local playerGroup = display.newGroup()  
  
 local sequenceData =  
 {  
 { name="jumping", start=51, count=9, time=1000, loopCount=0 }  
 }  
  
 local player = display.newSprite(playerGroup, dummySheet, sequenceData)  
 player:setSequence("jumping")  
 --player.xScale = .5; player.yScale = .5 (tried scaling as well, same poor results)   
 player.width = 32; player.height = 32  
 player:setReferencePoint(display.c)  
 player.x = x; player.y = y; player.name = name  
  
 --Add Physics  
 physics.addBody(player, "static", { friction=friction, density=density, bounce=bounce, filter=\_G.FILTER\_PLAYER })   
  

Here’s the “DummySprite” code generated by TexturePacker:

--  
-- created with TexturePacker (http://www.texturepacker.com)  
--  
-- $TexturePacker:SmartUpdate:5a6383316ba143466ec1aa3a0c68befc$  
--  
-- local sheetInfo = require("myExportedImageSheet") -- lua file that Texture packer published  
--  
-- local myImageSheet = graphics.newImageSheet( "ImageSheet.png", sheetInfo:getSheet() ) -- ImageSheet.png is the image Texture packer published  
--  
-- local myImage1 = display.newImage( myImageSheet , sheetInfo:getFrameIndex("image\_name1"))  
-- local myImage2 = display.newImage( myImageSheet , sheetInfo:getFrameIndex("image\_name2"))  
--  
local SheetInfo = {}  
  
SheetInfo.sheet =  
{  
 frames = {  
  
 {  
 -- obj\_Box000  
 x=36,  
 y=680,  
 width=40,  
 height=40,  
  
 sourceX = 28,  
 sourceY = 36,  
 sourceWidth = 64,  
 sourceHeight = 64  
 },  
 {  
 -- obj\_Box001  
 x=36,  
 y=638,  
 width=40,  
 height=40,  
  
 sourceX = 28,  
 sourceY = 36,  
 sourceWidth = 64,  
 sourceHeight = 64  
 },  
 {  
 -- obj\_Box002  
 x=36,  
 y=596,  
 width=40,  
 height=40,  
  
 sourceX = 28,  
 sourceY = 36,  
 sourceWidth = 64,  
 sourceHeight = 64  
 },  
 {  
 -- obj\_Box003  
 x=36,  
 y=554,  
 width=40,  
 height=40,  
  
 sourceX = 28,  
 sourceY = 36,  
 sourceWidth = 64,  
 sourceHeight = 64  
 },  
 {  
 -- obj\_Box004  
 x=36,  
 y=512,  
 width=40,  
 height=40,  
  
 sourceX = 28,  
 sourceY = 36,  
 sourceWidth = 64,  
 sourceHeight = 64  
 },  
 {  
 -- obj\_Box005  
 x=2,  
 y=1822,  
 width=48,  
 height=40,  
  
 sourceX = 24,  
 sourceY = 36,  
 sourceWidth = 64,  
 sourceHeight = 64  
 },  
 {  
 -- obj\_Box100  
 x=36,  
 y=470,  
 width=40,  
 height=40,  
  
 sourceX = 20,  
 sourceY = 36,  
 sourceWidth = 64,  
 sourceHeight = 64  
 },  
 {  
 -- obj\_Box101  
 x=36,  
 y=428,  
 width=40,  
 height=40,  
  
 sourceX = 20,  
 sourceY = 36,  
 sourceWidth = 64,  
 sourceHeight = 64  
 },  
 {  
 -- obj\_Box102  
 x=36,  
 y=386,  
 width=40,  
 height=40,  
  
 sourceX = 20,  
 sourceY = 36,  
 sourceWidth = 64,  
 sourceHeight = 64  
 },  
 {  
 -- obj\_Box103  
 x=36,  
 y=344,  
 width=40,  
 height=40,  
  
 sourceX = 20,  
 sourceY = 36,  
 sourceWidth = 64,  
 sourceHeight = 64  
 },  
 {  
 -- obj\_Box104  
 x=86,  
 y=212,  
 width=40,  
 height=40,  
  
 sourceX = 20,  
 sourceY = 36,  
 sourceWidth = 64,  
 sourceHeight = 64  
 },  
 {  
 -- obj\_Box105  
 x=2,  
 y=1780,  
 width=48,  
 height=40,  
  
 sourceX = 8,  
 sourceY = 36,  
 sourceWidth = 64,  
 sourceHeight = 64  
 },  
 {  
 -- obj\_Crouch000  
 x=78,  
 y=296,  
 width=32,  
 height=40,  
  
 sourceX = 32,  
 sourceY = 36,  
 sourceWidth = 64,  
 sourceHeight = 64  
 },  
 {  
 -- obj\_Crouch100  
 x=70,  
 y=722,  
 width=32,  
 height=40,  
  
 sourceX = 32,  
 sourceY = 36,  
 sourceWidth = 64,  
 sourceHeight = 64  
 },  
 {  
 -- obj\_Doze000  
 x=78,  
 y=338,  
 width=24,  
 height=40,  
  
 sourceX = 44,  
 sourceY = 36,  
 sourceWidth = 64,  
 sourceHeight = 64  
 },  
 {  
 -- obj\_Doze100  
 x=94,  
 y=254,  
 width=24,  
 height=40,  
  
 sourceX = 36,  
 sourceY = 36,  
 sourceWidth = 64,  
 sourceHeight = 64  
 },  
 {  
 -- obj\_FallFlat000  
 x=120,  
 y=254,  
 width=40,  
 height=32,  
  
 sourceX = 28,  
 sourceY = 48,  
 sourceWidth = 64,  
 sourceHeight = 64  
 },  
 {  
 -- obj\_FallFlat001  
 x=104,  
 y=338,  
 width=48,  
 height=32,  
  
 sourceX = 16,  
 sourceY = 48,  
 sourceWidth = 64,  
 sourceHeight = 64  
 },  
 {  
 -- obj\_FallFlat100  
 x=112,  
 y=296,  
 width=40,  
 height=32,  
  
 sourceX = 20,  
 sourceY = 48,  
 sourceWidth = 64,  
 sourceHeight = 64  
 },  
 {  
 -- obj\_FallFlat101  
 x=78,  
 y=380,  
 width=48,  
 height=32,  
  
 sourceX = 16,  
 sourceY = 48,  
 sourceWidth = 64,  
 sourceHeight = 64  
 },  
 {  
 -- obj\_FireBigGun000  
 x=86,  
 y=170,  
 width=40,  
 height=40,  
  
 sourceX = 28,  
 sourceY = 36,  
 sourceWidth = 64,  
 sourceHeight = 64  
 },  
 {  
 -- obj\_FireBigGun001  
 x=86,  
 y=128,  
 width=40,  
 height=40,  
  
 sourceX = 28,  
 sourceY = 36,  
 sourceWidth = 64,  
 sourceHeight = 64  
 },  
 {  
 -- obj\_FireBigGun100  
 x=94,  
 y=44,  
 width=40,  
 height=40,  
  
 sourceX = 20,  
 sourceY = 36,  
 sourceWidth = 64,  
 sourceHeight = 64  
 },  
 {  
 -- obj\_FireBigGun101  
 x=94,  
 y=2,  
 width=40,  
 height=40,  
  
 sourceX = 20,  
 sourceY = 36,  
 sourceWidth = 64,  
 sourceHeight = 64  
 },  
 {  
 -- obj\_FireBigGunCrouch000  
 x=86,  
 y=86,  
 width=40,  
 height=40,  
  
 sourceX = 28,  
 sourceY = 36,  
 sourceWidth = 64,  
 sourceHeight = 64  
 },  
 {  
 -- obj\_FireBigGunCrouch001  
 x=44,  
 y=228,  
 width=40,  
 height=40,  
  
 sourceX = 28,  
 sourceY = 36,  
 sourceWidth = 64,  
 sourceHeight = 64  
 },  
 {  
 -- obj\_FireBigGunCrouch100  
 x=44,  
 y=186,  
 width=40,  
 height=40,  
  
 sourceX = 20,  
 sourceY = 36,  
 sourceWidth = 64,  
 sourceHeight = 64  
 },  
 {  
 -- obj\_FireBigGunCrouch101  
 x=44,  
 y=144,  
 width=40,  
 height=40,  
  
 sourceX = 20,  
 sourceY = 36,  
 sourceWidth = 64,  
 sourceHeight = 64  
 },  
 {  
 -- obj\_FireGun000  
 x=52,  
 y=44,  
 width=40,  
 height=40,  
  
 sourceX = 28,  
 sourceY = 36,  
 sourceWidth = 64,  
 sourceHeight = 64  
 },  
 {  
 -- obj\_FireGun001  
 x=52,  
 y=2,  
 width=40,  
 height=40,  
  
 sourceX = 28,  
 sourceY = 36,  
 sourceWidth = 64,  
 sourceHeight = 64  
 },  
 {  
 -- obj\_FireGun100  
 x=44,  
 y=102,  
 width=40,  
 height=40,  
  
 sourceX = 20,  
 sourceY = 36,  
 sourceWidth = 64,  
 sourceHeight = 64  
 },  
 {  
 -- obj\_FireGun101  
 x=36,  
 y=302,  
 width=40,  
 height=40,  
  
 sourceX = 20,  
 sourceY = 36,  
 sourceWidth = 64,  
 sourceHeight = 64  
 },  
 {  
 -- obj\_FireGunCrouch000  
 x=44,  
 y=1990,  
 width=40,  
 height=40,  
  
 sourceX = 28,  
 sourceY = 36,  
 sourceWidth = 64,  
 sourceHeight = 64  
 },  
 {  
 -- obj\_FireGunCrouch001  
 x=44,  
 y=1948,  
 width=40,  
 height=40,  
  
 sourceX = 28,  
 sourceY = 36,  
 sourceWidth = 64,  
 sourceHeight = 64  
 },  
 {  
 -- obj\_FireGunCrouch100  
 x=44,  
 y=1906,  
 width=40,  
 height=40,  
  
 sourceX = 20,  
 sourceY = 36,  
 sourceWidth = 64,  
 sourceHeight = 64  
 },  
 {  
 -- obj\_FireGunCrouch101  
 x=44,  
 y=1864,  
 width=40,  
 height=40,  
  
 sourceX = 20,  
 sourceY = 36,  
 sourceWidth = 64,  
 sourceHeight = 64  
 },  
 {  
 -- obj\_Flat000  
 x=128,  
 y=86,  
 width=48,  
 height=24,  
  
 sourceX = 16,  
 sourceY = 60,  
 sourceWidth = 64,  
 sourceHeight = 64  
 },  
 {  
 -- obj\_Flat100  
 x=44,  
 y=270,  
 width=48,  
 height=24,  
  
 sourceX = 16,  
 sourceY = 60,  
 sourceWidth = 64,  
 sourceHeight = 64  
 },  
 {  
 -- obj\_Flying000  
 x=2,  
 y=252,  
 width=40,  
 height=48,  
  
 sourceX = 20,  
 sourceY = 24,  
 sourceWidth = 64,  
 sourceHeight = 64  
 },  
 {  
 -- obj\_Flying001  
 x=52,  
 y=1814,  
 width=32,  
 height=40,  
  
 sourceX = 32,  
 sourceY = 36,  
 sourceWidth = 64,  
 sourceHeight = 64  
 },  
 {  
 -- obj\_Flying100  
 x=2,  
 y=1352,  
 width=32,  
 height=48,  
  
 sourceX = 32,  
 sourceY = 24,  
 sourceWidth = 64,  
 sourceHeight = 64  
 },  
 {  
 -- obj\_Flying101  
 x=52,  
 y=1772,  
 width=32,  
 height=40,  
  
 sourceX = 32,  
 sourceY = 36,  
 sourceWidth = 64,  
 sourceHeight = 64  
 },  
 {  
 -- obj\_Idle000  
 x=2,  
 y=1302,  
 width=32,  
 height=48,  
  
 sourceX = 32,  
 sourceY = 24,  
 sourceWidth = 64,  
 sourceHeight = 64  
 },  
 {  
 -- obj\_Idle001  
 x=2,  
 y=1252,  
 width=32,  
 height=48,  
  
 sourceX = 32,  
 sourceY = 24,  
 sourceWidth = 64,  
 sourceHeight = 64  
 },  
 {  
 -- obj\_Idle002  
 x=2,  
 y=1202,  
 width=32,  
 height=48,  
  
 sourceX = 32,  
 sourceY = 24,  
 sourceWidth = 64,  
 sourceHeight = 64  
 },  
 {  
 -- obj\_Idle003  
 x=2,  
 y=1152,  
 width=32,  
 height=48,  
  
 sourceX = 32,  
 sourceY = 24,  
 sourceWidth = 64,  
 sourceHeight = 64  
 },  
 {  
 -- obj\_Idle100  
 x=2,  
 y=1102,  
 width=32,  
 height=48,  
  
 sourceX = 32,  
 sourceY = 24,  
 sourceWidth = 64,  
 sourceHeight = 64  
 },  
 {  
 -- obj\_Idle101  
 x=2,  
 y=1052,  
 width=32,  
 height=48,  
  
 sourceX = 32,  
 sourceY = 24,  
 sourceWidth = 64,  
 sourceHeight = 64  
 },  
 {  
 -- obj\_Idle102  
 x=2,  
 y=1002,  
 width=32,  
 height=48,  
  
 sourceX = 32,  
 sourceY = 24,  
 sourceWidth = 64,  
 sourceHeight = 64  
 },  
 {  
 -- obj\_Idle103  
 x=2,  
 y=952,  
 width=32,  
 height=48,  
  
 sourceX = 32,  
 sourceY = 24,  
 sourceWidth = 64,  
 sourceHeight = 64  
 },  
 {  
 -- obj\_Jump000  
 x=2,  
 y=902,  
 width=32,  
 height=48,  
  
 sourceX = 32,  
 sourceY = 24,  
 sourceWidth = 64,  
 sourceHeight = 64  
 },  
 {  
 -- obj\_Jump100  
 x=2,  
 y=852,  
 width=32,  
 height=48,  
  
 sourceX = 32,  
 sourceY = 24,  
 sourceWidth = 64,  
 sourceHeight = 64  
 },  
 {  
 -- obj\_JumpHigh000  
 x=2,  
 y=802,  
 width=32,  
 height=48,  
  
 sourceX = 32,  
 sourceY = 24,  
 sourceWidth = 64,  
 sourceHeight = 64  
 },  
 {  
 -- obj\_JumpHigh100  
 x=2,  
 y=752,  
 width=32,  
 height=48,  
  
 sourceX = 32,  
 sourceY = 24,  
 sourceWidth = 64,  
 sourceHeight = 64  
 },  
 {  
 -- obj\_JumpHigher000  
 x=2,  
 y=202,  
 width=40,  
 height=48,  
  
 sourceX = 20,  
 sourceY = 24,  
 sourceWidth = 64,  
 sourceHeight = 64  
 },  
 {  
 -- obj\_JumpHigher100  
 x=2,  
 y=152,  
 width=40,  
 height=48,  
  
 sourceX = 28,  
 sourceY = 24,  
 sourceWidth = 64,  
 sourceHeight = 64  
 },  
 {  
 -- obj\_JumpJoy000  
 x=2,  
 y=52,  
 width=48,  
 height=48,  
  
 sourceX = 16,  
 sourceY = 24,  
 sourceWidth = 64,  
 sourceHeight = 64  
 },  
 {  
 -- obj\_JumpJoy100  
 x=2,  
 y=2,  
 width=48,  
 height=48,  
  
 sourceX = 16,  
 sourceY = 24,  
 sourceWidth = 64,  
 sourceHeight = 64  
 },  
 {  
 -- obj\_JumpLand000  
 x=2,  
 y=1990,  
 width=40,  
 height=40,  
  
 sourceX = 20,  
 sourceY = 36,  
 sourceWidth = 64,  
 sourceHeight = 64  
 },  
 {  
 -- obj\_JumpLand100  
 x=52,  
 y=1730,  
 width=32,  
 height=40,  
  
 sourceX = 32,  
 sourceY = 36,  
 sourceWidth = 64,  
 sourceHeight = 64  
 },  
 {  
 -- obj\_JumpLong000  
 x=2,  
 y=102,  
 width=40,  
 height=48,  
  
 sourceX = 20,  
 sourceY = 24,  
 sourceWidth = 64,  
 sourceHeight = 64  
 },  
 {  
 -- obj\_JumpLong100  
 x=2,  
 y=702,  
 width=32,  
 height=48,  
  
 sourceX = 32,  
 sourceY = 24,  
 sourceWidth = 64,  
 sourceHeight = 64  
 },  
 {  
 -- obj\_Push000  
 x=52,  
 y=1688,  
 width=32,  
 height=40,  
  
 sourceX = 32,  
 sourceY = 36,  
 sourceWidth = 64,  
 sourceHeight = 64  
 },  
 {  
 -- obj\_Push100  
 x=52,  
 y=1646,  
 width=32,  
 height=40,  
  
 sourceX = 32,  
 sourceY = 36,  
 sourceWidth = 64,  
 sourceHeight = 64  
 },  
 {  
 -- obj\_Run000  
 x=2,  
 y=1738,  
 width=48,  
 height=40,  
  
 sourceX = 16,  
 sourceY = 36,  
 sourceWidth = 64,  
 sourceHeight = 64  
 },  
 {  
 -- obj\_Run001  
 x=52,  
 y=1604,  
 width=32,  
 height=40,  
  
 sourceX = 32,  
 sourceY = 36,  
 sourceWidth = 64,  
 sourceHeight = 64  
 },  
 {  
 -- obj\_Run002  
 x=52,  
 y=1562,  
 width=32,  
 height=40,  
  
 sourceX = 32,  
 sourceY = 36,  
 sourceWidth = 64,  
 sourceHeight = 64  
 },  
 {  
 -- obj\_Run003  
 x=52,  
 y=1520,  
 width=32,  
 height=40,  
  
 sourceX = 32,  
 sourceY = 36,  
 sourceWidth = 64,  
 sourceHeight = 64  
 },  
 {  
 -- obj\_Run004  
 x=2,  
 y=1948,  
 width=40,  
 height=40,  
  
 sourceX = 20,  
 sourceY = 36,  
 sourceWidth = 64,  
 sourceHeight = 64  
 },  
 {  
 -- obj\_Run005  
 x=52,  
 y=1478,  
 width=32,  
 height=40,  
  
 sourceX = 32,  
 sourceY = 36,  
 sourceWidth = 64,  
 sourceHeight = 64  
 },  
 {  
 -- obj\_Run006  
 x=2,  
 y=652,  
 width=32,  
 height=48,  
  
 sourceX = 32,  
 sourceY = 24,  
 sourceWidth = 64,  
 sourceHeight = 64  
 },  
 {  
 -- obj\_Run007  
 x=2,  
 y=602,  
 width=32,  
 height=48,  
  
 sourceX = 32,  
 sourceY = 24,  
 sourceWidth = 64,  
 sourceHeight = 64  
 },  
 {  
 -- obj\_Run100  
 x=2,  
 y=1696,  
 width=48,  
 height=40,  
  
 sourceX = 16,  
 sourceY = 36,  
 sourceWidth = 64,  
 sourceHeight = 64  
 },  
 {  
 -- obj\_Run101  
 x=52,  
 y=1436,  
 width=32,  
 height=40,  
  
 sourceX = 32,  
 sourceY = 36,  
 sourceWidth = 64,  
 sourceHeight = 64  
 },  
 {  
 -- obj\_Run102  
 x=52,  
 y=1394,  
 width=32,  
 height=40,  
  
 sourceX = 32,  
 sourceY = 36,  
 sourceWidth = 64,  
 sourceHeight = 64  
 },  
 {  
 -- obj\_Run103  
 x=36,  
 y=1352,  
 width=32,  
 height=40,  
  
 sourceX = 32,  
 sourceY = 36,  
 sourceWidth = 64,  
 sourceHeight = 64  
 },  
 {  
 -- obj\_Run104  
 x=2,  
 y=1654,  
 width=48,  
 height=40,  
  
 sourceX = 16,  
 sourceY = 36,  
 sourceWidth = 64,  
 sourceHeight = 64  
 },  
 {  
 -- obj\_Run105  
 x=36,  
 y=1310,  
 width=32,  
 height=40,  
  
 sourceX = 32,  
 sourceY = 36,  
 sourceWidth = 64,  
 sourceHeight = 64  
 },  
 {  
 -- obj\_Run106  
 x=2,  
 y=552,  
 width=32,  
 height=48,  
  
 sourceX = 32,  
 sourceY = 24,  
 sourceWidth = 64,  
 sourceHeight = 64  
 },  
 {  
 -- obj\_Run107  
 x=2,  
 y=502,  
 width=32,  
 height=48,  
  
 sourceX = 32,  
 sourceY = 24,  
 sourceWidth = 64,  
 sourceHeight = 64  
 },  
 {  
 -- obj\_Sit000  
 x=36,  
 y=1268,  
 width=32,  
 height=40,  
  
 sourceX = 32,  
 sourceY = 36,  
 sourceWidth = 64,  
 sourceHeight = 64  
 },  
 {  
 -- obj\_Sit100  
 x=36,  
 y=1226,  
 width=32,  
 height=40,  
  
 sourceX = 32,  
 sourceY = 36,  
 sourceWidth = 64,  
 sourceHeight = 64  
 },  
 {  
 -- obj\_Stab000  
 x=2,  
 y=1906,  
 width=40,  
 height=40,  
  
 sourceX = 28,  
 sourceY = 36,  
 sourceWidth = 64,  
 sourceHeight = 64  
 },  
 {  
 -- obj\_Stab001  
 x=2,  
 y=1612,  
 width=48,  
 height=40,  
  
 sourceX = 24,  
 sourceY = 36,  
 sourceWidth = 64,  
 sourceHeight = 64  
 },  
 {  
 -- obj\_Stab002  
 x=2,  
 y=1570,  
 width=48,  
 height=40,  
  
 sourceX = 24,  
 sourceY = 36,  
 sourceWidth = 64,  
 sourceHeight = 64  
 },  
 {  
 -- obj\_Stab003  
 x=2,  
 y=1528,  
 width=48,  
 height=40,  
  
 sourceX = 24,  
 sourceY = 36,  
 sourceWidth = 64,  
 sourceHeight = 64  
 },  
 {  
 -- obj\_Stab100  
 x=2,  
 y=1864,  
 width=40,  
 height=40,  
  
 sourceX = 20,  
 sourceY = 36,  
 sourceWidth = 64,  
 sourceHeight = 64  
 },  
 {  
 -- obj\_Stab101  
 x=2,  
 y=1486,  
 width=48,  
 height=40,  
  
 sourceX = 8,  
 sourceY = 36,  
 sourceWidth = 64,  
 sourceHeight = 64  
 },  
 {  
 -- obj\_Stab102  
 x=2,  
 y=1444,  
 width=48,  
 height=40,  
  
 sourceX = 8,  
 sourceY = 36,  
 sourceWidth = 64,  
 sourceHeight = 64  
 },  
 {  
 -- obj\_Stab103  
 x=2,  
 y=1402,  
 width=48,  
 height=40,  
  
 sourceX = 8,  
 sourceY = 36,  
 sourceWidth = 64,  
 sourceHeight = 64  
 },  
 {  
 -- obj\_Walk000  
 x=36,  
 y=1184,  
 width=32,  
 height=40,  
  
 sourceX = 32,  
 sourceY = 36,  
 sourceWidth = 64,  
 sourceHeight = 64  
 },  
 {  
 -- obj\_Walk001  
 x=36,  
 y=1142,  
 width=32,  
 height=40,  
  
 sourceX = 32,  
 sourceY = 36,  
 sourceWidth = 64,  
 sourceHeight = 64  
 },  
 {  
 -- obj\_Walk002  
 x=36,  
 y=1100,  
 width=32,  
 height=40,  
  
 sourceX = 32,  
 sourceY = 36,  
 sourceWidth = 64,  
 sourceHeight = 64  
 },  
 {  
 -- obj\_Walk003  
 x=36,  
 y=1058,  
 width=32,  
 height=40,  
  
 sourceX = 32,  
 sourceY = 36,  
 sourceWidth = 64,  
 sourceHeight = 64  
 },  
 {  
 -- obj\_Walk004  
 x=2,  
 y=452,  
 width=32,  
 height=48,  
  
 sourceX = 32,  
 sourceY = 24,  
 sourceWidth = 64,  
 sourceHeight = 64  
 },  
 {  
 -- obj\_Walk005  
 x=2,  
 y=402,  
 width=32,  
 height=48,  
  
 sourceX = 32,  
 sourceY = 24,  
 sourceWidth = 64,  
 sourceHeight = 64  
 },  
 {  
 -- obj\_Walk006  
 x=36,  
 y=1016,  
 width=32,  
 height=40,  
  
 sourceX = 32,  
 sourceY = 36,  
 sourceWidth = 64,  
 sourceHeight = 64  
 },  
 {  
 -- obj\_Walk007  
 x=36,  
 y=974,  
 width=32,  
 height=40,  
  
 sourceX = 32,  
 sourceY = 36,  
 sourceWidth = 64,  
 sourceHeight = 64  
 },  
 {  
 -- obj\_Walk100  
 x=36,  
 y=932,  
 width=32,  
 height=40,  
  
 sourceX = 32,  
 sourceY = 36,  
 sourceWidth = 64,  
 sourceHeight = 64  
 },  
 {  
 -- obj\_Walk101  
 x=36,  
 y=890,  
 width=32,  
 height=40,  
  
 sourceX = 32,  
 sourceY = 36,  
 sourceWidth = 64,  
 sourceHeight = 64  
 },  
 {  
 -- obj\_Walk102  
 x=36,  
 y=848,  
 width=32,  
 height=40,  
  
 sourceX = 32,  
 sourceY = 36,  
 sourceWidth = 64,  
 sourceHeight = 64  
 },  
 {  
 -- obj\_Walk103  
 x=36,  
 y=806,  
 width=32,  
 height=40,  
  
 sourceX = 32,  
 sourceY = 36,  
 sourceWidth = 64,  
 sourceHeight = 64  
 },  
 {  
 -- obj\_Walk104  
 x=2,  
 y=352,  
 width=32,  
 height=48,  
  
 sourceX = 32,  
 sourceY = 24,  
 sourceWidth = 64,  
 sourceHeight = 64  
 },  
 {  
 -- obj\_Walk105  
 x=2,  
 y=302,  
 width=32,  
 height=48,  
  
 sourceX = 32,  
 sourceY = 24,  
 sourceWidth = 64,  
 sourceHeight = 64  
 },  
 {  
 -- obj\_Walk106  
 x=36,  
 y=764,  
 width=32,  
 height=40,  
  
 sourceX = 32,  
 sourceY = 36,  
 sourceWidth = 64,  
 sourceHeight = 64  
 },  
 {  
 -- obj\_Walk107  
 x=36,  
 y=722,  
 width=32,  
 height=40,  
  
 sourceX = 32,  
 sourceY = 36,  
 sourceWidth = 64,  
 sourceHeight = 64  
 },  
 },  
  
 sheetContentWidth = 2048,  
 sheetContentHeight = 2048  
}  
  
SheetInfo.frameIndex =  
{  
  
 ["obj\_Box000"] = 1,  
 ["obj\_Box001"] = 2,  
 ["obj\_Box002"] = 3,  
 ["obj\_Box003"] = 4,  
 ["obj\_Box004"] = 5,  
 ["obj\_Box005"] = 6,  
 ["obj\_Box100"] = 7,  
 ["obj\_Box101"] = 8,  
 ["obj\_Box102"] = 9,  
 ["obj\_Box103"] = 10,  
 ["obj\_Box104"] = 11,  
 ["obj\_Box105"] = 12,  
 ["obj\_Crouch000"] = 13,  
 ["obj\_Crouch100"] = 14,  
 ["obj\_Doze000"] = 15,  
 ["obj\_Doze100"] = 16,  
 ["obj\_FallFlat000"] = 17,  
 ["obj\_FallFlat001"] = 18,  
 ["obj\_FallFlat100"] = 19,  
 ["obj\_FallFlat101"] = 20,  
 ["obj\_FireBigGun000"] = 21,  
 ["obj\_FireBigGun001"] = 22,  
 ["obj\_FireBigGun100"] = 23,  
 ["obj\_FireBigGun101"] = 24,  
 ["obj\_FireBigGunCrouch000"] = 25,  
 ["obj\_FireBigGunCrouch001"] = 26,  
 ["obj\_FireBigGunCrouch100"] = 27,  
 ["obj\_FireBigGunCrouch101"] = 28,  
 ["obj\_FireGun000"] = 29,  
 ["obj\_FireGun001"] = 30,  
 ["obj\_FireGun100"] = 31,  
 ["obj\_FireGun101"] = 32,  
 ["obj\_FireGunCrouch000"] = 33,  
 ["obj\_FireGunCrouch001"] = 34,  
 ["obj\_FireGunCrouch100"] = 35,  
 ["obj\_FireGunCrouch101"] = 36,  
 ["obj\_Flat000"] = 37,  
 ["obj\_Flat100"] = 38,  
 ["obj\_Flying000"] = 39,  
 ["obj\_Flying001"] = 40,  
 ["obj\_Flying100"] = 41,  
 ["obj\_Flying101"] = 42,  
 ["obj\_Idle000"] = 43,  
 ["obj\_Idle001"] = 44,  
 ["obj\_Idle002"] = 45,  
 ["obj\_Idle003"] = 46,  
 ["obj\_Idle100"] = 47,  
 ["obj\_Idle101"] = 48,  
 ["obj\_Idle102"] = 49,  
 ["obj\_Idle103"] = 50,  
 ["obj\_Jump000"] = 51,  
 ["obj\_Jump100"] = 52,  
 ["obj\_JumpHigh000"] = 53,  
 ["obj\_JumpHigh100"] = 54,  
 ["obj\_JumpHigher000"] = 55,  
 ["obj\_JumpHigher100"] = 56,  
 ["obj\_JumpJoy000"] = 57,  
 ["obj\_JumpJoy100"] = 58,  
 ["obj\_JumpLand000"] = 59,  
 ["obj\_JumpLand100"] = 60,  
 ["obj\_JumpLong000"] = 61,  
 ["obj\_JumpLong100"] = 62,  
 ["obj\_Push000"] = 63,  
 ["obj\_Push100"] = 64,  
 ["obj\_Run000"] = 65,  
 ["obj\_Run001"] = 66,  
 ["obj\_Run002"] = 67,  
 ["obj\_Run003"] = 68,  
 ["obj\_Run004"] = 69,  
 ["obj\_Run005"] = 70,  
 ["obj\_Run006"] = 71,  
 ["obj\_Run007"] = 72,  
 ["obj\_Run100"] = 73,  
 ["obj\_Run101"] = 74,  
 ["obj\_Run102"] = 75,  
 ["obj\_Run103"] = 76,  
 ["obj\_Run104"] = 77,  
 ["obj\_Run105"] = 78,  
 ["obj\_Run106"] = 79,  
 ["obj\_Run107"] = 80,  
 ["obj\_Sit000"] = 81,  
 ["obj\_Sit100"] = 82,  
 ["obj\_Stab000"] = 83,  
 ["obj\_Stab001"] = 84,  
 ["obj\_Stab002"] = 85,  
 ["obj\_Stab003"] = 86,  
 ["obj\_Stab100"] = 87,  
 ["obj\_Stab101"] = 88,  
 ["obj\_Stab102"] = 89,  
 ["obj\_Stab103"] = 90,  
 ["obj\_Walk000"] = 91,  
 ["obj\_Walk001"] = 92,  
 ["obj\_Walk002"] = 93,  
 ["obj\_Walk003"] = 94,  
 ["obj\_Walk004"] = 95,  
 ["obj\_Walk005"] = 96,  
 ["obj\_Walk006"] = 97,  
 ["obj\_Walk007"] = 98,  
 ["obj\_Walk100"] = 99,  
 ["obj\_Walk101"] = 100,  
 ["obj\_Walk102"] = 101,  
 ["obj\_Walk103"] = 102,  
 ["obj\_Walk104"] = 103,  
 ["obj\_Walk105"] = 104,  
 ["obj\_Walk106"] = 105,  
 ["obj\_Walk107"] = 106,  
}  
  
function SheetInfo:getSheet()  
 return self.sheet;  
end  
  
function SheetInfo:getFrameIndex(name)  
 return self.frameIndex[name];  
end  
  
return SheetInfo  
  

Thanks for any help! [import]uid: 36054 topic_id: 35721 reply_id: 335721[/import]

Hi @PuzzleRunner,
Wow, that’s a lot of code (frames). :wink:

I’d have to see your sprite sheet to know for sure, but a few things I suspect are going on.

  1. If you’re using TexturePacker 3.0.5, upgrade (if possible) or revert to 3.0.4. I think there was a bug introduced to 3.0.5 that caused image positioning issues with Corona. I think a new release is out, but I haven’t checked in a few days.

  2. I see you’re using trimmed sprites, hence all the “sourceX”, “sourceY”, etc. At this time, Corona supports only center reference positioning on trimmed sprites. I never used SpriteLoq, but in TP it’s important to note that trimmed sprites, once put into Corona, will honor the transparent pixels that were trimmed, in a -positional- standpoint, and around the center point only. So, you have to imagine that the sprite, in Corona, might appear as the trimmed size (and indeed, if you print its width and height, it will reflect that), but from a positioning standpoint and a physics body placement, it’s treated as if it resides on the original, untrimmed “frame canvas” size, oriented around the center of that theoretical bounding rectangle.

Again, I’d have to see your sprite sheet setup, but you should investigate the other Trim modes in TP… these can pick frames from your sheet and “ignore” the “original untrimmed size” when outputting to the screen.

Best regards,
Brent
[import]uid: 200026 topic_id: 35721 reply_id: 142059[/import]

@Puzzle, I (and many devs) have the same physics challenges you have run into. There was a thread going to try to identify/resolve them here:

http://developer.coronalabs.com/forum/2010/08/02/scaling-physics-bodies-attached-sprites

However, after this thread died, a dev put up some really useful info in the Code Exchange, here:

http://developer.coronalabs.com/code/body-modification

It essentially allows a you to change the physical body of the add.body property has been called. [import]uid: 135394 topic_id: 35721 reply_id: 142079[/import]

@Brent Thanks for the information on TexturePacker. Upgrading resolved the problem where the physics rectangle was far to the top left of the sprite. From a horizontal perspective, the physics rectangle and the sprite are now aligned.

From a vertical perspective, things are just a little bit off. Here’s a screenshot to show the issue:
Sprite
(The sprites legs are below the rectangle, and there is too much empty space above him)

I could probably get by if this issue was resolved. I did try multiple trim formats and such in TexturePacker, but it didn’t help.

I suspect that if I manually defined the physics rectangle itself I might be able to solve the issue, but It’d be ideal if things fit together naturally. [import]uid: 36054 topic_id: 35721 reply_id: 142195[/import]

Hi @Puzzle,
Can you email me your character image sheet? I promise I won’t use it for anything except to check this issue, to respect if you bought it or created it yourself. Email is brent AT coronalabs DOT com.

Thanks,
Brent [import]uid: 200026 topic_id: 35721 reply_id: 142338[/import]

Hi @PuzzleRunner,
Wow, that’s a lot of code (frames). :wink:

I’d have to see your sprite sheet to know for sure, but a few things I suspect are going on.

  1. If you’re using TexturePacker 3.0.5, upgrade (if possible) or revert to 3.0.4. I think there was a bug introduced to 3.0.5 that caused image positioning issues with Corona. I think a new release is out, but I haven’t checked in a few days.

  2. I see you’re using trimmed sprites, hence all the “sourceX”, “sourceY”, etc. At this time, Corona supports only center reference positioning on trimmed sprites. I never used SpriteLoq, but in TP it’s important to note that trimmed sprites, once put into Corona, will honor the transparent pixels that were trimmed, in a -positional- standpoint, and around the center point only. So, you have to imagine that the sprite, in Corona, might appear as the trimmed size (and indeed, if you print its width and height, it will reflect that), but from a positioning standpoint and a physics body placement, it’s treated as if it resides on the original, untrimmed “frame canvas” size, oriented around the center of that theoretical bounding rectangle.

Again, I’d have to see your sprite sheet setup, but you should investigate the other Trim modes in TP… these can pick frames from your sheet and “ignore” the “original untrimmed size” when outputting to the screen.

Best regards,
Brent
[import]uid: 200026 topic_id: 35721 reply_id: 142059[/import]

@Puzzle, I (and many devs) have the same physics challenges you have run into. There was a thread going to try to identify/resolve them here:

http://developer.coronalabs.com/forum/2010/08/02/scaling-physics-bodies-attached-sprites

However, after this thread died, a dev put up some really useful info in the Code Exchange, here:

http://developer.coronalabs.com/code/body-modification

It essentially allows a you to change the physical body of the add.body property has been called. [import]uid: 135394 topic_id: 35721 reply_id: 142079[/import]

@Brent Thanks for the information on TexturePacker. Upgrading resolved the problem where the physics rectangle was far to the top left of the sprite. From a horizontal perspective, the physics rectangle and the sprite are now aligned.

From a vertical perspective, things are just a little bit off. Here’s a screenshot to show the issue:
Sprite
(The sprites legs are below the rectangle, and there is too much empty space above him)

I could probably get by if this issue was resolved. I did try multiple trim formats and such in TexturePacker, but it didn’t help.

I suspect that if I manually defined the physics rectangle itself I might be able to solve the issue, but It’d be ideal if things fit together naturally. [import]uid: 36054 topic_id: 35721 reply_id: 142195[/import]

Hi @Puzzle,
Can you email me your character image sheet? I promise I won’t use it for anything except to check this issue, to respect if you bought it or created it yourself. Email is brent AT coronalabs DOT com.

Thanks,
Brent [import]uid: 200026 topic_id: 35721 reply_id: 142338[/import]