1 decade ago by littlefoot
Hi guys,
I just got Impact yesterday and am working on a small game to learn the ropes. Regular 2D platformer, character runs on screen collecting items for points etc.
So far I have the entity moving on an image background (the background image is wider than the canvas) and animating successfully with placeholder sprites. Movement so far is left, right, and jump (I'll need to build crouch in later).
My big problem right now is getting the camera to stay centered on the player entity. I read through Jesse Freeman's tutorial on Adobe.com and also checked out the demos (specifically the Jump n Run). These were very helpful and I've used them greatly in what I have so far. However the method both of these things suggest to center the camera on the entity doesn't seem to work for me. I've been searching the forums for hours now, and Googling, but no luck.
What I need: For the player entity to be in the center of the camera. As the player moves the player entity using WASD the camera scrolls with it, displaying different parts of the background image.
What is happening: When I try to implement this code the player entity loads above the ground, moves very slowly (~1px at a time), and can only move maybe up to 5 pixels in either direction.
My main.js:
I must be missing something very simple here. I'm using the main.js camera follow code as shown in the tutorial and Jump n Run and compared my player entity code to the Jump n Run demo, but couldn't find anything that looked relevant (although I'm sure I may be missing something). Was something meant to be happening in the player entity file that has an impact on this, or am I making some other mistake?
Thanks in advance for your help!
I just got Impact yesterday and am working on a small game to learn the ropes. Regular 2D platformer, character runs on screen collecting items for points etc.
So far I have the entity moving on an image background (the background image is wider than the canvas) and animating successfully with placeholder sprites. Movement so far is left, right, and jump (I'll need to build crouch in later).
My big problem right now is getting the camera to stay centered on the player entity. I read through Jesse Freeman's tutorial on Adobe.com and also checked out the demos (specifically the Jump n Run). These were very helpful and I've used them greatly in what I have so far. However the method both of these things suggest to center the camera on the entity doesn't seem to work for me. I've been searching the forums for hours now, and Googling, but no luck.
What I need: For the player entity to be in the center of the camera. As the player moves the player entity using WASD the camera scrolls with it, displaying different parts of the background image.
What is happening: When I try to implement this code the player entity loads above the ground, moves very slowly (~1px at a time), and can only move maybe up to 5 pixels in either direction.
My main.js:
ig.module( 'game.main' ) .requires( 'impact.game', 'impact.font', 'game.entities.red-player', 'game.levels.main' ) .defines(function(){ MyGame = ig.Game.extend({ // Load a font font: new ig.Font( 'media/04b03.font.png' ), clearColor: null, // no clear color gravity: 500, // Load background background: new ig.Image ( 'media/background.jpg' ), init: function() { // Initialize your game here; bind keys etc. ig.input.bind( ig.KEY.RIGHT_ARROW, 'right' ); ig.input.bind( ig.KEY.D, 'right' ); ig.input.bind( ig.KEY.LEFT_ARROW, 'left' ); ig.input.bind( ig.KEY.A, 'left' ); ig.input.bind( ig.KEY.UP_ARROW, 'jump' ); ig.input.bind( ig.KEY.W, 'jump' ); this.loadLevel( LevelMain ); }, update: function() { // screen follows the player var player = this.getEntitiesByType( EntityRedPlayer )[0]; if( player ) { this.screen.x = player.pos.x - ig.system.width/2; this.screen.y = player.pos.y - ig.system.height/2; } // Update all entities and BackgroundMaps this.parent(); }, draw: function() { this.background.draw( 0, 0 ); // Draw all entities and backgroundMaps this.parent(); } }); // Start the Game with 60fps, a resolution of 320x240, scaled // up by a factor of 2 ig.main( '#canvas', MyGame, 60, 800, 560, 1 ); });
I must be missing something very simple here. I'm using the main.js camera follow code as shown in the tutorial and Jump n Run and compared my player entity code to the Jump n Run demo, but couldn't find anything that looked relevant (although I'm sure I may be missing something). Was something meant to be happening in the player entity file that has an impact on this, or am I making some other mistake?
Thanks in advance for your help!