JamesNES
Well-known member
So, I wanted to have my player get different sets of armour/weapons during the game, but found myself quickly out of space in the standard game objects graphics set. I thought about palette swapping but that seemed pretty boring. I came up with this way to just instead swap out strips of the game object CHR which is fast and takes up very little space.
What you'll need is two variables, one for determining which set of graphics to use for the player and one for which set to use for the weapons, I've called them:
playerArmour
playerWeapon
What my idea basically is, is that you have all your player sprites in two rows of 8 pixel sprites at the top of the file, then your weapons in the next two rows, and during screenload you can swap them out depending on what those two variables hold. For reference:
Player in the top row, weapon (in this picture a staff) on the second row.
Next, you need to add the graphics that will be swapped in.
Separate them out into strips like this:
and your new player/weapon sprites:
For these, you need to convert them to .chr and put them in NESMaker\GameData\Graphics\Sprites. This is easy, NESMaker has a built in CHR converter.
Save them all in that directory as .chr files. Give them names like "CHR_PlayerSprites_00" and "CHR_WeaponSprites_00".
We'll include the new graphics in bank 15 as that is where the normal game objects graphics lives, and it's basically entirely empty.
So open up Bank15.asm and add this, making sure your filenames are correct:
Each of these files takes up about 3% of the bank, so it's pretty cheap considering how nifty it is.
Next we make references to these in Bank16.asm. Around line 410 there's the address for the standard game objects CHR so that's a good spot to put these under:
Finally, we have to get them to actually load. With this method it will only happen when the screen is reloaded. This is done in DoLoadScreen.asm.
Around line 380 you'll see:
Immediately after this, we want to add this, to replace the first 4 rows of game object data that just loaded:
So what this does, is change which player sprites and weapon sprites are loaded based on those two variables. At the moment the only two options are 0 or 1 so anything other value will give garbage results.
Tada:
(You can also change the sprite palette to match the new sprites).
What you'll need is two variables, one for determining which set of graphics to use for the player and one for which set to use for the weapons, I've called them:
playerArmour
playerWeapon
What my idea basically is, is that you have all your player sprites in two rows of 8 pixel sprites at the top of the file, then your weapons in the next two rows, and during screenload you can swap them out depending on what those two variables hold. For reference:
Player in the top row, weapon (in this picture a staff) on the second row.
Next, you need to add the graphics that will be swapped in.
Separate them out into strips like this:
and your new player/weapon sprites:
For these, you need to convert them to .chr and put them in NESMaker\GameData\Graphics\Sprites. This is easy, NESMaker has a built in CHR converter.
Save them all in that directory as .chr files. Give them names like "CHR_PlayerSprites_00" and "CHR_WeaponSprites_00".
We'll include the new graphics in bank 15 as that is where the normal game objects graphics lives, and it's basically entirely empty.
So open up Bank15.asm and add this, making sure your filenames are correct:
Code:
PlayerSpriteTiles00:
.incbin "Graphics\Sprites\CHR_PlayerSprites_00.chr"
PlayerSpriteTiles01:
.incbin "Graphics\Sprites\CHR_PlayerSprites_01.chr"
WeaponObjectTiles00:
.incbin "Graphics\Sprites\CHR_WeaponSprites_00.chr"
WeaponObjectTiles01:
.incbin "Graphics\Sprites\CHR_WeaponSprites_01.chr"
Each of these files takes up about 3% of the bank, so it's pretty cheap considering how nifty it is.
Next we make references to these in Bank16.asm. Around line 410 there's the address for the standard game objects CHR so that's a good spot to put these under:
Code:
PlayerSpriteCHRAddLo:
.db <PlayerSpriteTiles00, <PlayerSpriteTiles01
PlayerSpriteCHRAddHi:
.db >PlayerSpriteTiles00, >PlayerSpriteTiles01
WeaponObjectCHRAddLo:
.db <WeaponObjectTiles00, <WeaponObjectTiles01
WeaponObjectCHRAddHi:
.db >WeaponObjectTiles00, >WeaponObjectTiles01
Finally, we have to get them to actually load. With this method it will only happen when the screen is reloaded. This is done in DoLoadScreen.asm.
Around line 380 you'll see:
Code:
doneLoadingChrs:
LoadChrData #$15, #$00, #$00, #$80, GameObjectCHRAddLo, GameObjectCHRAddHi, #$00
;arg0 - bank where graphics live
;arg1 - row
;arg2 - column (by 10s...must end in zero)
;arg3 - how many tiles to load. If 00, will load whole sheet.
;arg4 - Label in bank 16 table, low.
;arg5 - Label in bank 16 table, hi.
;arg6 - Bank 16 table offset
Immediately after this, we want to add this, to replace the first 4 rows of game object data that just loaded:
Code:
LoadChrData #$15, #$00, #$00, #$20, PlayerSpriteCHRAddLo, PlayerSpriteCHRAddHi, playerArmour
LoadChrData #$15, #$02, #$00, #$20, WeaponObjectCHRAddLo, WeaponObjectCHRAddHi, playerWeapon
So what this does, is change which player sprites and weapon sprites are loaded based on those two variables. At the moment the only two options are 0 or 1 so anything other value will give garbage results.
Tada:
(You can also change the sprite palette to match the new sprites).