Hello everyone!
I am still continue my journey with this awesome game engine. Thanks for great work!
Today I was trying to start with Chipmunk and CocosBuilder alpha4 with this tutoral:
and these examples:
I tried to do example “Balls” and my code looks following:
var MainScene = function(){};
var space;
MainScene.prototype.onDidLoadFromCCB = function()
{
this.rootNode.setTouchEnabled(true);
cc.log("onLoads");
cc.log("======== CHIPMUNK START ========");
space = cp.spaceNew();
space.gravity = cp.v(0, -500);
space.sleepTimeThreshold = 0.5;
space.collisionSlop = 0.5;
space.sleepTimeThreshold = 0.5;
var width = 50;
var height = 60;
var mass = width * height * 1/1000;
var rockBody = cp.bodyNew(mass, cp.momentForBox(mass, width, height));
var rock = cp.spaceAddBody(space, rockBody);
rock.p = cp.v(500, 100);
rock.angle = 1;
shape = cp.spaceAddShape(space, cp.boxShapeNew(rock, width, height));
shape.friction = 0.3;
shape.elasticity = 0.3;
for (var i = 1; i <= 10; i++) {
var radius = 20;
mass = 3;
var body = cp.spaceAddBody(space, cp.bodyNew(mass, cp.momentForCircle(mass, 0, radius, cp.v(0, 0))));
body.pos = cp.v(200 + i, (2 * radius + 5) * i);
var circle = cp.spaceAddShape(space, cp.circleShapeNew(body, radius, cp.v(0, 0)));
circle.elasticity = 0.8;
circle.friction = 1;
}
this.rootNode.schedule(update, 1);
};
function update(dt) {
cc.log("update");
cp.spaceStep(space, dt);
}
And I have HelloWorld scene (MainScene.ccb) and everything compiles without errors, I run it on CocosPlayer and I can’t see any ball. I just see sprite and button added directly to MainScene.ccb.
Update method is executing every second.
What is my mistake? What am I doing wrong?
Thanks for every advice.