Jump to content

  • Log In with Google      Sign In   
  • Create Account

How to remove the left overs of SDL_FillRect?


Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.

  • You cannot reply to this topic
6 replies to this topic

#1 DarkHorseKnight   Members   -  Reputation: 143

Like
0Likes
Like

Posted 28 January 2012 - 11:32 AM

Hello I'm trying to figure out how to remove this black crap off my OrangeGhostKnight Surface which you can see clearly in this picture below

Posted Image

what would be your suggestions and tips

I've already tried using

SDL_FillRect(Screen,&OrangeGhostKnightRect,(0,0,0));
SDL_BlitSurface(OrangeGhostKnightSurf,NULL,Screen,&OrangeGhostKnightRect);
SDL_SetColorKey(OrangeGhostKnightSurf, SDL_SRCCOLORKEY |SDL_RLEACCEL, SDL_MapRGB(OrangeGhostKnightSurf->format,0, 0, 0));
SDL_Flip(Screen);

SDL_SetColorKey(); Clearly doesn't work in this problem

Any suggestions or tips or am I doing this wrong ?

Sponsor:

#2 aeroz   Members   -  Reputation: 171

Like
0Likes
Like

Posted 28 January 2012 - 11:43 AM

With SDL_FillRect your are explicitly creating that black rectangle.
And also try setting the color key before you blit the surface.

#3 DarkHorseKnight   Members   -  Reputation: 143

Like
0Likes
Like

Posted 28 January 2012 - 12:34 PM

its still not working ;(


SDL_SetColorKey(OrangeGhostKnightSurf, SDL_SRCCOLORKEY |SDL_RLEACCEL,BlackColor);

what are like the common problems for SDL_FillRect not working?

#4 aeroz   Members   -  Reputation: 171

Like
0Likes
Like

Posted 28 January 2012 - 12:46 PM

What I meant is that you should entirely remove SDL_FillRect from your code. (or do you want to have a rectangle there?)

What does the OrangeGhostKnight surface look like? (or the base image) Is it black in the background?

Try this:

SDL_BlitSurface(OrangeGhostKnightSurf,NULL,Screen,&OrangeGhostKnightRect);
SDL_SetColorKey(OrangeGhostKnightSurf, SDL_SRCCOLORKEY |SDL_RLEACCEL, SDL_MapRGB(OrangeGhostKnightSurf->format,0, 0, 0));
SDL_Flip(Screen);


#5 DarkHorseKnight   Members   -  Reputation: 143

Like
0Likes
Like

Posted 28 January 2012 - 12:55 PM

the orange Coloured character in the image on my first post is that ghostknight and what I want to do is basically change his frames without it overlaying constantly like if it were a trail of images so I'm filling that Orange Coloured character rectangle and then trying to get rid of it because the fill colour is still showing as you can see in the above image

#6 fastcall22   Crossbones+   -  Reputation: 4456

Like
0Likes
Like

Posted 28 January 2012 - 01:15 PM

what I want to do is basically change his frames without it overlaying constantly like if it were a trail of images


There is no efficient way to do this. As soon as you write pixels to the Screen, the previous pixels are lost. You can track what used to be behind the sprite by copying those pixels first, then drawing them over your sprite with them afterwards. However, reading from video memory is quite slow (read: slower than redrawing the entire screen by several orders of magnitude), and keeping track of the "background pixels" quickly becomes complicated once you have sprites intersecting.

The easiest (and fastest) solution that most games go for is to just redraw the entire scene on top of what was already there.
c3RhdGljIGNoYXIgeW91cl9tb21bMVVMTCA8PCA2NF07CnNwcmludGYoeW91cl9tb20sICJpcyBmYXQiKTs=

#7 Servant of the Lord   Crossbones+   -  Reputation: 21000

Like
1Likes
Like

Posted 28 January 2012 - 03:11 PM

the orange Coloured character in the image on my first post is that ghostknight and what I want to do is basically change his frames without it overlaying constantly like if it were a trail of images so I'm filling that Orange Coloured character rectangle and then trying to get rid of it because the fill colour is still showing as you can see in the above image


Think about this for a second: (this is what you are currently doing)

1) You draw the background.
2) You draw your character.
3) You draw a black rectangle to erase your character.
4) You draw your character again.
5) You complain there is a black rectangle that you just drew two steps before.

What you are wanting to do is "undraw" your character... but that's not possible. You can't undraw something. Instead, you need to draw over it. What you have to do, is draw over the character with the background, and then draw the character again afresh.
You can do that in two different ways:

The easy way: (every loop/frame of your game)
1) Draw the entire background.
2) Draw all the objects over the background.
3) Apply to screen.

Basically, your drawing code looks like this:
1) Erase the entire screen. (so no images from the previous frame shows through)
2) Draw the background.
3) Draw any trees or objects North of the knight.
4) Draw the knight. (so the knight appears over those trees)
5) Draw any trees or objects south of the Knight (so the southern trees appear over the knight, letting him "walk behind" them)
6) Draw the GUI (buttons, menus, healthbars, text, etc...)

Except, you don't actually need to do step 1 ("Erase the entire screen"), because step 2 covers the entire screen anyway.

The hard way: (Don't do this)
1) Draw the background once only.
2) Every time an object moves, calculate and redraw just the piece of the background that covers where the object used to be.
3) Redraw the object.
4) Apply to the screen.

This is called 'Dirty rectangles'. Don't do it like this - it complicates things, and makes things unnecessarily hard while bringing you a benefit that you won't need.
The point of dirty rectangles is to get a little extra speed - but you already have enough speed in your computer, so no matter how slow you think your game is running, the solution is to find the real slowdown, not to use dirty rectangles. There are much easier, safer, and stabler ways to boost a program's speed.

This is how your game should be laid out.
It's perfectly fine to abbreviate my username to 'Servant' rather than copy+pasting it all the time.
All glory be to the Man at the right hand... On David's throne the King will reign, and the Government will rest upon His shoulders. All the earth will see the salvation of God.
Of Stranger Flames - [indie turn-based rpg set in a para-historical French colony] | Indie RPG development journal

[Fly with me on Twitter] [Google+] [My broken website]

[Need web hosting? I personally like A Small Orange]





Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.



PARTNERS