Heroes & Shadows Posted October 22, 2018 Share Posted October 22, 2018 I have the following setup: ; player graphic PlayerGraphic PlayerDirectionUpGraphic .byte #%00111100 .byte #%01111110 .byte #%11000001 .byte #%10111111 .byte #%11111111 .byte #%11101011 .byte #%01111110 .byte #%00111100 PlayerDirectionDownGraphic .byte #%00111100 .byte #%01111110 .byte #%11000001 .byte #%10111111 .byte #%11111111 .byte #%11101011 .byte #%01111110 .byte #%00111100 PlayerDirectionLeftGraphic .byte #%00111100 .byte #%01111110 .byte #%11000001 .byte #%10111111 .byte #%11111111 And a ram variable: PlayerDirection .ds 1 With equates as follows: DIRECTION_UP equ 1 DIRECTION_DOWN equ 2 DIRECTION_LEFT equ 3 DIRECTION_RIGHT equ 4 What is the best way to handle changing the sprite being displayed based on the "direction" the player is facing? Sent from my LG-M150 using Tapatalk Quote Link to comment Share on other sites More sharing options...
nsn Posted October 22, 2018 Share Posted October 22, 2018 First redefine your directions to start at 0 - saves a lot of unnecessary code and even more unnecessary religious discussions with LUA programmers Then create a table of pointers to your graphics: TBL_GFX_PTR_LO: .byte <(PlayerDirectionUpGraphic) .byte <(PlayerDirectionDownGraphic) .byte <(PlayerDirectionLeftGraphic) .byte <(PlayerDirectionRightGraphic) we need two bytes for a sprite pointer: PlayerGfxPtr ds 2 each frame we initialise said pointer (first HI- then LO-byte): lda #>(PlayerDirectionUpGraphic) sta PlayerGfxPtr+1 ldy PlayerDirection lda TBL_GFX_PTR_LO,y sta PlayerGfxPtr now, in our kernel, we can load from that pointer: lda (PlayerGfxPtr),y sta GRP0 (I'm writing this code from memory, be wary) Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.