Jump to content
  • Advertisement


This topic is now archived and is closed to further replies.


[SDL] Trouble drawing to screen

This topic is 5221 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

void CSprite::draw() {
	if(mAnimating) {									// if the sprite is animating, do the checking for frames

		if(mLastUpdate + mBase->mAnim[mFrame].pause * mSpeed < SDL_GetTicks()) {
			if(mFrame > mBase->mNumFrames - 1)
			mLastUpdate = SDL_GetTicks();

		mDrawn = true;

	blit.x = mX;
	blit.y = mY;

	SDL_BlitSurface(mBase->mAnim[mFrame].image, NULL, mScreen, &blit);

class CSprite {											// actual individual sprites for each entity

		int getframe() { return mFrame; }
		void init(CSpriteBase *base, SDL_Surface *screen);
		void draw();
		void clearbg();
		void updatebg();
		void setframe(int nr) { mFrame = nr; }
		void setspeed(float nr) { mSpeed = nr; }
		void toggleanim() { mAnimating = !mAnimating; }
		void startanim() { mAnimating = true; }
		void stopanim() { mAnimating = false; }
		void resetanim() { mFrame = 0; }
		void setpos(int x, int y) { mX = x; mY = y; }
		float getspeed() { return mSpeed; }
		CSpriteBase *mBase;
		SDL_Surface *mBackreplace;
		SDL_Surface *mScreen;
		SDL_Rect blit;
		bool mAnimating;
		bool mDrawn;
		int mFrame;
		int mX, mY, mOldX, mOldY;
		int mBaseNum;									// which sprite base to use

		float mSpeed;
		long mLastUpdate;
I''m getting a Segmentation Parachute error from SDL whenever I call this function. If there''s any more information that you need, just ask. Thanks for your help -------------------------------- The Seishou Project - 1% complete Come support us! It gives us motivation

Share this post

Link to post
Share on other sites
Without seeing more of your code, my only guess is that maybe the surface, mscreen, hasn''t been intialized.

I might could help more, if you at least post the code to the init method and the program code that is causing the error.

Share this post

Link to post
Share on other sites
// screen is a global SDL_Surface used for SDL_SetVideoMode

p.spr.init(&spr_base[0], screen);

void CSprite::init(CSpriteBase *base, SDL_Surface *screen) {
mBase = base;
if(mBase->mBuilt) { // if this sprite base was loaded and exists

if(mBase->mNumFrames > 1) // if there''s more than 1 frame, it must be animated

mBackreplace = SDL_DisplayFormat(mBase->mAnim[0].image);
mScreen = screen;

// i know for a fact that clearbg() and updatebg() arent the cause

void CEngine::draw_scene() {




Is that enough? :| If you need any clarifications, just say.

Share this post

Link to post
Share on other sites
I''m terrible at wrapping my head around the way some people code, so I''m just goingto suggest that you run this in a debugger and see which line of your code causes teh egmentation fault, and then see if you can figure out why. (null pointer, or pointer going off the end of your array, most likely)

Share this post

Link to post
Share on other sites
Nevermind. I forgot to set mFrame to 0 when initializing, so the BlitSurface function was failing -_-

Thanks for the input, though!

[edited by - EQRainer on April 5, 2004 8:41:43 PM]

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!