1 decade ago by Bricky
Here's game/entities/player.js
Here's game/main.js
Player entity don't want move. I don't know why. Please help :)
ig.module( 'game.entities.player' ) .requires( 'impact.entity', 'plugins.box2d.entity' ) .defines(function() { EntityPlayer = ig.Box2DEntity.extend({ size: {x:60, y:136}, offset: {x: 4, y: 2}, collides: ig.Entity.COLLIDES.NEVER, type: ig.Entity.TYPE.A, checkAgainst: ig.Entity.TYPE.NONE, animSheet: new ig.AnimationSheet('media/player.png', 60, 136), init: function(x, y, settings) { this.parent(x, y, settings); this.addAnim('idle', 1, [0]); }, update: function() { if(ig.input.state('left')) { //this.vel.x = -100; this.body.ApplyForce(new b2.Vec2(-100, 0), this.body.GetPosition()); } else if(ig.input.state('right')) { //this.vel.x = 100; this.body.ApplyForce(new b2.Vec2(100, 0), this.body.GetPosition()); } else if(ig.input.state('jump')) { //this.vel.y = -350; this.body.ApplyForce(new b2.Vec2(0, -350), this.body.GetPosition()); } this.parent(); } }); });
Here's game/main.js
ig.module( 'game.main' ) .requires( 'impact.game', 'game.entities.player', 'impact.debug.debug', 'game.levels.begin', 'plugins.box2d.game' ) .defines(function(){ MyGame = ig.Box2DGame.extend({ gravity: 1000, clearColor: '#91C5FF', init: function() { // Initialize your game here; bind keys etc. ig.input.bind(ig.KEY.LEFT_ARROW, 'left'); ig.input.bind(ig.KEY.RIGHT_ARROW, 'right'); ig.input.bind(ig.KEY.UP_ARROW, 'jump'); this.loadLevel(LevelBegin); }, update: function() { // Update all entities and backgroundMaps this.parent(); var player = this.getEntitiesByType(EntityPlayer)[0]; if(player) { if(ig.system.width/2 < player.pos.x) { this.screen.x = player.pos.x - ig.system.width/2; } } }, draw: function() { // Draw all entities and backgroundMaps this.parent(); } }); // Start the Game with 60fps, a resolution of 728x480, scaled // up by a factor of 1 ig.main( '#canvas', MyGame, 60, 728, 383, 2); });
Player entity don't want move. I don't know why. Please help :)