Next Up Sprite Animation Table

Por Chilly Willy

Resident (64)

Imagen del Chilly Willy

26-06-2021, 15:50

As always I try to find info before I ask, however, Google is not as friendly as you would think.

Can someone please link me to a page, a demo with source or just plain share some code how to set up a proper animation table.

My understanding is that you set up the sprite in a normal fashion then use a register such as a to send different pattern tables to byte 3 in the sprite table.

However, I set up all my animation tiles and a table but it goes through the animation too fast to be useful.

Also I don't want to just have the one thing animate and THEN something else.
It want to have it take a step, something else do something on screen then I take another step ect.....

Should there be just a section calling animation from the main loop?

Again, just point me to an example of setup and execution and I should be able to figure out the rest.

So far I have a little guy on the screen and he's not doing much of anything.

TIA

Login sesión o register para postear comentarios

Por theNestruo

Champion (311)

Imagen del theNestruo

26-06-2021, 16:39

My player has a state byte that defines what is he doing: walking, on air, on ladder, dying, etc. The bits 0 and 1 are non-significant for the actual state, but indicate: animation flag, and "looking left" flag.

Then, I have a table that maps each state to the pattern to use:

; Maps player states to sprite patterns
PLAYER_SPRATR_TABLE:
	;	0	ANIM	LEFT	LEFT|ANIM
	db	$00,	$08,	$10,	$18	; PLAYER_STATE_FLOOR
	db	$08,	$18,	$08,	$18	; PLAYER_STATE_STAIRS
	db	$08,	$08,	$18,	$18	; PLAYER_STATE_AIR
	db	$20,	$28,	$20,	$28	; PLAYER_STATE_DYING
	;	...				; PLAYER_STATE_...

Then I have these two subroutines that handle the animation flag:

; Number of player sprites (i.e.: number of colors)
	CFG_PLAYER_SPRITES:		equ 2

; Player animation delay (frames)
	CFG_PLAYER_ANIMATION_DELAY:	equ 6

; -----------------------------------------------------------------------------
; Updates animation counter and toggles the animation flag
UPDATE_PLAYER_ANIMATION:
; Updates animation counter
	ld	a, [player.animation_delay]
	inc	a
	cp	CFG_PLAYER_ANIMATION_DELAY
	jp	nz, .DONT_ANIMATE
; Toggles the animation flag
	ld	hl, player.state
	ld	a, FLAG_STATE_ANIM
	xor	[hl]
	ld	[hl], a
; Resets animation counter
	xor	a
.DONT_ANIMATE:
	ld	[player.animation_delay], a
	ret
; -----------------------------------------------------------------------------

; -----------------------------------------------------------------------------
; Moves the player sprites in the SPRATR buffer,
; and sets their patterns according PLAYER_SPRATR_TABLE[player.state]
PUT_PLAYER_SPRITE:
; First pattern according player state
	ld	a, [player.state]
	ld	hl, PLAYER_SPRATR_TABLE
	call	GET_HL_A_BYTE
	ld	[player_spratr.pattern], a
; Moves the player sprites
	ld	hl, player_spratr
	ld	de, [player.xy]
	ld	b, CFG_PLAYER_SPRITES
	jp	MOVE_SPRITES
; -----------------------------------------------------------------------------

That's the most relevant parts of the code. I have a working example in case you want to check first this is what you need.

Por Chilly Willy

Resident (64)

Imagen del Chilly Willy

26-06-2021, 18:07

Sweet, you do it through a flag.

I was thinking of doing that but someone showed me to use 255 at the end but this gives me issues with alignment because of my graphics tables.

I set my sprites up to be 8x8 in order to preserve VRAM space for sprite patterns.
This gives me 256 as apposed to 64 patterns.

So I doubled up and my main guy is 16x8 while most enemies are 8x8.

My problem comes in for using two animation tables but checking for 255 once.