@Sagos wrote:
Hey, I was trying to write sth cool with cocos2d and i get stuck. DebugDrawing doesnt show anything ;/
I spent 4h looking for solution. I think it could be sth wrong with my implementation. ;/<canvas id="gameCanvas" width="560" height="450"></canvas> <script type="text/javascript"> window.onload = function(){ cc.game.onStart = function () { cc.LoaderScene.preload(["pics/HelloWorld.png"], function () { var MyScene = cc.Layer.extend({ ctor: function(){ this._super(); var screenSize = cc.director.getWinSize(); var b2Vec2 = Box2D.Common.Math.b2Vec2 , b2BodyDef = Box2D.Dynamics.b2BodyDef , b2Body = Box2D.Dynamics.b2Body , b2FixtureDef = Box2D.Dynamics.b2FixtureDef , b2Fixture = Box2D.Dynamics.b2Fixture , b2World = Box2D.Dynamics.b2World , b2MassData = Box2D.Collision.Shapes.b2MassData , b2PolygonShape = Box2D.Collision.Shapes.b2PolygonShape , b2CircleShape = Box2D.Collision.Shapes.b2CircleShape , b2DebugDraw = Box2D.Dynamics.b2DebugDraw; this.world = new b2World(new b2Vec2(0, -10), true); this.world.SetContinuousPhysics(true); var fixDef = new b2FixtureDef; fixDef.density = 1.0; fixDef.friction = 0.5; fixDef.restitution = 0.2; var bodyDef = new b2BodyDef; bodyDef.type = b2Body.b2_staticBody; bodyDef.position.x = 9; bodyDef.position.y = 13; fixDef.shape = new b2PolygonShape; fixDef.shape.SetAsBox(10, 0.5); this.world.CreateBody(bodyDef).CreateFixture(fixDef); bodyDef.type = b2Body.b2_dynamicBody; for (var i = 0; i < 10; ++i) { if (Math.random() > 0.5) { fixDef.shape = new b2PolygonShape; fixDef.shape.SetAsBox( Math.random() + 0.1 , Math.random() + 0.1 ); } else { fixDef.shape = new b2CircleShape( Math.random() + 0.1 ); } bodyDef.position.x = Math.random() * 10; bodyDef.position.y = Math.random() * 10; this.world.CreateBody(bodyDef).CreateFixture(fixDef); } var debugDraw = new Box2D.Dynamics.b2DebugDraw(); debugDraw.SetSprite(document.getElementById("gameCanvas").getContext("2d")); debugDraw.SetDrawScale(30.0); debugDraw.SetFillAlpha(0.3); debugDraw.SetLineThickness(1.0); debugDraw.SetFlags(Box2D.Dynamics.b2DebugDraw.e_shapeBit | Box2D.Dynamics.b2DebugDraw.e_jointBit); this.world.SetDebugDraw(debugDraw); this.world.DrawDebugData(); this.update(); this.scheduleUpdate(); }, update: function () { var dt = 1 / 60; var velocityIterations = 6; var positionIterations = 2; this.world.Step(dt, velocityIterations, positionIterations); }, }); cc.director.runScene(new MyScene()); }, this); }; cc.game.run("gameCanvas"); }; </script>
What could be wrong
i am very new in cocos2dhtml . Thanks for help
Posts: 1
Participants: 1