adding a filled rectangle to the space

Discuss any Chipmunk bugs here.
Post Reply
andrews
Posts: 16
Joined: Wed Apr 27, 2011 5:35 am
Contact:

adding a filled rectangle to the space

Post by andrews »

I have a board. I need to add filled rectangles around the perimeter of the board so the ball won't go through the wall at high speeds.

I am able to add rectangles, with thickness 1.0f, but that is more like a bound.

cpFloat thickness = 10.0f;

[space addBounds:CGRectMake([[ithDict objectForKey:k_PLIST_CONST_RECTANGLES_X] intValue],
[[ithDict objectForKey:k_PLIST_CONST_RECTANGLES_Y] intValue],
[[ithDict objectForKey:k_PLIST_CONST_RECTANGLES_W] intValue],
[[ithDict objectForKey:k_PLIST_CONST_RECTANGLES_H] intValue])
thickness:1.0f
elasticity:1.0f
friction:0.0f
layers:CP_ALL_LAYERS
group:CP_NO_GROUP
collisionType:blockBarrierType];

The objectForKey:k_PLIST_CONST_RECTANGLES_ values are the x,y,w,h of the rectangles.

How can I make it work with thickness?
is it added at the outside layer, or inside, or half/half?

I checked the documentation, but no details on thickness in ChipmunkShape.

(void) - addBounds:thickness:elasticity:friction:layers:group:collisionType:
Add a border of collision segments around a box. See ChipmunkShape for more information on the other parameters.
User avatar
slembcke
Site Admin
Posts: 4166
Joined: Tue Aug 14, 2007 7:13 pm
Contact:

Re: adding a filled rectangle to the space

Post by slembcke »

You are still passing 1.0 as the thickness. The thickness sets the radius of the line segment shapes it creates, but it also moves them outwards so the inner edge of them is always the size of the bounds you requested.
Can't sleep... Chipmunks will eat me...
Check out our latest projects! -> http://howlingmoonsoftware.com/wordpress/
andrews
Posts: 16
Joined: Wed Apr 27, 2011 5:35 am
Contact:

Re: adding a filled rectangle to the space

Post by andrews »

I played around with the thickness so in this example is 1.0 as you pointed out.

So the thickness is added to the original rectangle.
Thanks again for your quick response.
Post Reply

Who is online

Users browsing this forum: No registered users and 5 guests