Transparent png and ground mask

Hi all,

I’m just getting started with Corona and cant seem to find a solution to this problem…

Basically I want the ground in a physics demo to have a curve in it (all the demos are flat) I therefore have edited the ground.png and also created a mask (ground_mask.png) and applied it to the ground.

Yet it still treats the ground as a flat square object??

I looked at the project using physics.setDrawMode( “debug” ) and the image is just a solid box.

Is there a way i can turn the ground into a curve e.g. using the alpha channel on a .png instead of a box?

This is what i have so far…

-- create a mask for the ground  
local groundmask = graphics.newMask( "ground\_mask.png" )  
  
--Add the ground  
local ground = display.newImage( "ground.png" )  
ground.x = 160; ground.y = 368  
-- add the mask to ground  
ground:setMask( groundmask )  
  
--move the mask so it matches the ground png  
ground.groundmaskX = ground.contentWidth\*0.5  
ground.groundmaskY = ground.contentHeight\*0.5  
  
-- add hit test to ground to take into accound mask  
ground.isHitTestMasked = true  
--add physiics to the ground  
physics.addBody( ground, "static", { friction=0.1 } )  
  
--Add the crate  
local crate = display.newImage( "crate.png" )  
crate.x = 90; crate.y = 90  
physics.addBody( crate, { density=3.0, friction=0.4, bounce=0.2 } )  
  

Any pointers appreciated Im sure i must be missing something here…

Thanks
[import]uid: 225935 topic_id: 35949 reply_id: 335949[/import]

Hi there,

By default, the boundary of a physics object is equal to the rectangular bounding box of the image it is attached to. So, regardless of whether your image itself is round, or you use a mask to make parts of it look round, by default the physics object will still be a rectangle.

To create a curved physics object, you could do one of two things.

First, you could make the ground a polygon body and use a series of short line segments to approximate a curved surface. However, a polygon body can only have 8 segments, so unless you use a complex physics body with multiple elements, you’ll have areas that are still flat (at an angle, but still flat).

Second, you could define the ground as a circular physics body. You would set its center to be somewhere far below the bottom of the screen, and set its radius so that it “peeks” just above the bottom of the screen, creating a curved surface.

Have a look at some of the documentation here: http://developer.coronalabs.com/content/game-edition-physics-bodies

Hope this helps!

  • Andrew [import]uid: 109711 topic_id: 35949 reply_id: 142900[/import]

Adding to what Andrew says, you cannot declare a physics body as “concave” in Box2D. So, you can’t create a “half pipe” kind of object unless you construct it using a multi-element body.

Brent [import]uid: 200026 topic_id: 35949 reply_id: 142925[/import]

Great thanks for the pointers guys - I will take a look :o) [import]uid: 225935 topic_id: 35949 reply_id: 143041[/import]

Hi there,

By default, the boundary of a physics object is equal to the rectangular bounding box of the image it is attached to. So, regardless of whether your image itself is round, or you use a mask to make parts of it look round, by default the physics object will still be a rectangle.

To create a curved physics object, you could do one of two things.

First, you could make the ground a polygon body and use a series of short line segments to approximate a curved surface. However, a polygon body can only have 8 segments, so unless you use a complex physics body with multiple elements, you’ll have areas that are still flat (at an angle, but still flat).

Second, you could define the ground as a circular physics body. You would set its center to be somewhere far below the bottom of the screen, and set its radius so that it “peeks” just above the bottom of the screen, creating a curved surface.

Have a look at some of the documentation here: http://developer.coronalabs.com/content/game-edition-physics-bodies

Hope this helps!

  • Andrew [import]uid: 109711 topic_id: 35949 reply_id: 142900[/import]

Adding to what Andrew says, you cannot declare a physics body as “concave” in Box2D. So, you can’t create a “half pipe” kind of object unless you construct it using a multi-element body.

Brent [import]uid: 200026 topic_id: 35949 reply_id: 142925[/import]

Great thanks for the pointers guys - I will take a look :o) [import]uid: 225935 topic_id: 35949 reply_id: 143041[/import]

Hi there,

By default, the boundary of a physics object is equal to the rectangular bounding box of the image it is attached to. So, regardless of whether your image itself is round, or you use a mask to make parts of it look round, by default the physics object will still be a rectangle.

To create a curved physics object, you could do one of two things.

First, you could make the ground a polygon body and use a series of short line segments to approximate a curved surface. However, a polygon body can only have 8 segments, so unless you use a complex physics body with multiple elements, you’ll have areas that are still flat (at an angle, but still flat).

Second, you could define the ground as a circular physics body. You would set its center to be somewhere far below the bottom of the screen, and set its radius so that it “peeks” just above the bottom of the screen, creating a curved surface.

Have a look at some of the documentation here: http://developer.coronalabs.com/content/game-edition-physics-bodies

Hope this helps!

  • Andrew [import]uid: 109711 topic_id: 35949 reply_id: 142900[/import]

Adding to what Andrew says, you cannot declare a physics body as “concave” in Box2D. So, you can’t create a “half pipe” kind of object unless you construct it using a multi-element body.

Brent [import]uid: 200026 topic_id: 35949 reply_id: 142925[/import]

Great thanks for the pointers guys - I will take a look :o) [import]uid: 225935 topic_id: 35949 reply_id: 143041[/import]

Hi there,

By default, the boundary of a physics object is equal to the rectangular bounding box of the image it is attached to. So, regardless of whether your image itself is round, or you use a mask to make parts of it look round, by default the physics object will still be a rectangle.

To create a curved physics object, you could do one of two things.

First, you could make the ground a polygon body and use a series of short line segments to approximate a curved surface. However, a polygon body can only have 8 segments, so unless you use a complex physics body with multiple elements, you’ll have areas that are still flat (at an angle, but still flat).

Second, you could define the ground as a circular physics body. You would set its center to be somewhere far below the bottom of the screen, and set its radius so that it “peeks” just above the bottom of the screen, creating a curved surface.

Have a look at some of the documentation here: http://developer.coronalabs.com/content/game-edition-physics-bodies

Hope this helps!

  • Andrew [import]uid: 109711 topic_id: 35949 reply_id: 142900[/import]

Adding to what Andrew says, you cannot declare a physics body as “concave” in Box2D. So, you can’t create a “half pipe” kind of object unless you construct it using a multi-element body.

Brent [import]uid: 200026 topic_id: 35949 reply_id: 142925[/import]

Great thanks for the pointers guys - I will take a look :o) [import]uid: 225935 topic_id: 35949 reply_id: 143041[/import]