1 decade ago by bram
Hello,
I'm making a scrolling game and I want the camera to follow the player without showing anything outside the main/collision layer. I've used the example in the Jumpnrun game. But I can't get it to work, if I run it right now it doesn't load so. this is my whole main.js at the moment.
Please don't watch the Dutch cometary :)
I'm making a scrolling game and I want the camera to follow the player without showing anything outside the main/collision layer. I've used the example in the Jumpnrun game. But I can't get it to work, if I run it right now it doesn't load so. this is my whole main.js at the moment.
ig.module(
'game.main'
)
.requires(
//Alles wat de engine nodig heeft.
'impact.game',
'impact.font',
'game.entities.player',
'plugins.camera',
//Levels
'game.levels.alphalevel'
)
.defines(function(){
MyGame = ig.Game.extend({
gravity: 425, //Zwaartekracht. Hoe hoog je springt. En hoe hard je loopt.
instructText: new ig.Font( 'media/04b03.font.png' ),
init: function() {
//Level laden
this.loadLevel( LevelAlphalevel ); //Het eerste level word geladen.
//Besturing
ig.input.bind(ig.KEY.LEFT_ARROW, 'left'); //Pijl naar links.
ig.input.bind(ig.KEY.RIGHT_ARROW, 'right'); //Pijl naar rechts.
ig.input.bind(ig.KEY.X, 'jump'); //X toets.
ig.input.bind(ig.KEY.C, 'shoot'); //C toets.
ig.input.bind(ig.KEY.UP_ARROW, 'jump');
},
loadLevel: function( data ) {
this.currentLevel = data;
this.parent( data );
this.setupCamera();
}
setupCamera: function() {
// Set up the camera. The camera's center is at a third of the screen
// size, i.e. somewhat shift left and up. Damping is set to 3px.
this.camera = new ig.Camera( ig.system.width/3, ig.system.height/3, 3 );
// The camera's trap (the deadzone in which the player can move with the
// camera staying fixed) is set to according to the screen size as well.
this.camera.trap.size.x = ig.system.width/10;
this.camera.trap.size.y = ig.system.height/3;
// The lookahead always shifts the camera in walking position; you can
// set it to 0 to disable.
this.camera.lookAhead.x = ig.system.width/6;
// Set camera's screen bounds and reposition the trap on the player
this.camera.max.x = this.collisionMap.pxWidth - ig.system.width;
this.camera.max.y = this.collisionMap.pxHeight - ig.system.height;
this.camera.set( this.player );
},
update: function() {
this.parent();
this.camera.follow( this.player );
},
draw: function() {
// Draw all entities and backgroundMaps
this.parent();
var x = ig.system.width/2,
y = ig.system.height - 10;
this.instructText.draw(
'Left/Right Moves, X/Up Jumps.', x, y, ig.Font.ALIGN.CENTER );
}
});
// Start the Game with 60fps, a resolution of 320x240, scaled
// up by a factor of 2
ig.main( '#canvas', MyGame, 60, 400, 256, 2 ); // Resolutie van het spel en hoe veel het spel vergroot is.
});
Please don't watch the Dutch cometary :)
