PDA

View Full Version : SpriteEngine (Draw transparent).



Chesso
05-01-2007, 01:31 PM
Yes another question, to be honest I haven't tried this yet, but I'm not much sure on how to go about it, if it is possible.

So I have a sprite player walking around and doing what ever.

And as a Sprite of it's own (purely to handle the animation of it for me) the Arrow that resides of the players head (I'm sure most of you have seen this in a number of games).

I would like to somehow tell the SpriteEngine, to draw this arrow with transparency so what is underneath it while animating can be seen.

For example his attacks while facing upward, or just other objects below it (not so important, but it would be nice mostly to be able to see his attacks beneath it).

I'm not sure if the arrow indicator will be much use with w/e transparency I will need to see reasonably underneath it, but that's one thing I want to find out.

Paizo
05-01-2007, 02:48 PM
override the draw procedure and use drawalpha there,
if you goggle around you can find tutorial about that like celebral byclicle site etc.. for make simple games and sprite engines with delphix

Chesso
05-01-2007, 02:58 PM
So basically, by overiding the draw procedure and using drawalpha, it's the same as letting it draw itself (aside from the fact that I am now using drawalpha, instead of letting it plain draw).

Just wanting to confirm that there is/isn't anything else to it.

I'll go have a look at that site (haven't checked it out in awhile).

Chesso
05-01-2007, 03:17 PM
UPDATE:

Ok I have over ridden the DoDraw procedure for my TArrow object.

It draws with transparency, but does not animated like usual.

Hoping for sheer luck, I added "Inherited DoDraw;", and it drew the static alpha transparent image, and then the normal *animated* one overtop lol.

Got any advice on how I can fix this up? There's probably some manual code to go into the DoDraw procedure I would assume.

jasonf
05-01-2007, 03:59 PM
well, the reason it's rendering the non-transparent version on top is probably because you're calling inherited in the code after you draw the arrow..

As for the animation not working, well.. the DoDraw function in TImageSprite.DoDraw; gets the image to draw from the animation using some variables which are private.

Try using something like this



procedure TMySprite.DoDraw();
var
SpriteRect : TRect;

begin

SpriteRect.Left :=round(x);
SpriteRect.Right := SpriteRect.Left+width;
SpriteRect.Top := round(y);
SpriteRect.Bottom := SpriteRect.top +height;

image.DrawAlpha( Engine.Surface,SpriteRect,round(animpos),AlphaValu e);

end;



Hopefully, this should retain the animation.

DraculaLin
05-01-2007, 05:59 PM
Not need!!

Just inherited from TImageSpriteEx.

Chesso
05-01-2007, 11:24 PM
DraculaLin, could you explain what you mean? the above isn't needed or the idea of overriding DoDraw.

I'm using the post above yours solution for now, seems to work well :).