1 / 22

2D Terrains

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

damien
Download Presentation

2D Terrains

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

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”!) 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 0 1 2 3 4 5 6 7 8 9

  4. SpriteSheet 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 0 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? 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 0 1 2 3 4 5 6 7

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

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

  8. SpriteSheet srcX = (tileType % 18) * TILE_SIZE; srcY = (tileType / 18) * TILE_SIZE; 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 0 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 • 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

More Related