Moving sprites: Difference between revisions
m (1 revision) |
mNo edit summary |
||
Line 1: | Line 1: | ||
Sprites can be moved individually if they're not [[Sticky bit|stuck together]], | Sprites can be moved individually if they're not [[Sticky bit|stuck together]]. If they are, the sprite block can be moving by setting the [[sprites#driving sprite|driving sprite]]'s position. | ||
Like every location in VRAM, these values can be updated mid-frame to create [[Scanline stretch|stretches]] or [[Scanline distortions|distortions]]. | |||
=== Horizontal position === | === Horizontal position === | ||
Their horizontal (X) position is set in VRAM, in [[Sprites|SCB4]]. It's relative to the left screen border. | Their horizontal (X) position is set in VRAM, in [[Sprites|SCB4]]. It's relative to the left screen border. | ||
Example: | Example: writing $0010 to $8402, puts sprite #2 at 16 pixels from the left. | ||
ASM routine to set the X position of a given sprite: | |||
<pre> | |||
;D0: Sprite # | |||
;D1: X position | |||
SetSprX: | |||
addi.w #SCB4,d0 | |||
move.w d0,VRAM_ADDR | |||
lsl.w #7,d1 | |||
move.w d1,VRAM_RW | |||
rts | |||
</pre> | |||
=== Vertical position === | === Vertical position === | ||
Their vertical (Y) position is set in VRAM, in [[Sprites|SCB3]]. It's reversed (496-Y), | Their vertical (Y) position is set in VRAM, in [[Sprites|SCB3]]. It's reversed (496-Y), and relative to the top screen border. | ||
A value of $1F0 sets the sprite to Y=0, $110 sets it at 224 (out of the visible area). | A value of $1F0 sets the sprite to Y=0, $110 sets it at 224 (out of the visible area). | ||
Example: | Example: writing 496-14 ($1E2) to $8205, puts sprite #5 at 14 pixels from the top. | ||
ASM routine to set the Y position of a given sprite: | |||
<pre> | |||
;D0: Sprite # | |||
;D1: Y position | |||
SetSprY: | |||
addi.w #SCB3,d0 | |||
move.w d0,VRAM_ADDR | |||
neg.w d1 | |||
addi.w #496,d1 | |||
lsl.w #7,d1 | |||
move.w VRAM_RW,d2 | |||
andi.w #$007F,d2 ; Preserves the sticky bit and size attributes | |||
or.w d1,d2 | |||
move.w d2,VRAM_RW | |||
rts | |||
</pre> | |||
[[Category: Code]] | [[Category: Code]] |
Revision as of 09:14, 10 February 2011
Sprites can be moved individually if they're not stuck together. If they are, the sprite block can be moving by setting the driving sprite's position.
Like every location in VRAM, these values can be updated mid-frame to create stretches or distortions.
Horizontal position
Their horizontal (X) position is set in VRAM, in SCB4. It's relative to the left screen border.
Example: writing $0010 to $8402, puts sprite #2 at 16 pixels from the left.
ASM routine to set the X position of a given sprite:
;D0: Sprite # ;D1: X position SetSprX: addi.w #SCB4,d0 move.w d0,VRAM_ADDR lsl.w #7,d1 move.w d1,VRAM_RW rts
Vertical position
Their vertical (Y) position is set in VRAM, in SCB3. It's reversed (496-Y), and relative to the top screen border. A value of $1F0 sets the sprite to Y=0, $110 sets it at 224 (out of the visible area).
Example: writing 496-14 ($1E2) to $8205, puts sprite #5 at 14 pixels from the top.
ASM routine to set the Y position of a given sprite:
;D0: Sprite # ;D1: Y position SetSprY: addi.w #SCB3,d0 move.w d0,VRAM_ADDR neg.w d1 addi.w #496,d1 lsl.w #7,d1 move.w VRAM_RW,d2 andi.w #$007F,d2 ; Preserves the sticky bit and size attributes or.w d1,d2 move.w d2,VRAM_RW rts