PDA

View Full Version : Overriding the DoDraw Procedure



Cer3brus
18-04-2009, 06:13 PM
When creating a class in delphiX for a character and, for instance, I wanted to draw the sprite rotated at an angle using the sprite engine, my code looked as follows:

THero = class(TImageSprite)
Speed : Integer;
Public
Procedure DoMove(MoveCount: Integer); override;
procedure DoCollision(Sprite: TSprite; var Done: Boolean); override;
Procedure DoDraw; override;
end;
It works... but the sprite gets drawn twice!! Once rotated and once normal. I probably set up the DoDraw incorrectly :(
Any ideas?

efilnukefesin
18-04-2009, 10:06 PM
and how does your dodraw-procedure look like?
perhaps there is an 'inherited' too much in it ::)

chronozphere
19-04-2009, 08:57 AM
First of all, do you call OnDraw yourself? You should call SpriteEngine.Draw instead :)

If that's not the sollution, does your DoDraw procedure contain "inherited;". This reserved-word calls the DoDraw procedure implemented by the ancestor class (Probably TImageSprite), which means that the sprite will be rendered twice.

If the problem persists, i suggest you to step through your code using breakpoints. Put breakpoints in the DoDraw procedures and one at "SpriteEngine.Draw". Start stepping through your code from there to what get's called. No doubt you'll be able to figure it out. ;)

As a last resort you can also use TSprite instead and implement all specific rendering yourself.

Hope it helps. ;)