Jump to content
IGNORED

Quick question on tgi_sprite


LX.NET

Recommended Posts

Just a quick noob question on the use of tgi_sprite in cc65:

When I try to display the same sprite multiple times, (normal and horizontally flipped) I use the following code.

tgi_sprite(&spriteLeave1);
spriteLeave1.b0 = 0xE4; // Flip horizontally
spriteLeave1.posy = 16;
tgi_sprite(&spriteLeave1);

The end result is one (maybe two overlapping) sprite, which appears as flipped.

 

There must be an easy explanation and correct way to make this work. My goals is to display a single sprite.

say it looks like this:

[:>

to display like this:

[:><:][:><:][:>

I think it is ideal to use just a single SCB, but I'm not sure there.

 

And yes, I have some plans for a little port of a game (originally Atari 2600 game) to the Lynx.

Link to comment
Share on other sites

You can do something like that, stupid example but it works.

You sure you don't want to increment posx than posy ?

I may teach you to suck eggs, but as I don't see it on your code, if you're looping on it, don't forget to reinitialize the original values :)

while(1)
{
if(!tgi_busy())
{
 tgi_clear();

 spriteLeave1.posx = 80;
 spriteLeave1.b0 = SPRCTL0_4_bits_per_pixel | SPRCTL0_non_collide;
 tgi_sprite(&spriteLeave1t);

 spriteLeave1.posx = 80+16;
 spriteLeave1.b0 = SPRCTL0_4_bits_per_pixel | SPRCTL0_non_collide | SPRCTL0_h_flip;
 tgi_sprite(&spriteLeave1);

 tgi_updatedisplay();
}
}

Edited by obschan
Link to comment
Share on other sites

You can do something like that, stupid example but it works.

You sure you don't want to increment posx than posy ?

I may teach you to suck eggs, but as I don't see it on your code, if you're looping on it, don't forget to reinitialize the original values :)

 

I have tried something like that. You are right: the code fragment and my goal are not in sync.

Here's a more substantial piece of my code:

 

sprite_t spriteLeave1 = {
 0xc4, 0x10, 0x01,
 0,
 &leave1,
 48, 0,
 0x400, 0x100,
 {0x0b, 0x23, 0x45, 0x67, 0x89, 0xab, 0xcd, 0xef}
};
void ShowScreen(void)
{
 tgi_clear();
 tgi_sprite(&spriteLeave1);
 spriteLeave1.b0 = 0xE4;
 spriteLeave1.posx = 16;
 tgi_sprite(&spriteLeave1);
}
void main(void)
{
 while (1)
 {
   // Left out some stuff
   // ...
   if (!tgi_busy())
   {
  ShowScreen();
  tgi_updatedisplay();
   }
 };
}

 

What I see happen is a brief flash of the first sprite, then only the second altered SCB shows.

Have you tried your piece of code?

Thanks for the help

Link to comment
Share on other sites

You are looping on ShowScreen();

It works only one frame, that's why you see it "flashing", after that your sprite structure keeps the latest values you put in it.

So both sprite are at the same pos with same flip parameter.

You need to re-set posx and b0 before the first sprite.

 

Try this:

 

void ShowScreen(void)
{
 tgi_clear();
 spriteLeave1.b0 = 0xC4;
 spriteLeave1.posx = 0;
 tgi_sprite(&spriteLeave1);
 spriteLeave1.b0 = 0xE4;
 spriteLeave1.posx = 16;
 tgi_sprite(&spriteLeave1);
}
}

Link to comment
Share on other sites

Thanks obschan, especially for being so patient and not slagging me for this.

 

Well, this can go down into the history books as one of the stupidest programming mistakes.

 

Ahah no worries, would have been easier to spot it with a C debugger ;)

Link to comment
Share on other sites

Interesting. While debugging through a number of the commercial Lynx games in the past I noticed both approaches. There were games that did a new SPRGO for every single sprite. Others used chained SCB for the sprites. On average I would say that 50% were all single sprites (non-linked), 10% used one big chain and 40% a combination of small chains and single sprites. Note that these estimates are very rough.

 

I'll give it a spin. Got the sprites working now.

Link to comment
Share on other sites

If you want draw a map with one SCB its faster and easy to use a spritechain and let suzy do the job as creating a loop.

As example, the whole map of frogger i draw with one SCB that runs a chain with about 200 pictures.

 

Regards Matthias

 

That's interesting, how can you do that ? I may be missing something there.

With an unique scb you get to draw a full map ?

How do you update the sprite's coordinate during the internal loop ?

Link to comment
Share on other sites

Loop is perhaps a wrong term.

 

Matashen means a linked list of sprites.

 

You create many sprites where one sprite links to the next. The last sprites next pointer is zero.

 

If you draw the first sprite then Suzy continues with the next until all sprites are drawn.

 

--

Karri

Link to comment
Share on other sites

Ah yes, ok, misunderstanding.

For 200 sprites, you still have 200 SCB in this case.

No thats not exact what i mean, cause

1. you can copy SCBs so you dont need to define each SCB

2. you can set that the next sprite uses the same Colormap as the first SCB. That saves some Bytes Memory for every Sprite.

3. You can rebuild the SCB Map ever if you need by code. Youdont need to define it by start.

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...