Create function to update only secondary sprites to optimize die roll animation (#11)

This commit is contained in:
xCrystal 2023-09-30 13:30:30 +02:00
parent 49a3f6b8c8
commit 8967898bc9
3 changed files with 34 additions and 4 deletions

View File

@ -202,7 +202,7 @@ DIE_MAX_NUMBER EQU 6
add DIE_MAX_NUMBER
add $1
ld [wDieRoll], a
farcall _UpdateSprites
farcall _UpdateSecondarySprites
call GetJoypad
ldh a, [hJoyPressed]
bit B_BUTTON_F, a
@ -221,6 +221,7 @@ DIE_MAX_NUMBER EQU 6
ret
.confirm_roll
call UpdateSprites
ld a, TRUE
ld [wScriptVar], a
ret
@ -270,8 +271,8 @@ BoardMenu_BreakDieAnimation:
ld a, $8 * SPRITEOAMSTRUCT_LENGTH ; with SPRITE_ANIM_OBJ_BOARD_MENU_APPEAR_DIE_NUMBER
jr nz, .go
ld a, $4 * SPRITEOAMSTRUCT_LENGTH ; w/o SPRITE_ANIM_OBJ_BOARD_MENU_APPEAR_DIE_NUMBER
ldh [hUsedSpriteIndex], a
.go
ldh [hUsedSpriteIndex], a
farcall _UpdateSpritesAfterOffset
ld de, SFX_STRENGTH

View File

@ -3078,6 +3078,35 @@ InitSprites:
dw wObject11Struct
dw wObject12Struct
_UpdateSecondarySprites:
; this is a shorter _UpdateSprites for when only secondary sprites have changed since the last sprites update,
; but NOT expanded, which would require to displace primary (NPC) sprites in OAM.
; if it is detected that the size of secondary sprites has increased in the end,
; fall back to calling _UpdateSprites to avoid corruption.
ld a, [wVramState]
bit 0, a
ret z
ld a, [hUsedSpriteIndex]
push af
xor a
ldh [hUsedSpriteIndex], a
.go
ldh a, [hOAMUpdate]
push af
ld a, 1
ldh [hOAMUpdate], a
call InitSecondarySprites
pop af
ldh [hOAMUpdate], a
ldh a, [hUsedSpriteIndex]
ld c, a
pop af
cp c
ret nc
jp _UpdateSprites
InitSecondarySprites:
ld a, [wDisplaySecondarySprites]
bit SECONDARYSPRITES_BOARD_MENU_F, a

View File

@ -109,5 +109,5 @@ Level1_Map1_MapEvents:
object_event 4, 2, SPRITE_CONSOLE, SPRITEMOVEDATA_STILL, 0, 0, -1, -1, 0, OBJECTTYPE_SCRIPT, 0, Level1_Map1_GameConsoleScript, -1
object_event 4, 4, SPRITE_DOLL_1, SPRITEMOVEDATA_STILL, 0, 0, -1, -1, 0, OBJECTTYPE_SCRIPT, 0, Level1_Map1_Doll1Script, -1
object_event 5, 4, SPRITE_DOLL_2, SPRITEMOVEDATA_STILL, 0, 0, -1, -1, 0, OBJECTTYPE_SCRIPT, 0, Level1_Map1_Doll2Script, -1
; object_event 0, 1, SPRITE_BIG_DOLL, SPRITEMOVEDATA_BIGDOLL, 0, 0, -1, -1, 0, OBJECTTYPE_SCRIPT, 0, Level1_Map1_BigDollScript, -1
; object_event 6, 6, SPRITE_YOUNGSTER, SPRITEMOVEDATA_STANDING_DOWN, 0, 0, -1, -1, PAL_NPC_BLUE, OBJECTTYPE_TRAINER, 1, Level1_Map1_TrainerYoungsterMikey, -1
object_event 0, 1, SPRITE_BIG_DOLL, SPRITEMOVEDATA_BIGDOLL, 0, 0, -1, -1, 0, OBJECTTYPE_SCRIPT, 0, Level1_Map1_BigDollScript, -1
object_event 6, 6, SPRITE_YOUNGSTER, SPRITEMOVEDATA_STANDING_DOWN, 0, 0, -1, -1, PAL_NPC_BLUE, OBJECTTYPE_TRAINER, 1, Level1_Map1_TrainerYoungsterMikey, -1