I usually use Shiru's NESlib library to do my NES projects.
But I have a question as to how to mirror sprites or tiles with the "oam meta sprite" function.
This function is composed as follows:
oam_meta_spr(unsigned char x, unsigned char y, unsigned char sprid, const unsigned char *data);
Where "const unsigned char * data" must have our sprite attached. However, I have not found a way to mirror this way.
Someone knows?
Mirror sprites with Shiru's Library NESlib
Moderator: Moderators
Re: Mirror sprites with Shiru's Library NESlib
The OAM_FLIP flags go in the attribute field of the metasprite.
Re: Mirror sprites with Shiru's Library NESlib
Yes, I know that with OAM_FLIP I mirror the sprite array.calima wrote:The OAM_FLIP flags go in the attribute field of the metasprite.
But I need to do this in the function, to save myself having to write the same array twice with the OAM_FLIP variation.
Is there any way?
Re: Mirror sprites with Shiru's Library NESlib
You would have to copy the metasprite array to the RAM and edit the X coordinates manually, and toggle the H-Flip bit in attributes.
The fastest would be a second array of new X coordinates for every sprite, and simply copy the alternate X coordinate into the RAM array. But, you could also choose a central X coordinate and subtract each relative X coordinate from it.
I wrote some code for the Spacy Shooty example code that does the first thing, but it's much slower code than Shiru's code. Maybe I'll rewrite it some time.
(I also used the code in Flappy Jack).
The fastest would be a second array of new X coordinates for every sprite, and simply copy the alternate X coordinate into the RAM array. But, you could also choose a central X coordinate and subtract each relative X coordinate from it.
I wrote some code for the Spacy Shooty example code that does the first thing, but it's much slower code than Shiru's code. Maybe I'll rewrite it some time.
(I also used the code in Flappy Jack).
nesdoug.com -- blog/tutorial on programming for the NES
Re: Mirror sprites with Shiru's Library NESlib
You have to store two metasprite arrays, one for the original metasprite, and other with the flipped sprites, rearranging the sprites horizontally.
a looks right. b looks left. Note how the individual sprites are rearranged and how the HFLIP bit is set in the second array.
Code: Select all
const unsigned char sspl_00_a [] = {
0xfc, 0xf8, 0x12, 0x00, 0x04, 0xf8, 0x13, 0x00,
0xfc, 0x00, 0x14, 0x00, 0x04, 0x00, 0x15, 0x00,
0xfc, 0x08, 0x16, 0x00, 0x04, 0x08, 0x17, 0x00,
0x80
};
const unsigned char sspl_00_b [] = {
0xfc, 0xf8, 0x13, 0x40, 0x04, 0xf8, 0x12, 0x40,
0xfc, 0x00, 0x15, 0x40, 0x04, 0x00, 0x14, 0x40,
0xfc, 0x08, 0x17, 0x40, 0x04, 0x08, 0x16, 0x40,
0x80
};
Re: Mirror sprites with Shiru's Library NESlib
Currently it is what I do.na_th_an wrote:You have to store two metasprite arrays, one for the original metasprite, and other with the flipped sprites, rearranging the sprites horizontally.
Code: Select all
const unsigned char sspl_00_a [] = { 0xfc, 0xf8, 0x12, 0x00, 0x04, 0xf8, 0x13, 0x00, 0xfc, 0x00, 0x14, 0x00, 0x04, 0x00, 0x15, 0x00, 0xfc, 0x08, 0x16, 0x00, 0x04, 0x08, 0x17, 0x00, 0x80 }; const unsigned char sspl_00_b [] = { 0xfc, 0xf8, 0x13, 0x40, 0x04, 0xf8, 0x12, 0x40, 0xfc, 0x00, 0x15, 0x40, 0x04, 0x00, 0x14, 0x40, 0xfc, 0x08, 0x17, 0x40, 0x04, 0x08, 0x16, 0x40, 0x80 };
a looks right. b looks left. Note how the individual sprites are rearranged and how the HFLIP bit is set in the second array.
I thought there would be a smarter way to do
Re: Mirror sprites with Shiru's Library NESlib
It's possible to use a single routine for the flipped sprite and the not-flipped sprite. You just have to arrange to EOR the flipped sprites' relative X coordinates with $FF when flipped or $00 when not and modify the metasprite's X position accordingly.