-
efaresLikes 0Problem Description
Hello,
I am trying to make a 2D race game using Cocos2d-x JavaScript. In my game, the players move left to right on the screen at a constant speed and there is no gravity. The player has a faceBody and carBody which create “the racer” and I only care about collision detection. Do I have to make a shape for each body or can I make 1 shape and make it the size of both bodies?
As you can see from my picture, if I do the 1 shape option, can I offset the shape to cover both bodies instead of it being centred to the faceBody? So I want to move the shape down and to the right.
-
Sonar Systems adminLikes 0
Try setting the position.
This reply has been verified.
-
efaresLikes 0
I tried but I don’t know if I’m either using the wrong syntax or it simply can’t be done because of physics and center of gravity reasons?
I tried:
playerShape.x → undefined
playerShape.getPositionX → undefined
playerShape.getPositionX() → says it’s not a function
I also looked into the Chipmunk documentation and there was something about chipmunk_unsafe.h? But my project is in JS.Is there a way to do this or will I just have to create a shape for both bodies after all?
-
Sonar Systems adminLikes 0
Try ->setPosition();
This reply has been verified.
-
efaresLikes 0
It says setPosition(x, y) is not a function.
I tried playerShape.p = cc.p(x, y) and it does not produce any errors but it also does not seem to have any effects. The red square doesn’t seem to move when I use that.
-
Sonar Systems adminLikes 0
I would say use a custom physics body
This reply has been verified.
-
efaresLikes 0
It’s ok, I decided to just use the carShape and not have a faceShape.
-
Sonar Systems adminLikes 0
Cool
Login to reply