1
votes

I've implemented simple example based on this

My example uses chipmunk along with cocos2d-js. The problem is that physic only works with web builds. With the other builds (native ones - ios, mac, win32) all object are shown but they just hang - no animation. My update method is called with specified intervals, where I execute "step" method on space object. All my sprites are loaded using PhysicSprite class.

PS: I'm using cocos2d-js v3.0alpha

2

2 Answers

0
votes

Use this tutorial: http://www.cocos2d-x.org/docs/tutorial/framework/html5/parkour-game-with-javascript-v3.0/chapter6/en

I tried it both in the browser and in the iphone simulator and it worked just fine.

0
votes

you should apply impulse on your physics body, they will move surely but if you would try to move the body with schedular by changing its coordinate on every call they will work on web but not on native ones like iOS or mac .

for example:-

var mass = 1;    
var width = 1, height = 1;
playerBody = new cp.Body(mass , cp.momentForBox(mass, width, height));
playerBody.applyImpulse(cp.v(200, 300), cp.v(0, 0));// now you can move your playerBody

it will work well on all the platform but if you try my alternate solution ie:-

 init: function{
   var mass = 1;    
   var width = 1, height = 1;
   this.playerBody = new cp.Body(mass , cp.momentForBox(mass, width, height));
   this.schedule(this.move);
},
move: function(dt){
   this.playerBody.getPos().x += 2 * dt;
   this.playerBody.getPos().y += 2 * dt;
 }

this will work on web but on native platform like iOS or mac it will not move the playerBody at all. i don't know the reason yet if i got one i will let you know