[4.5.9] The ChangeAllTiles macro

dale_coop

Moderator
Staff member
I noticed some members were looking for this macro, so I will share it here.

This ChangeAllTiles macro replaces all tiles on the screen matching a specific collision type with another tile (both collision and graphics).

changeAllTiles.gif


How to Implement It in your Project:

0/ Download the changeallTilesMacro.zip file and extract it somewhere. The two required files are inside the zip.

1/ Place the ChangeAllTiles.asm macro file in the "GameEngineData\Routines\BASE_4_5\System\Macros\" folder.

2/ Place the doChangeAllTiles.asm script file in the "GameEngineData\Routines\BASE_4_5\Game\Subroutines\" folder.

3/ In the "Project Settings > Script Settings", edit your "LoadAllSubroutines.asm" script, and add the following line:
Code:
.include ROOT\Game\Subroutines\doChangeAllTiles.asm
Note: You can place this line among the other .include lines (around line 35 or 36 is a good spot).


Usage:
ChangeAllTiles <collisionToReplace>, <newGfxTile>, <newCollisionType>

collisionToReplace:
The collision tile you want to replace.
newGfxTile: The graphic tile you want to use (this is the tile ID from the current background tileset). Note: If you don't want to change the graphics, use #$FF for this parameter.
newCollisionType: The collision type you want to replace the old one with.


Examples:
If you want to replace all the tiles with collision type #06 (locked doors) with warp tiles (#03) and display the open door graphic (#$10 from your background tileset), you would use:
Code:
ChangeAllTiles #07, #$10, #03

Or if you want to remove tiles with collision type #12 and replace them with empty, walkable tiles (#$00), you would use
Code:
ChangeAllTiles #12, #$00, #00

Or if you want to remove invisible walls (tiles #12) but keep the same graphics (i.e., just change the collision type), you would use:
Code:
ChangeAllTiles #12, #$FF, #00



Note: These examples are based on my project, and the collision types and graphics tiles in your project may (and likely will) be different.
Let me know if you encounter any issues or have further questions!


UPDATE: fixed a bug in the doChangeAllTiles.asm script. The graphics of the replacement tile were incorrectly drawn (it was drawn using only an 8x8 graphic that was repeated 4 times, instead of using the 16x16 tile).
 

Attachments

  • changeAllTilesMacro.zip
    1.5 KB · Views: 9
Last edited:

mileco

Active member
Thanks Dale, that's what I was looking for. Does it work on all modules? Happy new year!
 

dale_coop

Moderator
Staff member
I am wondering what triggers The change in this code? I cant seem to get mine to change.
What do you mean?
I put my code in a tile script. In my project, it's a "destructible" tile type.
(It’s kind of like the destructible tile from the Adventure Module tutorial video, the "advanced" one from the official website).
 

jmotten

New member
What do you mean?
I put my code in a tile script. In my project, it's a "destructible" tile type.
(It’s kind of like the destructible tile from the Adventure Module tutorial video, the "advanced" one from the official website).
Oh , that makes sense. I understand how you are using it now. Thank you. I didn't realize You put it in the destruction tile.
 

TheRetroBro

Active member
I noticed some members were looking for this macro, so I will share it here.

This ChangeAllTiles macro replaces all tiles on the screen matching a specific collision type with another tile (both collision and graphics).

View attachment 8539


How to Implement It in your Project:

0/ Download the changeallTilesMacro.zip file and extract it somewhere. The two required files are inside the zip.

1/ Place the ChangeAllTiles.asm macro file in the "GameEngineData\Routines\BASE_4_5\System\Macros\" folder.

2/ Place the doChangeAllTiles.asm script file in the "GameEngineData\Routines\BASE_4_5\Game\Subroutines\" folder.

3/ In the "Project Settings > Script Settings", edit your "LoadAllSubroutines.asm" script, and add the following line:
Code:
.include ROOT\Game\Subroutines\doChangeAllTiles.asm
Note: You can place this line among the other .include lines (around line 35 or 36 is a good spot).


Usage:
ChangeAllTiles <collisionToReplace>, <newGfxTile>, <newCollisionType>

collisionToReplace:
The collision tile you want to replace.
newGfxTile: The graphic tile you want to use (this is the tile ID from the current background tileset). Note: If you don't want to change the graphics, use #$FF for this parameter.
newCollisionType: The collision type you want to replace the old one with.


Examples:
If you want to replace all the tiles with collision type #06 (locked doors) with warp tiles (#03) and display the open door graphic (#$10 from your background tileset), you would use:
Code:
ChangeAllTiles #07, #$10, #03

Or if you want to remove tiles with collision type #12 and replace them with empty, walkable tiles (#$00), you would use
Code:
ChangeAllTiles #12, #$00, #00

Or if you want to remove invisible walls (tiles #12) but keep the same graphics (i.e., just change the collision type), you would use:
Code:
ChangeAllTiles #12, #$FF, #00



Note: These examples are based on my project, and the collision types and graphics tiles in your project may (and likely will) be different.
Let me know if you encounter any issues or have further questions!
idk how im just seeing this but this is super useful
 

TheRetroBro

Active member
I noticed some members were looking for this macro, so I will share it here.

This ChangeAllTiles macro replaces all tiles on the screen matching a specific collision type with another tile (both collision and graphics).

View attachment 8539


How to Implement It in your Project:

0/ Download the changeallTilesMacro.zip file and extract it somewhere. The two required files are inside the zip.

1/ Place the ChangeAllTiles.asm macro file in the "GameEngineData\Routines\BASE_4_5\System\Macros\" folder.

2/ Place the doChangeAllTiles.asm script file in the "GameEngineData\Routines\BASE_4_5\Game\Subroutines\" folder.

3/ In the "Project Settings > Script Settings", edit your "LoadAllSubroutines.asm" script, and add the following line:
Code:
.include ROOT\Game\Subroutines\doChangeAllTiles.asm
Note: You can place this line among the other .include lines (around line 35 or 36 is a good spot).


Usage:
ChangeAllTiles <collisionToReplace>, <newGfxTile>, <newCollisionType>

collisionToReplace:
The collision tile you want to replace.
newGfxTile: The graphic tile you want to use (this is the tile ID from the current background tileset). Note: If you don't want to change the graphics, use #$FF for this parameter.
newCollisionType: The collision type you want to replace the old one with.


Examples:
If you want to replace all the tiles with collision type #06 (locked doors) with warp tiles (#03) and display the open door graphic (#$10 from your background tileset), you would use:
Code:
ChangeAllTiles #07, #$10, #03

Or if you want to remove tiles with collision type #12 and replace them with empty, walkable tiles (#$00), you would use
Code:
ChangeAllTiles #12, #$00, #00

Or if you want to remove invisible walls (tiles #12) but keep the same graphics (i.e., just change the collision type), you would use:
Code:
ChangeAllTiles #12, #$FF, #00



Note: These examples are based on my project, and the collision types and graphics tiles in your project may (and likely will) be different.
Let me know if you encounter any issues or have further questions!
odd, when i try to add the include i get an error that says it cannot open file yet its in the correct spot...im in the maze module
 
Last edited:

mileco

Active member
What do you mean?
I put my code in a tile script. In my project, it's a "destructible" tile type.
(It’s kind of like the destructible tile from the Adventure Module tutorial video, the "advanced" one from the official website).
If it is a breakable tile it doesn't work when the player steps on it? To do so I'd have to tweak sth?
 

dale_coop

Moderator
Staff member
If it is a breakable tile it doesn't work when the player steps on it? To do so I'd have to tweak sth?
Depends on your tile script. A tile script can be written for a specific object or for any object (by default). As soon as the object touches the tile, it can execute.
However, if the object also touches a solid tile, only the solid tile collision will be triggered. This is a limitation of the tile collision engine in NESmaker.
 

Zikifer

Member
However, if the object also touches a solid tile, only the solid tile collision will be triggered. This is a limitation of the tile collision engine in NESmaker.
Thank you for this!! I was tearing my hair out trying to figure out why breakable tile was only detecting if it was the upper-left corner of my game object. After some updates to the tile collision detection and a new tile type (15) I was able to get the breakable tile working even when surrounded by "solid" tiles. I might revisit at some point to see if I can do it without the new tile type, but for now it is working.
 

dale_coop

Moderator
Staff member
UPDATE: Following the bug reported by @Lord_Klump_Of_Kongo_Bongo, the doChangeAllTiles.asm script has been fixed. The graphics of the replacement tile were incorrectly drawn (they used an 8x8 graphic repeated 4 times instead of using the 16x16 tile).
The Zip file on the first post has been updated.
 
@dale_coop Hi Dale, I'm not using a scrolling module this time and I did not try your code yet but I have 3 questions:

1. Does your code change every collision type tiles on the screen. Just imagine I have 2 doors to blast through, I suppose the collision type of those 2 doors must be different?

2. The tiles your replacing for the new ones... If I have two tile sets (Using Doublemain layout), can I replace a tile from the first to another one from the second?

3. This one is so insane, I'm frightened to ask: I'm pretty sure you can't select the palette you want (one of your current 4) you want for the replacement tiles. Correct?

Thank you Dale, your the best.
 

dale_coop

Moderator
Staff member
@dale_coop Hi Dale, I'm not using a scrolling module this time and I did not try your code yet but I have 3 questions:

1. Does your code change every collision type tiles on the screen. Just imagine I have 2 doors to blast through, I suppose the collision type of those 2 doors must be different?

2. The tiles your replacing for the new ones... If I have two tile sets (Using Doublemain layout), can I replace a tile from the first to another one from the second?

3. This one is so insane, I'm frightened to ask: I'm pretty sure you can't select the palette you want (one of your current 4) you want for the replacement tiles. Correct?

Thank you Dale, your the best.

1 - Yes, that's correct. The macro checks the collision type and will change all tiles that match that collision type. So if you have two different doors, you will need to use two different tile types. (Or you could avoid using that macro and try a different approach, maybe with the classic ChangeTileAtCollision.)


2 - Yes, you can use any tile ID. The easiest way to find a tile's ID is to temporarily place it on the screen and hover your mouse over it. The ID will be displayed (e.g., $80 in my screenshot)

2025-03-10 15_42_35-NES MAKER 4.5.9 - Version_ 0x176 - AdventureTutorial.MST.png

3- Unfortunetly, no, you can't change the palette used. That macro replaces only the graphics, sorry.
 
Top Bottom