Troubles with sprites (new version SGDK)

SGDK only sub forum

Moderator: Stef

Hik
Very interested
Posts: 68
Joined: Thu Jul 30, 2015 11:39 pm
Location: Iceland

Re: Troubles with sprites (new version SGDK)

Post by Hik » Mon Sep 19, 2016 2:38 pm

sprite.h

Code: Select all

#ifndef _RES_SPRITE_H_
#define _RES_SPRITE_H_

extern const SpriteDefinition sega_logo_sprite;

#endif // _RES_SPRITE_H_
sprite.res

Code: Select all

SPRITE sega_logo_sprite "sega_logo_spritesheet.png" 13 4 -1 10
main.c

Code: Select all

#include <genesis.h>
#include "gfx.h"
#include "sprite.h"

//Sets default values for VDP register
//Cleans video RAM
//Loads 4 default palettes ; Grey, Red, Green and Blue
//Loads a default font for text print need
//Initializes input handling
//Resets sound and music
//Loads a default sound driver

// Sprite structure
Sprite sprites[2];

int main( )
{
	// Define variables
	u16 ANIM_LOGO;
	s16 posx = 111; //0x6F (Hex)
	s16 posy = 88; //0x58 (Hex)
	u16 palette[64];
	u16 ind;
	int counter = 0;
	
	// Disable interrupts when accessing VDP
    SYS_disableInts();
    // Initialization
    VDP_setScreenWidth320();
	VDP_setScreenHeight240();
	// Init sprites engine
    SPR_init(16,256,256);

	// Init logo sprite
	ind = TILE_USERINDEX;
    sprites[0] = SPR_addSprite(&sega_logo_sprite, posx, posy, TILE_ATTR(PAL0, TRUE, FALSE, FALSE)); //This is the only line I get an error on
    	//SPR_update(sprites, 1);
	// Prepare palettes
	memcpy(&palette[16], sega_logo_sprite.palette->data, 16 * 2);
	VDP_setPalette(0, sega_logo_sprite.palette->data);
	//Animation
	SPR_setAnim(&sprites[0], ANIM_LOGO);
	SYS_enableInts();
	
	...
	//Check Hik's SGDK Experiments thread for full code on the old version
}
main.c: In function 'main'
main.c:36: error: incompatible types in assignment
main.c:109:2: warning: no newline at end of file
make: *** [out/main.o] Error 1

Grind
Very interested
Posts: 69
Joined: Fri Jun 13, 2014 1:26 pm
Location: US
Contact:

Re: Troubles with sprites (new version SGDK)

Post by Grind » Mon Sep 19, 2016 2:51 pm

SPR_addSprite returns a pointer, so define sprites as

Sprite *sprites[2];

Then when passing sprites don't use a reference since it is already a pointer.

SPR_setAnim(sprites[0], ANIM_LOGO);

Hik
Very interested
Posts: 68
Joined: Thu Jul 30, 2015 11:39 pm
Location: Iceland

Re: Troubles with sprites (new version SGDK)

Post by Hik » Mon Sep 19, 2016 3:03 pm

Thanks it works now.

Post Reply