1 decade ago by coreysnyder
Below is my snowball class. I added one of these to my level via Weltmeister. I then later converted it over to a Box2D entity as seen below. After refreshing Weltmeister I get the error: Uncaught TypeError: Cannot read property 'CreateBody' of undefined on line 27. Does weltmeister not support the addition of Box2D entities?
ig.module( 'game.entities.snowball' ).requires( 'plugins.box2d.debug', 'plugins.box2d.game', 'plugins.box2d.entity' ).defines (function(){ EntitySnowball = ig.Box2DEntity.extend({ animSheet: new ig.AnimationSheet( 'media/web/ammo/fireball.png', 18, 18), size: {x: 18, y: 18}, type: ig.Entity.TYPE.NONE, checkAgainst: ig.Entity.TYPE.B, collides: ig.Entity.COLLIDES.NEVER, bounciness: 0.6, init: function (x, y, settings){ this.parent(x, y, settings); this.addAnim( 'idle', 1, [0]); //this.body.ApplyImpulse( new b2.Vec2(settings.velocity.x, settings.velocity.y), this.body.GetPosition() ); var velocity = 50; var bodyDef = new b2.BodyDef(); bodyDef.position.Set ( x, y ); console.log(ig.world); console.log(ig.world.CreateBody); var body = ig.world.CreateBody( bodyDef ); var shapeDef = new b2.CircleDef(); shapeDef.radius = (this.size.x/2) * b2.SCALE; body.CreateShape(shapeDef); body.SetMassFromShapes(); this.body.ApplyImpulse(new b2.Vec2(velocity, -30), this.body.GetPosition()); } }); });