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.