1 / 29

CS 1372

CS 1372. Sprites. Recall…. Atari computers and video games used the concept of players and missiles. Built in to the hardware Could instantly position at any column Row movement required moving data What technology!!! So why aren’t we all using Atari computers today?. The Commodore 64!.

iola
Download Presentation

CS 1372

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. CS 1372 Sprites

  2. Recall… • Atari computers and video games used the concept of players and missiles. • Built in to the hardware • Could instantly position at any column • Row movement required moving data • What technology!!! • So why aren’t we all using Atari computers today?

  3. The Commodore 64!

  4. With Sprites!!!

  5. With Sprites!!! Row, Column

  6. With Sprites!!! Row, Column

  7. Time passes…

  8. Sprites • Sprites is a generic term for images which can be placed into a larger scene. Originally sprites were images that could be inserted without disturbing the scene. In this sense, they are implemented with hardware. • Gameboy sprites fall under the original definition. • In the gameboy, sprites are often referred to as objects. The two terms will be mixed in the following presentation because everyone uses the term sprite and some of the GBA documentation uses the term object.

  9. GBA Sprite Overview • Standard component of games • Ball, paddle, selection cursor, etc • Composed of 8x8 tiles like tile backgrounds • Hardware supported movement and drawing that doesn't change background • GBA supports up to 128 sprites ranging from 8x8 to 64x64 pixels

  10. Visualization This is the smallest sprite If this is a pixel If this is the smallest sprite This is the largest sprite

  11. Essential Sprite Steps • Load sprite palette into palette memory • Load sprite graphics into OVRAM (Object Video Random Access Memory) • Set sprite attributes in OAM (Object Attribute Memory) • Enable sprite objects and select correct mapping mode in REG_DISPCNT • Note: Implementation will be slightly more complicated and involve a kind of “double buffering” for sprites.

  12. 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 Video Buffer Layoutfor Tiles & Sprites You put tile data (images) here (what each tile looks like) Character Block Character Block Character Block Character Block You put the tile map here (where the tiles go on the screen) Sprite Data Sprite Data OVRAM (Object Video Random Access Memory)

  13. Video Buffer Layoutfor Bitmaps & Sprites X7000000 OAMs X6014000 Sprites X600A000 VideoRAM DB X6000000 VideoRAM X5000200 SpritePalette Not to Scale X5000000 Palette

  14. Indices • The two character blocks dedicated to sprite images are divided into 32 byte long chunks. • When telling the game boy where to find a sprite's image you give it the index of the chunk where the image starts.

  15. Color Modes • 16 colors • 4bpp (bits per pixel) • 32 bytes per 8x8 sprite (smallest) • Each 8x8 sprite uses one charblock index • 256 colors • 8bpp • 64 bytes per 8x8 sprite • Each 8x8 sprite uses two charblock indices

  16. Sizing • Character blocks are 16 kb long • Smallest sprite (8x8, 16 colors) uses 32 bytes • Therefore a character block can hold 512 of them • Switch to 256 colors and reduce the number per character block to 256 • The largest sprite is 64x64 and at 256 colors takes up 4096 bytes so a character block can hold 4 of them!

  17. OAM • Object Attribute Memory • Location: 0x7,000,000 • Size: 1Kb Short Attribute 0 Attribute 1 8 bytes Attribute 2 Attribute 3

  18. Attribute 0 0F 0E 0D 0C 0B 0A 09 08 07 06 05 04 03 02 01 00 • Bits 0-7: Row location (Top of Sprite) • Bits 8-9: Object Mode: • 00: Regular, 01: Affine, 10: Hide • Bit 10: Enable alpha blending • Bit 13: 16 colors if cleared, 256 colors if set • Bits 14-15: Sprite shape: • 00: Square, 01: Wide, 10: Tall 15 14 13 12 11 10 09 08 07 06 05 04 03 02 01 00 Shape 256 α OM Row Location

  19. Attribute 1 0F 0E 0D 0C 0B 0A 09 08 07 06 05 04 03 02 01 00 • Bits 0-8: Column location (Left side of sprite) • Bits 12-13: Horizontal/Vertical Flip • 00: No Flip, 01: Horizontal Flip, 10: Vertical Flip • Bits 14-15: Sprite Size • 00: 8 pixels, 01: 16, 10: 32, 11: 64 15 14 13 12 11 10 09 08 07 06 05 04 03 02 01 00 Size Flip Column Location

  20. Attribute 2 0F 0E 0D 0C 0B 0A 09 08 07 06 05 04 03 02 01 00 15 14 13 12 11 10 09 08 07 06 05 04 03 02 01 00 Sub-Palette Priority Base index of sprite image • Bits 0-9: Base index of sprite image • Bits 10-11: Draw priority • Higher priorities drawn first • For same priority sprites, higher OAM entry number is drawn first • Bits 12-15: Sub-palette for 16 color sprites

  21. Attribute 3 • There is no Attribute 3 but you have to leave space for it nevertheless!

  22. Sprite Setup • Copy palette into palette memory • Copy image into OVRAM • Create a space in memory equivalent to OAM • Set location of all sprites off screen • Set the attributes of the sprites you will be using • Copy OAM copy into the actual OAM location • Set appropriate bits in REG_DISPCNT

  23. Sprite Use • Change/update location or tile index of all updated sprites in the OAM buffer • On vertical blank, DMA copy the buffer into the OAM location

  24. REG_DISPCNT 0F 0E 0D 0C 0B 0A 09 08 07 06 05 04 03 02 01 00 • 0-2: Mode. Sets video mode. • 0, 1, 2 are tiled modes; 3, 4, 5 are bitmap modes. • 4: Page select. Modes 4 and 5 can use page flipping for smoother animation. This bit selects the displayed page (and allowing the other one to be drawn on without artifacts). • 6: Object mapping mode. • 0 is 2D, 1 is 1D • 8, 9, 10, 11 BG0, BG1, BG2, BG3 • 12 Objects Enable (Set to 1 to enable sprites) 15 14 13 12 11 10 09 08 07 06 05 04 03 02 01 00 Enable Objects BG3 BG2 BG1 BG0 Object Map Mode Page Select Mode

  25. Example Suppose we want to have the following symbol on the screen: It actually consists of 2 * 2 tiles each 8 * 8 pixels in size. Unfortunately, we also need to rotate it. So we have to create a series of images:

  26. Multiple sprite images The images need to be created in such a manner that they occupy a rectangle 4096 bits wide. • At 4bpp, this is 256 pixels or 16 symbols: • At 8bpp, this is 128 pixels or 8 symbols:

  27. Processing sprite images Consider the 4bpp case. If we load this image into CBB[4], the images are indexed as tiles as shown below: tile: 0 2 4 6 8 … 30 32 - 62 64 - 94 So the tile locations where our 2 * 2 tiles start are tiles 0 .. 30 and 64 .. 94

  28. Questions?

More Related