Physics with scaled images

I’m creating a border around the screen using a single image, which is scaled based on the size of the display and the number of images used. Apparently, the physics engine is using the actual size of the image as the extent for collisions, evidenced by drawing in debug mode. Is there a way to get physics to use the scaled size of the image for collisions, or do I need to maintain different sized images for each type of display (iphone, ipad, droid) and just use a scale of 1.0?

The code to create a single image follows:

function newCrate(game, physics)  
 local sprt = display.newImage("crate.jpeg")  
 sprt.xScale = 1/NUM\_CRATES \* (display.contentWidth / sprt.contentWidth)  
 sprt.yScale = 1/NUM\_CRATES \* (display.contentHeight / sprt.contentHeight)  
 game:insert(sprt)  
  
 physics.addBody( sprt, "static", { friction=0.5, bounce=0.3 } )  
  
 return sprt  
end  

And this code draws the top row.

for i = 0, NUM\_CRATES - 1  
 do  
 local sprt = newCrate(game, physics)   
 sprt.x = sprt.contentWidth \* 0.5 + (sprt.contentWidth \* i)  
 sprt.y = sprt.contentHeight \* 0.5  
  
 top[i+1] = sprt  
 end  

Both the game group and physics module are passed in from the main.lua script. [import]uid: 58455 topic_id: 10590 reply_id: 310590[/import]

The physics library doesn’t handle scaling so here’s my workaround:

--for a local rotator local phyX = rotator.width \* .5 \* rotator.xScale local phyY = rotator.height \* .5 \* rotator.yScale rotatorShape = { -phyX, -phyY, phyX, -phyY, phyX, phyY, -phyX, phyY } physics.addBody(rotator, "dynamic", {density = 100, friction = .2, bounce = 0, shape=rotatorShape}) [import]uid: 49205 topic_id: 10590 reply_id: 38633[/import]

Thanks, but I just removed scaling code, resized my image to 32x32, and this config.lua seems to behave well on all simulator platforms. Since I know the image size and the display size, I know how many to draw.

application = { content = { width = 320, height = 480, scale = "zoomStretch" }, } [import]uid: 58455 topic_id: 10590 reply_id: 38776[/import]

Glad you got something working! [import]uid: 49205 topic_id: 10590 reply_id: 38791[/import]

How do I decrease the rotator function? so that the physics is smaller?
[import]uid: 51459 topic_id: 10590 reply_id: 40029[/import]

rotator is a display object. It was made with

local rotator = display.newImage("rotator.png")  

[import]uid: 49205 topic_id: 10590 reply_id: 40032[/import]

I just figured that out after i sent that, my image is a car and it is called player… do you know how to make the body smaller… right now I have this huge box around my car and if can make it smaller with this code I would very happy… I see that you are * the width and height by 5 how do I subtract it by -10 lets say… [import]uid: 51459 topic_id: 10590 reply_id: 40034[/import]

You might want to check this out:

http://www.physicseditor.de/ [import]uid: 49205 topic_id: 10590 reply_id: 40035[/import]

I don’t have the money for another third party item that I can’t follow how they do code… I don’t care about the shape it can still be a rectangle… I just want it a little smaller… please… someone has to know a way to make the box smaller… [import]uid: 51459 topic_id: 10590 reply_id: 40037[/import]

.5 just means half of the width. If you pass in a table of points, they create a physics body in that shape relative to the display object’s reference point.

so

rotatorShape = { -phyX, -phyY, phyX, -phyY, phyX, phyY, -phyX, phyY }  

Just covers the rectangle perfectly b/c you go half one way and half the other from the center.

If you want the body to be smaller, just use .3 instead of .5 [import]uid: 49205 topic_id: 10590 reply_id: 40072[/import]

Hey thanks for your help I figured it out!!! this is the line of code I used if anyone else has this same issue

squareShape = { -60,-30, 60,-30, 60,30, -60,30 }
physics.addBody(player,“dynamic”, {density=0.8, shape=squareShape}) [import]uid: 51459 topic_id: 10590 reply_id: 40131[/import]