nesdev.com
https://forums.nesdev.com/

Mirror sprites with Shiru's Library NESlib
https://forums.nesdev.com/viewtopic.php?f=2&t=16407
Page 1 of 1

Author:  Diskover [ Wed Aug 23, 2017 11:40 pm ]
Post subject:  Mirror sprites with Shiru's Library NESlib

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?

Author:  calima [ Thu Aug 24, 2017 12:37 am ]
Post subject:  Re: Mirror sprites with Shiru's Library NESlib

The OAM_FLIP flags go in the attribute field of the metasprite.

Author:  Diskover [ Thu Aug 24, 2017 3:01 am ]
Post subject:  Re: Mirror sprites with Shiru's Library NESlib

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?

Author:  dougeff [ Thu Aug 24, 2017 5:14 am ]
Post subject:  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).

Author:  na_th_an [ Sun Aug 27, 2017 3:25 am ]
Post subject:  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.

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.

Author:  Diskover [ Sun Aug 27, 2017 12:25 pm ]
Post subject:  Re: Mirror sprites with Shiru's Library NESlib

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 :(

Author:  tepples [ Sun Aug 27, 2017 1:05 pm ]
Post subject:  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.

Page 1 of 1 All times are UTC - 7 hours
Powered by phpBB® Forum Software © phpBB Group
http://www.phpbb.com/