Sprite Tile Order Corruption

SGDK only sub forum

Moderator: Stef

Post Reply
TechnoZealot
Interested
Posts: 30
Joined: Mon May 06, 2013 2:27 am
Location: Vermont, USA

Sprite Tile Order Corruption

Post by TechnoZealot » Tue May 07, 2013 6:05 pm

So I've noticed that if I load a 32x32 bitmap with VDP_loadBMPTileData() that displays entirely correctly if I display it to the screen on Plane A with VDP_fillTileMapRectInc() will have it's 8x8 tiles all jumbled up when displayed as a sprite.

I am loading it (to swap the picture) periodically in my game loop, and this probably is suboptimal, but nevertheless, I don't think it is the problem.

Here is my sprite code:

Code: Select all

#include <genesis>
#include "ship1.h"

int main()
{
	VDP_setPalette(PAL0, ship1.palette);

	VDP_loadBMPTileData((u32*) ship1.image, TILE1, ship1.w/8, ship1.h/8, ship1.w/8);

//This works!
	VDP_fillTileMapRectInc(APLAN, TILE_ATTR_FULL(PAL0, 0, 0, 0, TILE1), 15, 15, ship1.w/8, ship1.h/8);


	SpriteDef myShip;
	
	myShip.posx = (320-ship1.w)/2;
	myShip.posy = (224-ship1.h)/2;
	myShip.size = SPRITE_SIZE(4,4);
	myShip.tile_attr = TILE_ATTR_FULL(PAL0,1,0,0,TILE1);
	myShip.link  = 0;
	

	VDP_setSpriteP(0, &myShip);

	VDP_updateSprites();

	while(1)
	{
		VDP_waitVSync();
	}
}
What's wrong here?

djcouchycouch
Very interested
Posts: 710
Joined: Sat Feb 18, 2012 2:44 am

Post by djcouchycouch » Tue May 07, 2013 7:11 pm

By "jumbled", do you mean that the tiles are random or that the order is incorrect?

Something like:

What you want:

ABC
DEF
GHI

What you get:
ADG
BEH
CFI

Meaning that the rows and columns are swaped?

TechnoZealot
Interested
Posts: 30
Joined: Mon May 06, 2013 2:27 am
Location: Vermont, USA

Post by TechnoZealot » Tue May 07, 2013 7:48 pm

Exactly. they are swapped.

Here's what it should look like:

Image

Here's what it ends up looking like:

Image

kubilus1
Very interested
Posts: 237
Joined: Thu Aug 16, 2012 2:25 am
Contact:

Post by kubilus1 » Wed May 08, 2013 3:15 am

The tile order will be different for the sprite than the straight up BMP. I posted a link on another question of yours where I address this question exactly with a shell script to arrange the tiles of a BMP into a spriteable format.

I believe there are some other tools to do this (Genres?) Take a look at some of the tutorials on the SGDK website: https://code.google.com/p/sgdk/wiki/SGD ... al#Sprites

Some of the examples are out of date, but the general ideas should hold.

TechnoZealot
Interested
Posts: 30
Joined: Mon May 06, 2013 2:27 am
Location: Vermont, USA

Post by TechnoZealot » Wed May 08, 2013 5:54 pm

Thank you very much! This is invaluable! :D

Somehow I didn't quite understand your link earlier. Now it makes perfect sense! Sorry about that! :P

kubilus1
Very interested
Posts: 237
Joined: Thu Aug 16, 2012 2:25 am
Contact:

Post by kubilus1 » Thu May 09, 2013 2:03 am

Not a problem at all! Glad to be of assistance.

Post Reply