This page is a mirror of Tepples' nesdev forum mirror (URL TBD).
Last updated on Oct-18-2019 Download

Mirror sprites with Shiru's Library NESlib

Mirror sprites with Shiru's Library NESlib
by on (#203139)
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?
Re: Mirror sprites with Shiru's Library NESlib
by on (#203142)
The OAM_FLIP flags go in the attribute field of the metasprite.
Re: Mirror sprites with Shiru's Library NESlib
by on (#203144)
calima wrote:
The OAM_FLIP flags go in the attribute field of the metasprite.


Yes, I know that with OAM_FLIP I mirror the sprite array.

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
by on (#203147)
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).
Re: Mirror sprites with Shiru's Library NESlib
by on (#203343)
You have to store two metasprite arrays, one for the original metasprite, and other with the flipped sprites, rearranging the sprites horizontally.

Code:
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.
Re: Mirror sprites with Shiru's Library NESlib
by on (#203360)
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:
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.


Currently it is what I do.

I thought there would be a smarter way to do :(
Re: Mirror sprites with Shiru's Library NESlib
by on (#203365)
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.