[4.5.x] Animated Tiles with CHR-RAM Switching

Vasyan

New member
Тайл был бы довольно сложным... потому что тип столкновения выполняется каждый кадр... до тех пор, пока вы не перестанете с ним сталкиваться. Таким образом, он всегда будет выполнять снова и снова код для замены всех плиток блокировки. В этом случае я бы предложил изменить столкновение кнопки на 0, как только игрок столкнется с ней, чтобы выполнить код только один раз.

Пример изменения столкновения плиток на 0 можно найти в коллекционных плитках.
А замена всех плиток при столкновении выполняется здесь: https://www.nesmakers.com/index.php?threads/solved-4-5-9-is-there-a-way-to-bring-back-changealltiles .6727/#пост-38543
Thank you! I figured it out too, I'm learning fast, can I please have one more question, how to make a walk like in this game?https://destroyed4com4t.itch.io/graveyard-dude-homebrew-nes-game
View: https://www.youtube.com/watch?v=m2rcoazQ5fY?
 
Last edited:

Peter Schmitz

Active member
I implemented this in my maze module and it works like a dream. But where can I find the script where the background tiles are loaded? I would like to tell NesMaker to change the animated tiles based on the selected tileset. Or isn't that possible? How many of the AnimTilesXX.chr am I allowed to have? All I found is the variable "backgroundTilesToLoad" but I haven't found it yet in any other script than doLoadScreen16.asm
 

Peter Schmitz

Active member
oh sorry, wasn't clear enough - I meant that I implemented the animated tiles chr-ram switching - not the way the character in the above video is walking. ;)

But what you are looking for is something I am interest in as well ;)
 

JamesNES

Well-known member
I implemented this in my maze module and it works like a dream. But where can I find the script where the background tiles are loaded? I would like to tell NesMaker to change the animated tiles based on the selected tileset. Or isn't that possible? How many of the AnimTilesXX.chr am I allowed to have? All I found is the variable "backgroundTilesToLoad" but I haven't found it yet in any other script than doLoadScreen16.asm
That's what the screenbyte is for, it tells it where in the table to start loading tiles from. So if the byte is set to 4 it'll load in the three sets starting from the fourth one, not including zero.

You can fit a lot of those strips of tiles in a bank, if you download shiru's space checker you can load your rom and see how much space is left in each bank.
 

Peter Schmitz

Active member
That's what the screenbyte is for, it tells it where in the table to start loading tiles from. So if the byte is set to 4 it'll load in the three sets starting from the fourth one, not including zero.

You can fit a lot of those strips of tiles in a bank, if you download shiru's space checker you can load your rom and see how much space is left in each bank.
Okay - but let's say I have the AnimTiles01-03 I would like to use for a dungeon level that uses tileset 0.

Now I have a lava level using tileset 1 and I created AnimTiles04-07 specifically for the lava level. So if I set the screenbyte to 4 - it will only cycle through animTiles04 to 07?

Or would I have to add sth like

Code:
AnimTiles_Lo2:
.db #$00, #<AnimTiles04, #<AnimTiles05 ...etc

And use another screenbyte?
 

Peter Schmitz

Active member
Got it - tried both methods:

using another table:

Code:
AnimTiles2_Lo:
.db #$00, #<AnimTiles04, #<AnimTiles05, #<AnimTiles06

AnimTiles2_Hi:
.db #$00, #>AnimTiles04, #>AnimTiles05, #>AnimTiles06

in combination with a check for userScreenByte6 :
Code:
LDA userScreenByte7  ; UserScreenByte 7 activates Animation
    BNE +hasAnimatedTiles
            JMP +noAnimatedTiles
        +hasAnimatedTiles
              
        INC tempj
        LDA tempj
        CMP #$04
        BEQ +loadAnimatedTiles
            SwitchCHRBank tempj
            JMP Load_Sprite_CHR_Loop
        +loadAnimatedTiles
      
       LDA userScreenByte6  ;;;; userScreenByte6 selects a different set of animated tiles for a second tileset
       BNE +Tileset2
            JMP +Tileset1
      
        +Tileset2
            
        SwitchCHRBank #$01
        LoadChrData #$17, #$10, #$00, #$60, AnimTiles2_Lo, AnimTiles2_Hi, userScreenByte7
        ;arg0 - bank where graphics live
        ;arg1 - row 10 = row1 , 12 = row 2 , 14 = row 3
        ;arg2 - column (by 10s...must end in zero)
        ;arg3 - how many tiles to load.  If 00, will load whole sheet. #$20 = first 16 tile row
        ;arg4 - Label in bank 16 table, low.
        ;arg5 - Label in bank 16 table, hi.
        ;arg6 - Bank 16 table offset
        jsr doWaitFrame
      
        INC userScreenByte7
      
        SwitchCHRBank #$02
        LoadChrData #$17, #$10, #$00, #$60, AnimTiles2_Lo, AnimTiles2_Hi, userScreenByte7
        jsr doWaitFrame
        
        INC userScreenByte7
        
        SwitchCHRBank #$03
        LoadChrData #$17, #$10, #$00, #$60, AnimTiles2_Lo, AnimTiles2_Hi, userScreenByte7
        jsr doWaitFrame

       SwitchCHRBank #$00  ;;switch back to the first bank
       jmp    +noAnimatedTiles
        
        +Tileset1
        
        
        SwitchCHRBank #$01
        LoadChrData #$17, #$10, #$00, #$60, AnimTiles_Lo, AnimTiles_Hi, userScreenByte7
        ;arg0 - bank where graphics live
        ;arg1 - row 10 = row1 , 12 = row 2 , 14 = row 3
        ;arg2 - column (by 10s...must end in zero)
        ;arg3 - how many tiles to load.  If 00, will load whole sheet. #$20 = first 16 tile row
        ;arg4 - Label in bank 16 table, low.
        ;arg5 - Label in bank 16 table, hi.
        ;arg6 - Bank 16 table offset
        jsr doWaitFrame
      
        INC userScreenByte7
      
        SwitchCHRBank #$02
        LoadChrData #$17, #$10, #$00, #$60, AnimTiles_Lo, AnimTiles_Hi, userScreenByte7
        jsr doWaitFrame
        
        INC userScreenByte7
        
        SwitchCHRBank #$03
        LoadChrData #$17, #$10, #$00, #$60, AnimTiles_Lo, AnimTiles_Hi, userScreenByte7
        jsr doWaitFrame

       SwitchCHRBank #$00  ;;switch back to the first bank

    +noAnimatedTiles 
     SwitchCHRBank #$00

and the second version:

just adding the animated tiles to the original table
Code:
AnimTiles_Lo:
.db #$00, #<AnimTiles01, #<AnimTiles02, #<AnimTiles03, #<AnimTiles04, #<AnimTiles05, #<AnimTiles06

AnimTiles_Hi:
.db #$00, #>AnimTiles01, #>AnimTiles02, #>AnimTiles03, #>AnimTiles04, #>AnimTiles05, #>AnimTiles06

This might get very long if you have too many animated tiles.
 

vanderblade

Active member
Got it - tried both methods:

using another table:

Code:
AnimTiles2_Lo:
.db #$00, #<AnimTiles04, #<AnimTiles05, #<AnimTiles06

AnimTiles2_Hi:
.db #$00, #>AnimTiles04, #>AnimTiles05, #>AnimTiles06

in combination with a check for userScreenByte6 :
Code:
LDA userScreenByte7  ; UserScreenByte 7 activates Animation
    BNE +hasAnimatedTiles
            JMP +noAnimatedTiles
        +hasAnimatedTiles
             
        INC tempj
        LDA tempj
        CMP #$04
        BEQ +loadAnimatedTiles
            SwitchCHRBank tempj
            JMP Load_Sprite_CHR_Loop
        +loadAnimatedTiles
     
       LDA userScreenByte6  ;;;; userScreenByte6 selects a different set of animated tiles for a second tileset
       BNE +Tileset2
            JMP +Tileset1
     
        +Tileset2
           
        SwitchCHRBank #$01
        LoadChrData #$17, #$10, #$00, #$60, AnimTiles2_Lo, AnimTiles2_Hi, userScreenByte7
        ;arg0 - bank where graphics live
        ;arg1 - row 10 = row1 , 12 = row 2 , 14 = row 3
        ;arg2 - column (by 10s...must end in zero)
        ;arg3 - how many tiles to load.  If 00, will load whole sheet. #$20 = first 16 tile row
        ;arg4 - Label in bank 16 table, low.
        ;arg5 - Label in bank 16 table, hi.
        ;arg6 - Bank 16 table offset
        jsr doWaitFrame
     
        INC userScreenByte7
     
        SwitchCHRBank #$02
        LoadChrData #$17, #$10, #$00, #$60, AnimTiles2_Lo, AnimTiles2_Hi, userScreenByte7
        jsr doWaitFrame
       
        INC userScreenByte7
       
        SwitchCHRBank #$03
        LoadChrData #$17, #$10, #$00, #$60, AnimTiles2_Lo, AnimTiles2_Hi, userScreenByte7
        jsr doWaitFrame

       SwitchCHRBank #$00  ;;switch back to the first bank
       jmp    +noAnimatedTiles
       
        +Tileset1
       
       
        SwitchCHRBank #$01
        LoadChrData #$17, #$10, #$00, #$60, AnimTiles_Lo, AnimTiles_Hi, userScreenByte7
        ;arg0 - bank where graphics live
        ;arg1 - row 10 = row1 , 12 = row 2 , 14 = row 3
        ;arg2 - column (by 10s...must end in zero)
        ;arg3 - how many tiles to load.  If 00, will load whole sheet. #$20 = first 16 tile row
        ;arg4 - Label in bank 16 table, low.
        ;arg5 - Label in bank 16 table, hi.
        ;arg6 - Bank 16 table offset
        jsr doWaitFrame
     
        INC userScreenByte7
     
        SwitchCHRBank #$02
        LoadChrData #$17, #$10, #$00, #$60, AnimTiles_Lo, AnimTiles_Hi, userScreenByte7
        jsr doWaitFrame
       
        INC userScreenByte7
       
        SwitchCHRBank #$03
        LoadChrData #$17, #$10, #$00, #$60, AnimTiles_Lo, AnimTiles_Hi, userScreenByte7
        jsr doWaitFrame

       SwitchCHRBank #$00  ;;switch back to the first bank

    +noAnimatedTiles
     SwitchCHRBank #$00

and the second version:

just adding the animated tiles to the original table
Code:
AnimTiles_Lo:
.db #$00, #<AnimTiles01, #<AnimTiles02, #<AnimTiles03, #<AnimTiles04, #<AnimTiles05, #<AnimTiles06

AnimTiles_Hi:
.db #$00, #>AnimTiles01, #>AnimTiles02, #>AnimTiles03, #>AnimTiles04, #>AnimTiles05, #>AnimTiles06

This might get very long if you have too many animated tiles.
The second version, of just adding to the table, should work fine. Then just set the screens userScreenByte7 to start at 4. Works fine.
 

FuncleDude

New member
I'm reading through the tutorial and reviewing Baardi-B's video on animated tiles. The tutorial from my understanding is set up for three frames for each animated tile. What would I need to change or modify to add in the fourth frame?
 

Peter Schmitz

Active member
I'm reading through the tutorial and reviewing Baardi-B's video on animated tiles. The tutorial from my understanding is set up for three frames for each animated tile. What would I need to change or modify to add in the fourth frame?
I think you only have 3 banks to switch to - someone can correct me but if I take a look at the PPU viewer in Mesen - there is only room for three additional chr banks.
 

FuncleDude

New member
I'm stuck... So I got this window when I went to compile and test the game through NESMaker:

C:\Users\james\Desktop\nesmaker_4_5_9\NESmaker_4_5_9\NESmaker_4_5_x\GameEngineData>asm6 MainASM.nes game.nes demo.txt
pass 1..
Routines\BASE_4_5\System\BankData\Bank17.asm(3): Can't open file.
Routines\BASE_4_5\System\BankData\Bank17.asm(6): Can't open file.
Routines\BASE_4_5\System\BankData\Bank17.asm(9): Can't open file.
demo.txt written.

C:\Users\james\Desktop\nesmaker_4_5_9\NESmaker_4_5_9\NESmaker_4_5_x\GameEngineData>pause
Press any key to continue . . .



I tried deleting the extensions for the following lines, but still did not rectify the problem...

Bank17.asm

1
2 AnimTiles00_01:
3 .incbin ROOT\Graphics\AnimTiles00_01.chr
4
5 AnimTiles00_02:
6 .incbin ROOT\Graphics\AnimTiles00_02.chr
7
8 AnimTiles00_03:
9 .incbin ROOT\Graphics\AnimTiles00_03.chr


Also, I did name the files differently to try and compartmentalize the animated tiles, in case I decide to do more than one set. Thoughts?
 
Last edited:

SciNEStist

Well-known member
did you remember to export the tilesets as a chr (click Pixel Editor> Export CHR) or are you just saving the .bmp files there?
 

FuncleDude

New member
did you remember to export the tilesets as a chr (click Pixel Editor> Export CHR) or are you just saving the .bmp files there?
Funny thing is, they were exported as the correct format when I went to run it.

I'm betting @force73's question could lead to why my code isn't successfully compiling and running.
 
Top Bottom