[phpBB Debug] PHP Warning: in file [ROOT]/includes/bbcode.php on line 488: preg_replace(): The /e modifier is no longer supported, use preg_replace_callback instead
[phpBB Debug] PHP Warning: in file [ROOT]/includes/bbcode.php on line 488: preg_replace(): The /e modifier is no longer supported, use preg_replace_callback instead
[phpBB Debug] PHP Warning: in file [ROOT]/includes/bbcode.php on line 488: preg_replace(): The /e modifier is no longer supported, use preg_replace_callback instead
[phpBB Debug] PHP Warning: in file [ROOT]/includes/bbcode.php on line 488: preg_replace(): The /e modifier is no longer supported, use preg_replace_callback instead
[phpBB Debug] PHP Warning: in file [ROOT]/includes/bbcode.php on line 488: preg_replace(): The /e modifier is no longer supported, use preg_replace_callback instead
[phpBB Debug] PHP Warning: in file [ROOT]/includes/bbcode.php on line 488: preg_replace(): The /e modifier is no longer supported, use preg_replace_callback instead
[phpBB Debug] PHP Warning: in file [ROOT]/includes/bbcode.php on line 488: preg_replace(): The /e modifier is no longer supported, use preg_replace_callback instead
[phpBB Debug] PHP Warning: in file [ROOT]/includes/bbcode.php on line 488: preg_replace(): The /e modifier is no longer supported, use preg_replace_callback instead
[phpBB Debug] PHP Warning: in file [ROOT]/includes/bbcode.php on line 488: preg_replace(): The /e modifier is no longer supported, use preg_replace_callback instead
[phpBB Debug] PHP Warning: in file [ROOT]/includes/bbcode.php on line 488: preg_replace(): The /e modifier is no longer supported, use preg_replace_callback instead
[phpBB Debug] PHP Warning: in file [ROOT]/includes/bbcode.php on line 488: preg_replace(): The /e modifier is no longer supported, use preg_replace_callback instead
[phpBB Debug] PHP Warning: in file [ROOT]/includes/bbcode.php on line 488: preg_replace(): The /e modifier is no longer supported, use preg_replace_callback instead
[phpBB Debug] PHP Warning: in file [ROOT]/includes/bbcode.php on line 488: preg_replace(): The /e modifier is no longer supported, use preg_replace_callback instead
[phpBB Debug] PHP Warning: in file [ROOT]/includes/bbcode.php on line 488: preg_replace(): The /e modifier is no longer supported, use preg_replace_callback instead
[phpBB Debug] PHP Warning: in file [ROOT]/includes/bbcode.php on line 488: preg_replace(): The /e modifier is no longer supported, use preg_replace_callback instead
[phpBB Debug] PHP Warning: in file [ROOT]/includes/bbcode.php on line 488: preg_replace(): The /e modifier is no longer supported, use preg_replace_callback instead
[phpBB Debug] PHP Warning: in file [ROOT]/includes/bbcode.php on line 488: preg_replace(): The /e modifier is no longer supported, use preg_replace_callback instead
[phpBB Debug] PHP Warning: in file [ROOT]/includes/bbcode.php on line 488: preg_replace(): The /e modifier is no longer supported, use preg_replace_callback instead
[phpBB Debug] PHP Warning: in file [ROOT]/includes/bbcode.php on line 488: preg_replace(): The /e modifier is no longer supported, use preg_replace_callback instead
[phpBB Debug] PHP Warning: in file [ROOT]/includes/bbcode.php on line 488: preg_replace(): The /e modifier is no longer supported, use preg_replace_callback instead
[phpBB Debug] PHP Warning: in file [ROOT]/includes/bbcode.php on line 488: preg_replace(): The /e modifier is no longer supported, use preg_replace_callback instead
[phpBB Debug] PHP Warning: in file [ROOT]/includes/bbcode.php on line 488: preg_replace(): The /e modifier is no longer supported, use preg_replace_callback instead
[phpBB Debug] PHP Warning: in file [ROOT]/includes/bbcode.php on line 488: preg_replace(): The /e modifier is no longer supported, use preg_replace_callback instead
[phpBB Debug] PHP Warning: in file [ROOT]/includes/bbcode.php on line 488: preg_replace(): The /e modifier is no longer supported, use preg_replace_callback instead
[phpBB Debug] PHP Warning: in file [ROOT]/includes/bbcode.php on line 488: preg_replace(): The /e modifier is no longer supported, use preg_replace_callback instead
[phpBB Debug] PHP Warning: in file [ROOT]/includes/bbcode.php on line 488: preg_replace(): The /e modifier is no longer supported, use preg_replace_callback instead
[phpBB Debug] PHP Warning: in file [ROOT]/includes/functions.php on line 4762: Cannot modify header information - headers already sent by (output started at [ROOT]/includes/functions.php:3897)
[phpBB Debug] PHP Warning: in file [ROOT]/includes/functions.php on line 4764: Cannot modify header information - headers already sent by (output started at [ROOT]/includes/functions.php:3897)
[phpBB Debug] PHP Warning: in file [ROOT]/includes/functions.php on line 4765: Cannot modify header information - headers already sent by (output started at [ROOT]/includes/functions.php:3897)
[phpBB Debug] PHP Warning: in file [ROOT]/includes/functions.php on line 4766: Cannot modify header information - headers already sent by (output started at [ROOT]/includes/functions.php:3897)
Chipmunk Physics • View topic - rotating a static body graphic.

rotating a static body graphic.

Official forum for the .

rotating a static body graphic.

Postby ijerry » Thu Dec 23, 2010 5:15 am

Hi

I have a graphic resource png wall 150 heigh x 3 width wich is vertically alligned in the graphic.

how can i plot this on the screen at 45 degrees

Should i create a new graphic resource which is rotated 45 degrees or can i rotate it within the code.

It is also being added as a static body in chipmunk.

if so how is it done ?
ijerry
 
Posts: 9
Joined: Tue Sep 28, 2010 8:08 am

Re: rotating a static body graphic.

Postby aisman » Thu Dec 23, 2010 5:35 am

Put the PNG into a sprite.
After this you can rotate the sprite.
Chipmunk4PB: The fastest way to write games together with PureBasic and the Chipmunk physics engine.
User avatar
aisman
 
Posts: 144
Joined: Tue Mar 04, 2008 2:21 am

Re: rotating a static body graphic.

Postby ijerry » Thu Dec 23, 2010 1:45 pm

Thats the question how does one rotate the graphic.

It is rectangular, it is a static wall usually, but in this case i want to initialize its position by rotating it and indirectly rotating the shape.

Below is the code after which i want to rotate graphic and cpbody/cpshape ?

Thank you.

cpBody *staticBody = cpBodyNew(INFINITY, INFINITY);
cpShape *shape;
CCSprite * wallsprite = [CCSprite spriteWithSpriteFrameName:@"verticalwallshort.png"];
[vsheet addChild:wallsprite];
wallsprite.position = ccp(x,y);
int num = 4;
CGPoint verts[] = {
ccp(-3,-28),
ccp(-3, 28),
ccp( 3, 28),
ccp( 3,-28),
};
staticBody->p = ccp(x, y);
cpShape* newShape = cpPolyShapeNew(staticBody, 4, verts, cpv(0.0f, 0.0f));
newShape->e = 0.5; newShape->u = 0.5; newShape->collision_type = 2;

cpSpaceAddStaticShape(space,newShape);
ijerry
 
Posts: 9
Joined: Tue Sep 28, 2010 8:08 am

Re: rotating a static body graphic.

Postby slembcke » Thu Dec 23, 2010 3:21 pm

Your Cocos2D and Chipmunk code doesn't reference the other in any way. What prevents you from setting wallSprite.rotation = 45?
Can't sleep... Chipmunks will eat me...
Check out our latest projects! -> http://howlingmoonsoftware.com/wordpress/
User avatar
slembcke
Site Admin
 
Posts: 4164
Joined: Tue Aug 14, 2007 7:13 pm

Re: rotating a static body graphic.

Postby ijerry » Thu Dec 23, 2010 4:10 pm

Apologies over confusion. Thank you for response. I will have a go now.
ijerry
 
Posts: 9
Joined: Tue Sep 28, 2010 8:08 am

Re: rotating a static body graphic.

Postby ijerry » Thu Dec 23, 2010 8:29 pm

The graphic rotates but the shape / body does not rotate

Is there any thing i am missing
ijerry
 
Posts: 9
Joined: Tue Sep 28, 2010 8:08 am

Re: rotating a static body graphic.

Postby slembcke » Thu Dec 23, 2010 8:47 pm

You are already attaching the poly shape to it's own body, so just rotate that too. staticBody.a = CC_DEGREES_TO_RADIANS(45).
Can't sleep... Chipmunks will eat me...
Check out our latest projects! -> http://howlingmoonsoftware.com/wordpress/
User avatar
slembcke
Site Admin
 
Posts: 4164
Joined: Tue Aug 14, 2007 7:13 pm

Re: rotating a static body graphic.

Postby ijerry » Fri Dec 24, 2010 1:24 am

There must be something else .... this is still not doing the job ?

cpBody *staticBody = cpBodyNew(INFINITY, INFINITY);
cpShape *shape;
CCSprite * wallsprite = [CCSprite spriteWithSpriteFrameName:@"verticalwallshort.png"];
[vsheet addChild:wallsprite];
wallsprite.position = ccp(x,y);

int num = 4;
CGPoint verts[] = {
ccp(-3,-28),
ccp(-3, 28),
ccp( 3, 28),
ccp( 3,-28),
};
staticBody->p = ccp(x, y);
cpShape* newShape = cpPolyShapeNew(staticBody, 4, verts, cpv(0.0f, 0.0f));
newShape->e = 0.5; newShape->u = 0.5; newShape->collision_type = 2;
wallsprite.rotation=45;
staticBody->a = CC_DEGREES_TO_RADIANS(45);
cpSpaceAddStaticShape(space,newShape);
ijerry
 
Posts: 9
Joined: Tue Sep 28, 2010 8:08 am

Re: rotating a static body graphic.

Postby ijerry » Fri Dec 24, 2010 1:32 am

The image rotates but the physics body remains the same vertical ?
ijerry
 
Posts: 9
Joined: Tue Sep 28, 2010 8:08 am

Re: rotating a static body graphic.

Postby slembcke » Fri Dec 24, 2010 11:59 am

Depending on the version of Chipmunk you are using, you might have to rotate the body before attaching the static shape to it.
Can't sleep... Chipmunks will eat me...
Check out our latest projects! -> http://howlingmoonsoftware.com/wordpress/
User avatar
slembcke
Site Admin
 
Posts: 4164
Joined: Tue Aug 14, 2007 7:13 pm

Next

Return to Chipmunk2D Physics

Who is online

Users browsing this forum: No registered users and 1 guest

cron