Presentation is loading. Please wait.

Presentation is loading. Please wait.

2D Terrains.

Similar presentations


Presentation on theme: "2D Terrains."— Presentation transcript:

1 2D Terrains

2 A Starting Room Is it just a background image?

3 A Starting Room (it’s just a 16x10 2D array of “ints”!)
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 1 2 3 4 5 6 7 8 9

4 SpriteSheet 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 1 2 3 4 5 6 7 Note: each sprite is 16x16 pixels big, with a 1 pixel border (17x17)

5 SpriteSheet Problem: what’s the location of the 61st tile? 1 2 3 4 5 6
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 1 2 3 4 5 6 7

6 SpriteSheet 18 sprites wide by 8 sprites high 18 1 2 3 4 5 6 7 8 9 10
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 1 2 3 8 4 5 6 7

7 SpriteSheet srcX = tileType % 18; // 61 % 18 = 7
srcY = tileType / 18; // 61 / 18 = 3 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 1 2 3 4 5 6 7

8 SpriteSheet srcX = (tileType % 18) * TILE_SIZE;
srcY = (tileType / 18) * TILE_SIZE; 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 1 2 3 4 5 6 7

9 Drawing the Terrain srcRect tileType == 61 destRect

10 Drawing the Terrain srcRect tileType == 61 destRect

11 Drawing the Terrain srcRect tileType == 61 destRect

12 Drawing the Terrain srcRect tileType == 61 destRect

13 Drawing the Terrain srcRect tileType == 61 destRect

14 Drawing the Terrain srcRect tileType == 61 destRect

15 Drawing the Terrain srcRect tileType == 61 destRect

16 Drawing the Terrain srcRect tileType == 2 destRect

17 Drawing the Terrain srcRect tileType == 2 destRect

18 Drawing the Terrain srcRect tileType == 61 destRect

19 Drawing the Terrain srcRect tileType == 61 destRect

20 Our Hero

21 Collisions

22 Terrain Define a Room Each Tile
use 2D Array of Tiles stores the spritesheet Each Tile is passed a number to define its type calculates its srcX and srcY from the spritesheet has a “passable” attribute To draw background, traverse the 2D Array


Download ppt "2D Terrains."

Similar presentations


Ads by Google