[comp.sys.amiga.tech] ===> Need help with hardware sprites <===

greenwoode@merrimack.edu (Ed Greenwood) (08/17/90)

                                                              8/17/90


	Using Lattice C (version .5.04), I have been unable make more 
than one hardware sprite appear on the screen at a time.  When I do
try to put more than one sprite on the screen, any sprite that is there
will disappear.  I know thatha program must be linked with the "-ad"
option when you are working with sprites, but there anything else that
must be done?  All my knowledge of sprite graphics has come from the 
book, Inside the Amiga with C, by John Thomas Berry.  Are the sprite 
graphic programs in this book correct?  I would be grateful for any
comments or suggestions.
       

                                                 Thanks,
 
                                                   Ed Greenwood

greenwoode@merrimack.edu (Ed Greenwood) (08/20/90)

                                                              8/19/90


     Using Lattice C (v. 5.04), I have been unable to make more than 
one hardware sprite appear on the screen at the same time.  Whenever I 
place a sprite on the screen, all other sprites will immediately 
disappear.  I know the "-ad" option must be used when compiling a 
program that uses sprites, but is there anything else that must be done? 
My knowledge of sprite graphics has come from the book, INSIDE THE AMIGA
WITH C.  Are the sprite examples in this correct?  I would greatly
appreciate any comments or suggestions.

                                                          
                                                        Thanks,
                  
                                                        Ed Greenwood

ken@cbmvax.commodore.com (Ken Farinsky - CATS) (08/20/90)

In article <19919.26cec9ee@merrimack.edu> greenwoode@merrimack.edu (Ed Greenwood) writes:
>     Using Lattice C (v. 5.04), I have been unable to make more than 
>one hardware sprite appear on the screen at the same time.  Whenever I 
>place a sprite on the screen, all other sprites will immediately 
>disappear...

I would suggest reading the beginning of the chapter "Graphics:  Sprites,
Bobs and Animation", from the ROM Kernel Manual:  Libraries and Devices.

For each sprite that you use, you have to "get" another one from the
system.  For instance, if you want to use sprites 2 and 3 (note that
sprite 0 is the intuition pointer and sprite 1 can be paired with it,
avoid these sprites if possible...) you would do something like:

	struct SimpleSprite sprite2,sprite3;
	extern UWORD chip sprite_data2,sprite_data3;

	if (-1 == (sprite_number2 = GetSprite(&sprite2,2))
		; /* error, could not get sprite */
	else
		{
		/* here we can use sprite2 */
		if (-1 == (sprite_number3 = GetSprite(&sprite3,3))
			; /* error, could not get sprite */
		else
			{
			/* here we can use sprite3 */
			ChangeSprite(NULL,&sprite2,sprite_data2);
			ChangeSprite(NULL,&sprite3,sprite_data3);

			/* do more stuff here */
			rest_of_program(&sprite2,&sprite3);

			/* after you are done with the sprites,
			** free them.
			*/
			FreeSprite(sprite_number3);
			}
		FreeSprite(sprite_number2);
		}

If you "re-use" a sprite, say sprite 2, and load new data into it, then
the old image will go away when the new one appears.

>...I know the "-ad" option must be used when compiling a 
>program that uses sprites, but is there anything else that must be done? 

You do NOT need to use the -ad flag when using sprites, you simply must
insure that the sprite image data is in chip memory.  you can do this
with the following construct:

	UWORD chip sprite_data[] =
		{
		0,0, /* position control */
		0xffff, 0xffff, /* image data goes in here */
		0,0, /* after image data must have 0,0 */
		};

This is the only part of a sprite that has to go into chip memory.
You can use the chip or __chip keywords to tell lattice that the data
is to be placed into chip memory.  Once you have access to the sprite,
install the data with a call to ChangeSprite().

>My knowledge of sprite graphics has come from the book, INSIDE THE AMIGA
>WITH C.  Are the sprite examples in this correct?

Don't know.

-- 
--
Ken Farinsky - CATS - (215) 431-9421 - Commodore Business Machines
uucp: ...{uunet,rutgers}!cbmvax!ken
bix:  kfarinsky