Jump to content

Photo

Quick question on tgi_sprite


12 replies to this topic

#1 LX.NET ONLINE  

LX.NET

    Moonsweeper

  • 444 posts
  • Location:The Netherlands

Posted Sat Mar 24, 2012 5:37 PM

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.

#2 obschan OFFLINE  

obschan

    Chopper Commander

  • 149 posts
  • Location:Hong-Kong

Posted Sat Mar 24, 2012 11:13 PM

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, Sat Mar 24, 2012 11:33 PM.


#3 LX.NET ONLINE  

LX.NET

    Moonsweeper

  • Topic Starter
  • 444 posts
  • Location:The Netherlands

Posted Sun Mar 25, 2012 2:53 PM

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

#4 obschan OFFLINE  

obschan

    Chopper Commander

  • 149 posts
  • Location:Hong-Kong

Posted Sun Mar 25, 2012 6:02 PM

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);
}
}


#5 LX.NET ONLINE  

LX.NET

    Moonsweeper

  • Topic Starter
  • 444 posts
  • Location:The Netherlands

Posted Mon Mar 26, 2012 3:31 PM

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.

#6 obschan OFFLINE  

obschan

    Chopper Commander

  • 149 posts
  • Location:Hong-Kong

Posted Mon Mar 26, 2012 7:57 PM

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 ;)

#7 matashen OFFLINE  

matashen

    Moonsweeper

  • 455 posts

Posted Tue Mar 27, 2012 3:45 AM

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

#8 LX.NET ONLINE  

LX.NET

    Moonsweeper

  • Topic Starter
  • 444 posts
  • Location:The Netherlands

Posted Wed Mar 28, 2012 1:24 PM

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.

#9 Shawn Jefferson OFFLINE  

Shawn Jefferson

    Stargunner

  • 1,700 posts
  • Location:Victoria, Canada

Posted Wed Mar 28, 2012 7:46 PM

I imagine it depends a lot on the structure of your game, the on-screen elements and your programming style.

#10 obschan OFFLINE  

obschan

    Chopper Commander

  • 149 posts
  • Location:Hong-Kong

Posted Sat Mar 31, 2012 12:46 AM

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 ?

#11 karri OFFLINE  

karri

    Stargunner

  • 1,398 posts
  • Location:Espoo, Finland

Posted Sat Mar 31, 2012 3:02 AM

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

#12 obschan OFFLINE  

obschan

    Chopper Commander

  • 149 posts
  • Location:Hong-Kong

Posted Sat Mar 31, 2012 3:52 AM

Ah yes, ok, misunderstanding.
For 200 sprites, you still have 200 SCB in this case.

#13 matashen OFFLINE  

matashen

    Moonsweeper

  • 455 posts

Posted Sat Mar 31, 2012 6:43 AM

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.




0 user(s) are browsing this forum

0 members, 0 guests, 0 anonymous users