Impact

This forum is read only and just serves as an archive. If you have any questions, please post them on github.com/phoboslab/impact

1 decade ago by Bricky

Here's game/entities/player.js
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 :)

1 decade ago by Snowleopard

not sure if this tip helps or if it's the problem you're dealing with, but make sure the player is outside of the world. if your collision map doesn't fully wrap around the player, then the sample code in the physics demo won't work and you should create the box2d world a different way.
Page 1 of 1
« first « previous next › last »