Jump to content
  • Advertisement
phil67rpg

sprite sheet

Recommended Posts

I am learning how to use a sprite sheet to animate a sprite, are there any good tutorials that would help me or do you have any suggestions for me. I am using SOIL and opengl and c++.

Share this post


Link to post
Share on other sites
Advertisement
31 minutes ago, phil67rpg said:

hey retrometron do you have any suggestions

Did the example code @Ianuarius provided not give you enough of an idea to write your own?  In total it looks to be about 200-300 lines of code.  Should be quite easy to follow and port to your own needs.

Share this post


Link to post
Share on other sites
On 9/3/2018 at 5:54 PM, phil67rpg said:

I am learning how to use a sprite sheet to animate a sprite, are there any good tutorials that would help me or do you have any suggestions for me. I am using SOIL and opengl and c++.

In Photoshop, GIMP, ect... or whatever you use make a document size that follows the power of 2 rule then put your animation strip in the document. Once you have an object that represents your player or whatever it is you'll need to track the current draw area based on the frame you're on, and each "frame" will be a section of the texture file.

Frames usually alternate based on a timer. For example when you move right you run a timer that swaps frames every (x) milliseconds.

Is there something in the link above which @Ianuarius posted that you're having trouble with specifically?

Share this post


Link to post
Share on other sites

well I am able to draw a single sprite using SOIL and opengl and c++ I am trying to draw sprites using a sprite sheet. I am however able to draw the entire sprite sheet to the screen. I have been doing a lot of research on google. here is some of my code

int LoadGLTextures()
{
	texture[0] = SOIL_load_OGL_texture
	(
		"planesheet.png",
		SOIL_LOAD_AUTO,
		SOIL_CREATE_NEW_ID,
		SOIL_FLAG_INVERT_Y|SOIL_FLAG_POWER_OF_TWO|SOIL_FLAG_TEXTURE_REPEATS
	);

	if (texture[0] == 0)
		return false;

	glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
	glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);

	return true;
}

void display(void)
{
	glClear(GL_COLOR_BUFFER_BIT);

	glEnable(GL_TEXTURE_2D);

	glGenTextures(8, &texture[1]);
	glBindTexture(GL_TEXTURE_2D,texture[0]);

	glBegin(GL_QUADS);
	glTexCoord2f(0.0f, 0.0f); 
	glVertex3f(-1.0f, -1.0f, 0.0f);
	glTexCoord2f(1.0f, 0.0f); 
	glVertex3f(-1.0f, 1.0f, 0.0f);
	glTexCoord2f(1.0f, 1.0f); 
	glVertex3f(1.0f, 1.0f, 0.0f);
	glTexCoord2f(0.0f, 1.0f); 
	glVertex3f(1.0f, -1.0f, 0.0f);
	glEnd();

	glutSwapBuffers();
}

 

Share this post


Link to post
Share on other sites

I've read it over. You don't actually ask a question and instead merely write that you're having problems, but that seems to be your writing style. Do you have a question about that code?

Assuming you have a question about the code and simply forgot to ask it, look at the lines GlTexCoord2f().  Explain what those coordinates are for, what they do, and how they work. That will answer the questions you are probably facing next.

Share this post


Link to post
Share on other sites

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!