Mirror sprites with Shiru's Library NESlib

Discuss technical or other issues relating to programming the Nintendo Entertainment System, Famicom, or compatible systems. See the NESdev wiki for more information.

Moderator: Moderators

Post Reply
User avatar
Diskover
Posts: 219
Joined: Thu Nov 24, 2011 7:16 am
Contact:

Mirror sprites with Shiru's Library NESlib

Post by Diskover »

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?
calima
Posts: 1745
Joined: Tue Oct 06, 2015 10:16 am

Re: Mirror sprites with Shiru's Library NESlib

Post by calima »

The OAM_FLIP flags go in the attribute field of the metasprite.
User avatar
Diskover
Posts: 219
Joined: Thu Nov 24, 2011 7:16 am
Contact:

Re: Mirror sprites with Shiru's Library NESlib

Post by Diskover »

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?
User avatar
dougeff
Posts: 3078
Joined: Fri May 08, 2015 7:17 pm

Re: Mirror sprites with Shiru's Library NESlib

Post by dougeff »

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).
nesdoug.com -- blog/tutorial on programming for the NES
na_th_an
Posts: 558
Joined: Mon May 27, 2013 9:40 am

Re: Mirror sprites with Shiru's Library NESlib

Post by na_th_an »

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.
User avatar
Diskover
Posts: 219
Joined: Thu Nov 24, 2011 7:16 am
Contact:

Re: Mirror sprites with Shiru's Library NESlib

Post by Diskover »

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.
Currently it is what I do.

I thought there would be a smarter way to do :(
tepples
Posts: 22705
Joined: Sun Sep 19, 2004 11:12 pm
Location: NE Indiana, USA (NTSC)
Contact:

Re: Mirror sprites with Shiru's Library NESlib

Post by tepples »

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.
Post Reply