You are not logged in. | Register | Resend Activation

Objects

Objects (OBJs) are used to represent small, independently movable objects, such as game characters, coins, etc.

OBJs differ from BGMaps in many ways:

  • Each OBJ only holds one Character.
  • Chars can overlap each other.
  • Chars can be positioned arbitrarily.
  • Chars can be placed with pixel granularity.

These attributes are great if one wants to place a few Chars randomly about the screen, e.g. bubbles, stars and other particle effects.

Object Attributes

F E D C B A 9 8 7 6 5 4 3 2 1 0
JX: -7 (0xFFF9) to 383 (0x017F)
JLON JRON JP: -256 (0x3F01) to 255 (0x00FF)
JY: -7 (0xFFF9) to 223 (0x00DF)
JPLT HFLP VFLP 0 JCA: 0 (0×000) to 2047 (0x7FF)


JX

  • X coordinate of OBJ, relative to screen. Can be negative to allow an OBJ to 'sneak' onto the screen smoothly from the left, and large enough to sneak back off to the right.

JLON

  • If set, the OBJ is visible on the left screen.

JRON

  • If set, the OBJ is visible on the right screen.

JP

  • The OBJ's parallax. The OBJ's true X coordinate (TX) is computed by:
  • TXL = JX - JP and TXR = JX + JP.
  • In other words, the more positive JP is, the farther away the OBJ appears.

JY

  • Y coordinate of OBJ, relative to screen. Can be negative to allow an OBJ to 'sneak' onto the screen smoothly from the top, and large enough to sneak back off to the bottom.

JPLT (0-3)

  • Palette # for this OBJ, using VIP register JPLT#

HFLP

  • If set, the OBJ is drawn flipped horizontally

VFLP

  • If set, the OBJ is drawn flipped vertically

JCA

  • Char # to display from CHR RAM (Character RAM)

Note: JY wraps back to zero in the display coordinate system every +/- 256, JX every 1024. For example, JY value -33 is wrapped to Y-position 223 on the display.

Object Storage

OBJs are stored in OAM (Object Attribute Memory) which occupies the 8,192 (0×2000) bytes from 0×0003 E000 to 0×0003 FFFF. Since each OBJ is 8 bytes in size, there is a total of 1,024 (0×400) possible OBJs.

There are four offset registers in the VIP region (SPT0-SPT3) that break up OAM into four collections. A World may contain only one of these four OBJ collections, but every OBJ can be used without using all four collections.

When the graphics engine needs to draw a collection of OBJs, the display renderer starts at an SPT pointer (SPT3 is first) and counts backwards, drawing each OBJ where it goes. When it reaches the next lower SPT pointer, (actually, right before it…) it stops drawing until another OBJ World is encountered.

The VIP at Work

Here's an example which illustrates the VIP's behavior concerning OBJs:

Let us assume the following:

Worlds 31 and 30 are set to display OBJs.
SPT3 holds 512.
SPT2 holds 237.
SPT1 and SPT0 both contain a 0.

The VIP starts to render World 31 into a frame buffer.

It looks at SPT3 and sees 512, so it skips OBJs 1,023 through 513 and draws OBJ 512. OBJ 512 is located at OBJ Base Address (0x0003E000) + SPT3 (0×00000200) = 0x0003E200

Then it checks SPT2 and sees 237.

So it draws OBJ 511, 510, 509, etc. until it gets to 238 (SPT2 + 1) and it is done with this World.

It checks World 30 and sees that it, too, is assigned to an OBJ collection, so it checks SPT1 (which is 0) and draws every OBJ from 237 (0x0003E000 + 0x000000ED (237) = 0x0003E0ED) to SPT1 + 1 (0x0003E000 + 0×0000001 (1) = 0x0003E001) before going on to the next World.

If you want to draw OBJ 0, you have two options: 1) set SPT1 to 1,023, in which case the VIP will automatically stop at 0x0003E000, or 2) set one of the Worlds from 29 to 0 to display OBJs (or, in this case, an OBJ).

The VIP draws OBJs in reverse order for the same reason it draws World 31 first: so that lower numbered OBJs have priority over (i.e. they are drawn on top of) higher numbered ones.

 


Last modified: 05.09.2008