views:

40

answers:

2

Hello.

I'm using Chipmunk with SpaceManager inside of Cocos2D. I have a body which is moving around with impulses, I'd like to be able to use that bodies location to drive a parallax node in Cocos2D.

So, when body 'a' moves to the left, the parallax follows but with a small time offset, or elastic effect. If you know AS3 and Flash, you can think of this as using a movieclip's x and y location to drive a constantly updating tween with an ease out effect. This is what I'd like to achieve, and after no sleep trying to work it out last night I've decided to ask you much more experienced people :)

Thanks.

A: 

You could associate an additional body with the parallax node, and attach it to body a with a suitable joint or set of joints. It is difficult to tell from the question what exact behaviour you are looking for, but at least one of slide, groove or damped-spring constraint should do the trick.

Marcelo Cantos
Hello. That sounds like it may work, it's the 'associate a body with the parallax node' that's causing me problems, that's the bit I can't quite work out. :) Thanks for responding.
Andrew
I don't know Cocos2D at all, but I'm guessing there is an API that can explicitly position the parallax node, which you would call with the output of cpBodyGetPos(my_elastic_body). Depending on the way parallax nodes work, you might also need to make it a normal non-parallex layer that is controlled by the body, possibly with some scale factor on the body's movement, in order to reintroduce the parallex effect. I apologise if this makes no sense due to my ignorance of Cocos2D.
Marcelo Cantos
A: 

Hello. I worked this out, for future ref in case others need it you use:

[voidNode setPosition:(yourShape.position)];

Andrew