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 fulvio

I was watching a couple of videos on YouTube of different platformer games.

I noticed that the way the camera follows the player is very different to the general way I setup my game player to follow the camera.

If you watch the videos you'll notice that the player starts from the bottom left hand side of the screen. When he makes his way all the top to the pillars in the center of the screen the ground is still visible.

Within my game if I don't set a repeating background my blocks are very far from the ground unlike the video and my player is always kept centered.

This is because I'm using the following code, which always places my character in the center of the screen and the camera follows from there:

update: function() {
    // screen follows the player
    if( this.player ) {
	    this.screen.x = this.player.pos.x - ig.system.width/2;
        this.screen.y = this.player.pos.y - ig.system.height/2;
    }
}

I'm not quite sure what camera follow technique is used within the game in the video I posted, but I quite like how you can see most of the screen, which would allow more blocks that are visible to the user.

I did try modifying my height to the following, but it doesn't give the same functionality I'm after:

this.screen.y = this.player.pos.y - ig.system.height+104/2;

The easiest way I can understand or explain it is that even though the camera follows the screen the camera does not display any blocks outside of the level dimensions. The top, right, bottom and left are "snapped" to the sides of the level and only when the player rises within the level the camera follows respectively. You'll notice also that when the player walks closer to walls the camera stops moving and no outside (black areas within my setup) of the level is displayed.

Any help applying this functionality within my game would be greatly appreciated.

1 decade ago by alexandre

Go to this post and search for "Here's the camera class from Biolab Disaster, that uses a "trap" as described in Shaun Inman's excellent video/article.". It works well.

1 decade ago by fulvio

@alexandre: Perfect, thanks! Works a treat.
Page 1 of 1
« first « previous next › last »