rotating a static body graphic.
-
- Posts: 9
- Joined: Tue Sep 28, 2010 8:08 am
- Contact:
rotating a static body graphic.
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 ?
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 ?
-
- Posts: 145
- Joined: Tue Mar 04, 2008 2:21 am
- Contact:
Re: rotating a static body graphic.
Put the PNG into a sprite.
After this you can rotate the sprite.
After this you can rotate the sprite.
Chipmunk4PB: The fastest way to write games together with PureBasic and the Chipmunk physics engine.
-
- Posts: 9
- Joined: Tue Sep 28, 2010 8:08 am
- Contact:
Re: rotating a static body graphic.
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);
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);
- slembcke
- Site Admin
- Posts: 4166
- Joined: Tue Aug 14, 2007 7:13 pm
- Contact:
Re: rotating a static body graphic.
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/
Check out our latest projects! -> http://howlingmoonsoftware.com/wordpress/
-
- Posts: 9
- Joined: Tue Sep 28, 2010 8:08 am
- Contact:
Re: rotating a static body graphic.
Apologies over confusion. Thank you for response. I will have a go now.
-
- Posts: 9
- Joined: Tue Sep 28, 2010 8:08 am
- Contact:
Re: rotating a static body graphic.
The graphic rotates but the shape / body does not rotate
Is there any thing i am missing
Is there any thing i am missing
- slembcke
- Site Admin
- Posts: 4166
- Joined: Tue Aug 14, 2007 7:13 pm
- Contact:
Re: rotating a static body graphic.
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/
Check out our latest projects! -> http://howlingmoonsoftware.com/wordpress/
-
- Posts: 9
- Joined: Tue Sep 28, 2010 8:08 am
- Contact:
Re: rotating a static body graphic.
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);
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);
-
- Posts: 9
- Joined: Tue Sep 28, 2010 8:08 am
- Contact:
Re: rotating a static body graphic.
The image rotates but the physics body remains the same vertical ?
- slembcke
- Site Admin
- Posts: 4166
- Joined: Tue Aug 14, 2007 7:13 pm
- Contact:
Re: rotating a static body graphic.
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/
Check out our latest projects! -> http://howlingmoonsoftware.com/wordpress/
Who is online
Users browsing this forum: No registered users and 26 guests