Move static shapes, or another method?

Official forum for the Chipmunk2D Physics Library.
mrTortex
Posts: 51
Joined: Sat Jul 24, 2010 9:38 am
Contact:

Move static shapes, or another method?

Post by mrTortex »

Hello.

Using Cocos2D and Chipmunk together, I have a parallax node with three levels. I want to add a collision object to the front most level, but it must start off screen then move in. I've heard using a static shape, moving then re-hashing every frame is the bad way to do it, and I vaguely understand why. Currently however, this is the only way I can think to do it. Can anyone think of a better alternative, as at some point I'm going to need a fair amount more collision objects and I'd like to be as efficient as possible :)

Thanks.
User avatar
slembcke
Site Admin
Posts: 4166
Joined: Tue Aug 14, 2007 7:13 pm
Contact:

Re: Move static shapes, or another method?

Post by slembcke »

If you have a static shape that you are rehashing every frame, you should just add it as a normal shape. Static shapes are just an optimization for the collision detection so they don't have to be updated every frame. If you are doing that anyway, then you are just undoing the optimization in a very expensive way.
Can't sleep... Chipmunks will eat me...
Check out our latest projects! -> http://howlingmoonsoftware.com/wordpress/
mrTortex
Posts: 51
Joined: Sat Jul 24, 2010 9:38 am
Contact:

Re: Move static shapes, or another method?

Post by mrTortex »

OK, thought as much. So, I guess I give the collision object a huge mass or something so it doesn't get effected by the collision?

But, wont my shape be effect by gravity?

I have a feeling dynamic shapes are not would you'd call 'normal shapes', I'll go read.
User avatar
slembcke
Site Admin
Posts: 4166
Joined: Tue Aug 14, 2007 7:13 pm
Contact:

Re: Move static shapes, or another method?

Post by slembcke »

Collision hapes aren't affected by gravity, the rigid bodies the are attached to are. Bodies added to the space are simulated (and fall under gravity). Adding a shape to the space does not automatically add the body as well.

You should set the mass and moment of inertia of your externally controlled body to INFINITY.
Can't sleep... Chipmunks will eat me...
Check out our latest projects! -> http://howlingmoonsoftware.com/wordpress/
mobilebros
Posts: 90
Joined: Tue Aug 04, 2009 9:53 am
Contact:

Re: Move static shapes, or another method?

Post by mobilebros »

I believe you are using SpaceManager mrTortex, correct? If you are then it adds both the shape and body to the space when you use one of the creation methods, this means you would have to remove the body from the space "manually"; just take the returned shape and call the native chipmunk function:

Code: Select all

cpSpaceRemoveBody(smgr.space, shape->body);
mrTortex
Posts: 51
Joined: Sat Jul 24, 2010 9:38 am
Contact:

Re: Move static shapes, or another method?

Post by mrTortex »

Hello.

I am indeed, thanks for spotting my post and offering this. :) That's another pint I owe you.
mrTortex
Posts: 51
Joined: Sat Jul 24, 2010 9:38 am
Contact:

Re: Move static shapes, or another method?

Post by mrTortex »

Any idea why when I add Chipmunk shapes to the parallax node it crashes? Compiles fine, but then just fails.

I'll post code later if I can, code machine has no net access. :(
User avatar
slembcke
Site Admin
Posts: 4166
Joined: Tue Aug 14, 2007 7:13 pm
Contact:

Re: Move static shapes, or another method?

Post by slembcke »

Did you try running it in the debugger to find out what line it crashes on and why?
Can't sleep... Chipmunks will eat me...
Check out our latest projects! -> http://howlingmoonsoftware.com/wordpress/
mrTortex
Posts: 51
Joined: Sat Jul 24, 2010 9:38 am
Contact:

Re: Move static shapes, or another method?

Post by mrTortex »

Yep, nothing jumps out. It doesn't actually crash as such, it just hangs the device. In the simulator the level doesn't load, I just get a black screen. When I quit, it quits as it would with everything working. My code has grown to be messy as hell, let me have a tidy up and see where that gets me.
mrTortex
Posts: 51
Joined: Sat Jul 24, 2010 9:38 am
Contact:

Re: Move static shapes, or another method?

Post by mrTortex »

OK, nothing appears in the debugger but in the console:

Code: Select all

[Session started at 2010-07-27 19:34:27 +0100.]
2010-07-27 19:34:29.189 iLander[609:207] ******* Accessibility Status Changed: On
2010-07-27 19:34:29.223 iLander[609:207] ********** Loading AX for: com.yourcompany.iLander ************
2010-07-27 19:34:29.411 iLander[609:207] cocos2d: cocos2d v0.99.3
2010-07-27 19:34:29.412 iLander[609:207] cocos2d: Using Director Type:CCDisplayLinkDirector
2010-07-27 19:34:29.443 iLander[609:207] cocos2d: GL_VENDOR:   Apple Computer, Inc.
2010-07-27 19:34:29.444 iLander[609:207] cocos2d: GL_RENDERER: Apple Software Renderer
2010-07-27 19:34:29.444 iLander[609:207] cocos2d: GL_VERSION:  OpenGL ES-CM 1.1 APPLE
2010-07-27 19:34:29.445 iLander[609:207] cocos2d: GL_MAX_TEXTURE_SIZE: 2048
2010-07-27 19:34:29.446 iLander[609:207] cocos2d: GL_MAX_MODELVIEW_STACK_DEPTH: 16
2010-07-27 19:34:29.447 iLander[609:207] cocos2d: GL supports PVRTC: YES
2010-07-27 19:34:29.448 iLander[609:207] cocos2d: GL supports BGRA8888 textures: YES
2010-07-27 19:34:29.449 iLander[609:207] cocos2d: GL supports NPOT textures: YES
2010-07-27 19:34:29.450 iLander[609:207] cocos2d: GL supports discard_framebuffer: NO
2010-07-27 19:34:29.451 iLander[609:207] cocos2d: compiled with NPOT support: NO
2010-07-27 19:34:29.456 iLander[609:207] cocos2d: compiled with VBO support in TextureAtlas : YES
2010-07-27 19:34:29.457 iLander[609:207] cocos2d: compiled with Affine Matrix transformation in CCNode : YES
2010-07-27 19:34:29.464 iLander[609:207] cocos2d: compiled with Profiling Support: NO
2010-07-27 19:34:29.484 iLander[609:207] cocos2d: Frame interval: 1
2010-07-27 19:34:32.552 iLander[609:207] cocos2d: CCTexture2D. Can't create Texture. UIImage is nil
2010-07-27 19:34:32.553 iLander[609:207] cocos2d: Couldn't add image:Mini Thruster.png in CCTextureCache
Initializing Chipmunk v5.x.x (Debug Enabled)
Compile with -DNDEBUG defined to disable debug mode and runtime assertion checks
And here is some code which is pretty much how I'm trying to do this. I already know I'm not doing this correctly but Google isn't helping and neither is any documentation currently.

Code: Select all

[pNode addChild:myShape z:-7 parallaxRatio:ccp(0.0f, -0.6f) positionOffset:ccp(0,0)];
		
//then once everything else is set up add the parallax node
[gameLayer addChild:pNode z:-5 tag:kTagNode];
Post Reply

Who is online

Users browsing this forum: No registered users and 5 guests