It is currently Tue Dec 12, 2017 1:05 pm

All times are UTC - 7 hours





Post new topic Reply to topic  [ 7 posts ] 
Author Message
PostPosted: Wed Aug 23, 2017 11:40 pm 
Offline

Joined: Thu Nov 24, 2011 7:16 am
Posts: 170
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?


Top
 Profile  
 
PostPosted: Thu Aug 24, 2017 12:37 am 
Offline

Joined: Tue Oct 06, 2015 10:16 am
Posts: 601
The OAM_FLIP flags go in the attribute field of the metasprite.


Top
 Profile  
 
PostPosted: Thu Aug 24, 2017 3:01 am 
Offline

Joined: Thu Nov 24, 2011 7:16 am
Posts: 170
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?


Top
 Profile  
 
PostPosted: Thu Aug 24, 2017 5:14 am 
Offline
User avatar

Joined: Fri May 08, 2015 7:17 pm
Posts: 1866
Location: DIGDUG
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


Top
 Profile  
 
PostPosted: Sun Aug 27, 2017 3:25 am 
Offline

Joined: Mon May 27, 2013 9:40 am
Posts: 362
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.

_________________
http://www.mojontwins.com


Top
 Profile  
 
PostPosted: Sun Aug 27, 2017 12:25 pm 
Offline

Joined: Thu Nov 24, 2011 7:16 am
Posts: 170
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 :(


Top
 Profile  
 
PostPosted: Sun Aug 27, 2017 1:05 pm 
Offline

Joined: Sun Sep 19, 2004 11:12 pm
Posts: 19335
Location: NE Indiana, USA (NTSC)
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.


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 7 posts ] 

All times are UTC - 7 hours


Who is online

Users browsing this forum: No registered users and 6 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
Powered by phpBB® Forum Software © phpBB Group