Clipping Error

Started by
12 comments, last by BeerNutts 11 years, 2 months ago

I don't know if the problem would be classified as a clipping error or what, but sometimes the tops/bottoms of sprites shift to the left or the right or a block is cut out of them. It isn't a major problem and only shows up for a single frame, but it still occurs and I am still able to catch it. I am using SDL alongside C. What can I do to eliminate this problem? I have attached an example image, where the sprite on the left is the original and the ones on the right are the modified ones. Thank you! :)

Advertisement

Well, in order to eliminate it we'll need to find out what's causing it. Could you give us some information that may help narrow those possibilities down?

void hurrrrrrrr() {__asm sub [ebp+4],5;}

There are ten kinds of people in this world: those who understand binary and those who don't.

Here is the basic layout of the code. Maybe I am doing something ineffectively:


SDL_Init(SDL_INIT_EVERYTHING);
SDL_Surface *screen=SDL_SetVideoMode( 200, 200, 32, SDL_SWSURFACE ), *sprite=IMG_Load("sprite.png");
SDL_Rect location;
while(1) {
       /* Code here to move it. */
       SDL_BlitSurface(sprite,NULL,screen,&location);
       SDL_Flip(screen);
       SDL_Delay(35); }

Could the delay possibly be causing the problem? I need a way to keep it from hogging the processing power to itself and using a delay is the only thing that came to mind. Thanks!

This might be a bit of an obvious one but best to eliminate the simple factors first. Are the images in your sprite sheet aligned properly. As the image may be starting off the top of your sprites drawing box.

Or is your drawing rectangle of your sprite being set in a slightly offset position.

These are assuming you're using a single sprite sheet and are only drawing a specific area of the sprite sheet using a rectangle. Though without knowing how you're drawing your sprite exactly or the image you're drawing from makes it a little more difficult.

I am using a sprite sheet and have the proper coordinates, yes. As I have stated, it is not a constant issue that happens on every frame nor a certain frame, so I don't think it is in the code itself. It is barely noticeable and easiest to catch when the game is running and you take a screenshot of it with the keyboard key for that. Is this because SDL_Flip does not replace the whole screen area all at once but instead starts at the bottom and goes up in blocks? Or starts at the top and goes down? I can see how this could cause the rendering issue in screenshots taken. The top half of the player is from the old position and the bottom half is from the new position... so everything below a certain line is new and everything above it is the previously flipped screen. I'm wondering what I can do so I can take a screenshot of the game without the refresh issue being involved.

So I think I have found the problem. It isn't anything to do with my code (which I already figured), but instead has to do with the way SDL is refreshing the graphics. Is there anything whatsoever I can do about this? Thank you!

EDIT: It rarely ever happens. Is it really anything to be concerned about? I may be over-thinking everything...

Could it be an artifact from v sync shearing? Meaning, is it just whem your screen has updatwd in the middle of sdl drawing to screen? Try to turn on v sync and see if it still happens.

My Gamedev Journal: 2D Game Making, the Easy Way

---(Old Blog, still has good info): 2dGameMaking
-----
"No one ever posts on that message board; it's too crowded." - Yoga Berra (sorta)

Just did a reputation++; for you! Is it possible to enable V-Sync-ing software-side via SDL, or will whoever plays the game have to enable it? Thank you! :) Definitely a topic for me to research! :)

Just did a reputation++; for you! Is it possible to enable V-Sync-ing software-side via SDL, or will whoever plays the game have to enable it? Thank you! smile.png Definitely a topic for me to research! smile.png

Google "SDL vsync"

Check the top 2 responses. It seems SDl doesn't natively support it, but it may be turned on via a OpenGL call.

BTW, may I suggest you look into SFML? IMO, it's a better multimedia API solution. You don't have to use it, but I advise at least looking into it. Having used both (SDL and SFML), I find SFML to be FAR superior.

My Gamedev Journal: 2D Game Making, the Easy Way

---(Old Blog, still has good info): 2dGameMaking
-----
"No one ever posts on that message board; it's too crowded." - Yoga Berra (sorta)

More reputation++; for you! I found the line of code for it and added it to my code. I don't see it often, so I haven't noticed and changes yet... hopefully it has eliminated the problem!

Thanks for the recommendation! I did some research on it to find that it is a lot easier to catch on to than SDL and that it is higher level. For me, higher level stuff is just more confusing (even though higher level is meant to be more understandable). I noticed that it is still in early stages and not as portable as SDL, and that SDL has better performance. SFML sounds like something to keep an eye on, but I prefer SDL and the low level atmosphere. Thank you for bringing it to my attention, and thank you very much for providing the solution to my problem! smile.png

I noticed that it is still in early stages and not as portable as SDL, and that SDL has better performance.

Where did you hear that? You're looking at the wrong thing if you think SFML is in the early stages. You'll find SFML has MUCH better performance than SDL.

About 2 years ago, I was trying to write a game in SDL (as I had used it multiple times before on other projects), and it included a rotating sprite. SDL's doesn't natively support rotation, so I tried using using SDL_gfx to rotate an image, and it worked, but it was awfully slow.

So, I then tried it SFML, and using sf::Sprite::setRotation(), there was no delay. It was night and day. I would never consider going back to SDL after using SFML.

BTW, SFML also has sf::Window::setVerticalSyncEnabled() to control v-sync form the application.

SDL is fine for many things, but I'll never go back to it after using SFML for the last 2 years.

Good luck and have fun!

My Gamedev Journal: 2D Game Making, the Easy Way

---(Old Blog, still has good info): 2dGameMaking
-----
"No one ever posts on that message board; it's too crowded." - Yoga Berra (sorta)

This topic is closed to new replies.

Advertisement