Hey everyone!! I am trying to use chipmunk physics with my game, and for some reason when i run my game in cocos creator, only the sprite shows and nothing else happens. It doesn’t fall or move. This is my code. any help would be appreciated. Thanks!!
code__________
var body;
cc.Class({
extends: cc.Component,
properties: {
playerPrefab: {
default: null,
type: cc.Prefab
},
},
PhysicsInit: function(){
//create physics space
var space = this.space = new cp.Space();
space.gravity = cp.v(0.3, 0.5);
space.iterations = 60;
//here i setup my static walls
},
createPlayer: function(x, y){
var space = this.space;
var newPlayer = cc.instantiate(this.PlayerPrefab);
var pos = newPlayer.position = cc.v2(x,y);
var mass = 1;
var radius = 40;
var velocity = 10;
//make body for PlayerPrefab
body = space.addBody(new cp.Body(mass, cp.momentForCircle(mass, 0, radius, cp.v(0,0))));
body.setPos(pos);
body.setVel(cp.v(Math.sin(20) * velocity, Math.cos(20) * velocity));
//make shape for body
var playerShape = space.addShape(new cp.CircleShape(body, radius, cp.v(0,0)));
playerShape.setElasticity(0.8);
playerShape.setFriction(1);
// put the newly added node under the Canvas node
this.node.addChild(newPlayer, 13);
cc.log("printed");
},
// use this for initialization
onLoad: function () {
this.PhysicsInit();
var x = ((cc.winSize.width/2) + 30);
var y = ((cc.winSize.height/2) + 50);
this.createPlayer(200,300);
},
// called every frame, uncomment this function to activate update callback
update: function (dt) {
if (this.space) {
this.space.step(dt);
}
},
});