Presentation is loading. Please wait.

Presentation is loading. Please wait.

2D Platform Games: Tiles & Scrolling. Platform Games Character jumps from platform to platform World terrain is made of tiles Add player, bad guys, power.

Similar presentations


Presentation on theme: "2D Platform Games: Tiles & Scrolling. Platform Games Character jumps from platform to platform World terrain is made of tiles Add player, bad guys, power."— Presentation transcript:

1 2D Platform Games: Tiles & Scrolling

2 Platform Games Character jumps from platform to platform World terrain is made of tiles Add player, bad guys, power ups

3 Creating the game map Make the world (game map) for one level. Dont use one huge image! Use grid – each slot points to a tile image or null

4 Issues with Drawing the World Tile world is bigger than screen Need to move the screen (instead of the player, often) Often want background image that moves slower than the rest of the world

5 Calculate New Position Keep the player in the middle of the screen… Percentage of left and right of screen that makes the scroll happen if (Player.Position.X < marginLeft) cameraMovement = Player.Position.X - marginLeft

6 Offset Dont scroll off ends: float maxCameraPosition = Tile.Width * Width – viewport.Width; That is, (the width of one tile * # tiles in a row) – (width of screen) Screen

7 Drawing the Tiles Efficiency: only draw visible tiles: int left = (int)Math.Floor(cameraPosition/Tile.Width); int right = left + /Tile.Width; right = Math.Min(right, Width-1) // where Width is the width of the 2D table.

8 Drawing the Sprites Not many – just draw all (brute force) Many – only draw visible sprites Keep sprites in a list ordered by position Partition map into screen – sized portions, keep sprites from each portion

9 Drawing Backgrounds Choices: Keep background static Scroll background image at same rate as tiles Scroll background image slower to mimic distance Last method is known as Parallax Scrolling

10 Scrolling Often will have segments of backgrounds. As scrolling happens, rotate backgrounds. Usually no more than 2 backgrounds segments drawn at any given time.


Download ppt "2D Platform Games: Tiles & Scrolling. Platform Games Character jumps from platform to platform World terrain is made of tiles Add player, bad guys, power."

Similar presentations


Ads by Google