Move static shapes, or another method?
-
- Posts: 51
- Joined: Sat Jul 24, 2010 9:38 am
- Contact:
Re: Move static shapes, or another method?
Thinking about it, if I add a body without a shape, can I still add a sprite? I guess I can animate the sprite in the tick method happily enough. But, how do I define the body's size, doesn't it need a shape to have a size?
I'm confusing the hell out of myself.
I'm confusing the hell out of myself.
- slembcke
- Site Admin
- Posts: 4166
- Joined: Tue Aug 14, 2007 7:13 pm
- Contact:
Re: Move static shapes, or another method?
did you try pausing the debugger when it hangs? If it's stuck in an infinite loop somewhere, you should be able to find out that way.
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: 51
- Joined: Sat Jul 24, 2010 9:38 am
- Contact:
Re: Move static shapes, or another method?
Hello.
Yep, tried pausing, it crashes the simulator and the debugger freezes. So I've obviously done something hideous.
Yep, tried pausing, it crashes the simulator and the debugger freezes. So I've obviously done something hideous.

-
- Posts: 51
- Joined: Sat Jul 24, 2010 9:38 am
- Contact:
Re: Move static shapes, or another method?
Just had a thought, instead of adding te body to the parallax node, why don't I just update the body position in my tick method from the position of the layer? One question remains, how do I give my body size so things can collide with it? I'd normally go with a rect.
-
- Posts: 90
- Joined: Tue Aug 04, 2009 9:53 am
- Contact:
Re: Move static shapes, or another method?
From your console error it sounds like "Mini Thruster.png" is not included in your project.... Also I'm hoping "myShape" is actually a type of CCNode; and also you have a sprite associated with a body but not a shape?... there's a bunch going on here lol 

-
- Posts: 51
- Joined: Sat Jul 24, 2010 9:38 am
- Contact:
Re: Move static shapes, or another method?
Hello.
Ye, that image is included and is showing fine on screen, so that's confusing.
I was tired last night, so will go at it again later and see how it goes.
Ye, that image is included and is showing fine on screen, so that's confusing.

I was tired last night, so will go at it again later and see how it goes.

-
- Posts: 51
- Joined: Sat Jul 24, 2010 9:38 am
- Contact:
Re: Move static shapes, or another method?
Hello again.
OK, thruster image is still causing issues even though it's included in the resources, so that one is confusing me still.
I've ripped out all the code that wasn't doing anything, and all the code to do with adding shapes to the parallax. It's super clean, so I'll go from there.
Would you mind showing me the cleanest way to create a rectangle shape and adding that to a layer? I don't want to start off with a mess again.
As far as I can see, I need a body to apply a shape to. Do I create the body, then shape, then kill the body?
It's been one of those days, so although my head hurts, I am determined to not sleep until this works.
OK, thruster image is still causing issues even though it's included in the resources, so that one is confusing me still.
I've ripped out all the code that wasn't doing anything, and all the code to do with adding shapes to the parallax. It's super clean, so I'll go from there.
Would you mind showing me the cleanest way to create a rectangle shape and adding that to a layer? I don't want to start off with a mess again.

It's been one of those days, so although my head hurts, I am determined to not sleep until this works.
-
- Posts: 90
- Joined: Tue Aug 04, 2009 9:53 am
- Contact:
Re: Move static shapes, or another method?
Code: Select all
//Create the rect
cpShape *shape = [smgr addRectAt:pos mass:mass width:width height:height rotation:0];
//Remove body if you want a "static-like" moveable object
cpSpaceRemoveBody(smgr.space, shape->body);
//If you want a drawn shape attached
cpShapeNode *node = [cpShapeNode nodeWithShape:shape];
//Blue's a fun color
node.color = ccBLUE;
//Assuming you're within a Layer or other CCNode type
[self addChild:node];
-
- Posts: 51
- Joined: Sat Jul 24, 2010 9:38 am
- Contact:
Re: Move static shapes, or another method?
Hello.
Ye, that works, but gets me back to where I started I think. Shapes don't have a position do they, not as far as I can see, so I can't update the position of the shape with the parallax. I can move a cpCCSprite but that doesn't change the position of the shape. :s
Why did I ever want to use Parallax?
Ye, that works, but gets me back to where I started I think. Shapes don't have a position do they, not as far as I can see, so I can't update the position of the shape with the parallax. I can move a cpCCSprite but that doesn't change the position of the shape. :s
Why did I ever want to use Parallax?

- slembcke
- Site Admin
- Posts: 4166
- Joined: Tue Aug 14, 2007 7:13 pm
- Contact:
Re: Move static shapes, or another method?
Shapes are always attached to a body. If you move the body they are attached to, the shape moves with it. Normally the space takes care of updating the velocity and position of objects so that you don't have to. If you do it yourself, you need to make sure the velocity matches how you are changing the position.
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 11 guests