8 Replies - 9338 Views - Last Post: 06 April 2009 - 11:50 PM Rate Topic: -----

#1 revned  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 11
  • Joined: 10-February 09

How to use a Sprite Sheet

Posted 03 April 2009 - 09:12 PM

ok i am creating a game and i just started in Dark GDK C++. right know the character is just a box but i would like it to use a sprite sheet. i am wondering how to put it in my game?

here is the code so far. it is just simple for right know.
void DarkGDK ( void )
{
	// turn on sync rate and set maximum rate to 60 fps
	dbSyncOn   ( );
	dbSyncRate ( 60 );
	dbLoadImage("cube.jpg",1);//user picture
	dbLoadImage("Enemy.jpg",2);//enemy
	//random
	int random_Y = (rand()%475)+1;
	int random_X = (rand()%650)+1;
.
.
.
.
.
								dbSprite(1,UserX,UserY,1);//position of User and movement
		dbSprite(2,EneX,EneY,2);//position of enemy and movement
		// update the screen
		dbSync ( );
	}

	// return back to windows
	return;



Is This A Good Question/Topic? 0
  • +

Replies To: How to use a Sprite Sheet

#2 SigurdSuhm  Icon User is offline

  • D.I.C Head

Reputation: 18
  • View blog
  • Posts: 111
  • Joined: 05-August 08

Re: How to use a Sprite Sheet

Posted 04 April 2009 - 03:52 AM

I'm not familiar with the DarkGDK framework to be honest. But the general idea of spritesheets is that you load an image and then only draw part of it. So instead of using the full height and width of the texture you draw images with 1/3 of each for example (in case of a 3x3 sprite sheet). You also have to specify an offset so your program knows where in the image it should fetch the sprite to be drawn.

As I said I don't really know DarkGDK and I don't know if it has any built in features for this. If not you would probably have to write your own algorithm. I'll check in later to see if anyone knows anything about DarkGDK's features for sprite sheets.

Regards
Sigurd
Was This Post Helpful? 0
  • +
  • -

#3 stayscrisp  Icon User is online

  • フカユ
  • member icon

Reputation: 994
  • View blog
  • Posts: 4,158
  • Joined: 14-February 08

Re: How to use a Sprite Sheet

Posted 04 April 2009 - 07:59 AM

Hi

Dark GDK has built in support for sprite sheets, the hello world tutorial uses one.

You will need to split your sprite sheet into different rows or columns for each type of animation, such as your walk animation could be one column 1 with a maximum of 6 frames, then your code would loop between these frames by incrementing the height of the sprite each time until a certain point then resetting and doing it again.

But read the hello world tutorial for Dark GDK for the basics.
Was This Post Helpful? 0
  • +
  • -

#4 revned  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 11
  • Joined: 10-February 09

Re: How to use a Sprite Sheet

Posted 05 April 2009 - 05:22 PM

ok so i did follow the tutorial know i did my own and i get a error.

heres the code
// Dark GDK - The Game Creators - www.thegamecreators.com

// the wizard has created a very simple 2D project that uses Dark GDK
// it can be used as a starting point in making your own 2D games

// whenever using Dark GDK you must ensure you include the header file
#include "DarkGDK.h"

// the main entry point for the application is this function
void DarkGDK ( void )
{
	
	dbSyncOn   ( );
	dbSyncRate ( 60 );

	dbCreateAnimatedSprite(1,"sheet.jpg",6,29,1);
	dbSprite(1,5,5,1);
	while ( LoopGDK ( ) )
	{
		dbPlaySprite(1,1,5,200);
		

		
		
		dbSync ( );
	}

	
	return;
}


and here is the error that i get
1>------ Build started: Project: spritesheet2, Configuration: Debug Win32 ------
1>Compiling...
1>Main.cpp
1>Linking...
1>C:\Program Files\The Game Creators\Dark GDK\Lib\VS9\darksdk.lib : fatal error LNK1107: invalid or corrupt file: cannot read at 0x471B21
1>Build log was saved at "file://c:\Users\name\Downloads\Documents\Visual Studio 2008\Projects\spritesheet2\Debug\BuildLog.htm"
1>spritesheet2 - 1 error(s), 0 warning(s)
========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========


Was This Post Helpful? 0
  • +
  • -

#5 stayscrisp  Icon User is online

  • フカユ
  • member icon

Reputation: 994
  • View blog
  • Posts: 4,158
  • Joined: 14-February 08

Re: How to use a Sprite Sheet

Posted 05 April 2009 - 11:20 PM

It looks like you havent set up Dark GDK properly, follow this tutorial here then try again. This looks like it checks you have installed things right which should be helpful.

Good luck
Was This Post Helpful? 0
  • +
  • -

#6 WolfCoder  Icon User is offline

  • Isn't a volcano just an angry hill?
  • member icon


Reputation: 781
  • View blog
  • Posts: 7,604
  • Joined: 05-May 05

Re: How to use a Sprite Sheet

Posted 06 April 2009 - 06:42 AM

I wrote my program which converts many images into my own format. Each image gets chopped up into different frames so that I can load them each as their own. It's worth it, but involving since you have to write another program. It does help in the long run once you're ready to do 3D and texture coords. I find they can screw up easily if you're not careful.

This post has been edited by WolfCoder: 06 April 2009 - 06:43 AM

Was This Post Helpful? 0
  • +
  • -

#7 revned  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 11
  • Joined: 10-February 09

Re: How to use a Sprite Sheet

Posted 06 April 2009 - 03:56 PM

well i read through that installation thing and i did it the way they said. but i have other games that i have been making and they have work. just not this one since i put in the sprite sheet.
Was This Post Helpful? 0
  • +
  • -

#8 revned  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 11
  • Joined: 10-February 09

Re: How to use a Sprite Sheet

Posted 06 April 2009 - 04:45 PM

so i tried it on another game and it works fine but it uses a differnet sprite sheet and it only has one row of images.
here is the code. its just simple
dbSyncOn   ( );
	dbSyncRate ( 60 );
	//load image
	dbSetImageColorKey(255,255,255);
	dbCreateAnimatedSprite(1,"ninjarunning.png",7,1,1);
	
	

	// our main loop
	while ( LoopGDK ( ) )
	{
		//variables for movement of circle
	float UserX=0,UserY=0,UserSpeed=0;
	//gravity
	float Gravity = -2;
	if(dbUpKey())
	{
		dbPlaySprite(1,1,7,200);
	}
	dbPlaySprite(1,1,1,200);
		
		//Create the character sprite
	dbSprite(1,UserX,UserY,1);
		// update the screen
		dbSync ( );
	}

	// return back to windows
	return;
}


Was This Post Helpful? 0
  • +
  • -

#9 stayscrisp  Icon User is online

  • フカユ
  • member icon

Reputation: 994
  • View blog
  • Posts: 4,158
  • Joined: 14-February 08

Re: How to use a Sprite Sheet

Posted 06 April 2009 - 11:50 PM

Do you have any way of converting your file or changing size?

A lot of programs like a certain size of file or multiples of a number or it wont load it. Try getting the size of the other sheet (that works), and change one of your own columns to that size to test.
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1