Original Post

OK, I read the wiki page (http://www.planetvb.com/modules/dokuwiki/doku.php?id=background_map) and I can’t get it to work at all. What am I doing wrong?

if (flipping==1) VIP_REGS[HFLP1]=0x00;
if (flipping==2) VIP_REGS[HFLP1]=0x01;

11 Replies

It’s probably easier for you to just flip certain sprites in your bgmap in VIDE before you export it.

Why do you say that? Is it hard to flip sprites? If I did that, then I would have to do something like this:

if (flipping==2) copymem((void*)CharSeg1, (void*)SPRITEFLIPPEDCHAR, 256*16);
if (flipping==2) copymem((void*)BGMap(1), (void*)SPRITEFLIPPEDMAP, 256*16);
if (flipping==1) copymem((void*)CharSeg1, (void*)SPRITENOTFLIPPEDCHAR, 256*16);
if (flipping==1) copymem((void*)BGMap(1), (void*)SPRITENOTFLIPPEDMAP, 256*16);

Wouldn’t that slow down my program considerably?

It’s a bit harder than you think, because if you want to say mirror a fighter it’s not enough to just flip all its chars, you have to move all of them around within the map too, or you will end up with something like the image below.

Also, there’s no need to make a duplicate mirrored charset, it’s only the map that you’d have to have a mirrored version of. (if you can’t fit both mirrored and normal sprites in a single map)

Attachments:

Why wouldn’t I need another charset? Wouldn’t the characters be all messed up if I flipped the whole map horizontally?

You don’t need another charset because you never flip the actual chars, only how they appear in certain cells of the map.

All that said, here’s how you flip a single cell of a bgmap programmatically. You can’t flip the whole map at once, only one cell at a time, so just put it in a loop to flip a larger image.

A “cell” is a single tile (8×8 pixels) together with its palette info and flip info.

//Set H-flip bit (mirror) of bgmap at cell x,y
BGMM[bgmap*(0x1000) + (y * 64) + x] |= 0x2000;

//Clear H-flip bit (un-mirror) of bgmap at cell x,y
BGMM[bgmap*(0x1000) + (y * 64) + x] &= 0xDFFF;
  • This reply was modified 13 years, 4 months ago by DanB.

I never in a million years would have guessed that’s how you would flip a sprite! I tried your program sample and it came out just like you tried to tell me it would (It’s not that I didn’t trust you, it’s that I somehow thought you had fixed the way it would do that) , so in the end I just made another BGMap. Thanks for your help.

I didn’t say it wasn’t possible to correctly flip a large area of a bgmap through code, I just wanted you to try to figure out how to do it yourself first by pointing you in the right direction 😉

Here’s a function you can call that should work (Just wrote it, untested)

void HFlip(CHAR bgmap, CHAR startX, CHAR startY, CHAR width, CHAR height) {
  CHAR y;
  
  for (y=0; y

(startX, startY, width and height are number of cells, not pixels) To un-mirror, just run the function again on the same area of the map. Now you don't need to create separate mirrored versions of the maps!

Do you think that you could try to write some code that makes the guy turn when pressing left and not when pressing right? (The character originally faces right.) Because I tried and I couldn’t get it to do it right. When I pressed left, the character got all garbled and kept turning from left to right to left to right etc. whenever I tried to do it.

The problem was (is?) I was changing the sprite every other frame, so that’s why it went back and forth when I told it to flip (and I still don’t get why it did that.) When I tell it to change the sprite every frame, it works well, although the legs are moving faster when he’s going right as opposed to going left. I don’t know if that’s due to the VB’s computer having to work more to make it go left because I tell it to flip the sprite, or what.

Maybe you’re flipping the sprite from right-facing to left-facing every time it moves to the left, and not only when it changes the direction?

I think HorvatM is right. Here’s a little demo rom with source code of how you can do it:

Attachments:

 

Write a reply

You must be logged in to reply to this topic.