View Full Version : Drawing on a SpriteEngine image?
MikeSee
08-09-2006, 02:00 AM
Hi there all,
I'm playing with some old(er) DelphiX demo code just to help me get familar with DelphiX and I've become stuck:
Could someone please tell me if it is possible to draw on to the sprite image fo a sprite loaded into a SpiteEngine? E.g. let's say I want to draw particles via pixel access or maybe even blitting an other image on to the sprite... I've been trying for days to get anything to work.
Any help would be great - I'm pulling chunks of hair out over this :shock:
Speeeder
08-09-2006, 09:54 AM
uuhhmm, drawing with pixel-by-pixel or bitting for a particle system will be slooooooooowwwwww like hell I think! I have a picture loaded in an ImageList or TDirectDrawSurface and I draw the thing with the hardware accelerated methods any time the particle exists. Not the fastest I could think of for sure, but it's working, and I think it's alot faster than eighter blitting or pixel access. There was a demo of a smoke thingy, and I've played around with that, here's the source of the smoke thingy I've found on my HDD: Clicky (http://www.yousendit.com/transfer.php?action=download&ufid=B08B549160D617EB)
Hope that helps!
blackvoid
10-09-2006, 01:01 PM
You can draw on top of sprites yes!
If it is another sprite, then you have to set the right z order, if it is something else, just draw it after the sprite in your draw loop.
MikeSee
11-09-2006, 10:29 PM
Speeeder, thanks very much for your excellent code sample - it's given me lots of ideas!
blackvoid, I think I understand what you're saying but my question would be how? My problem seems to stem from not being able to alter the sprite image in question if it is held in a SpriteEngine. Let me restate my problem: say I have a sprite depicting a rally car - at the start of a race it'd be all shiny and clean but as the race wears on the car would get dirtier and dirtier... I know I could use different (pre-drawn) versions of my car's sprite image to show the car getting dirtier but what I want to do is "splatter" the car with "mud" in a random-ish manner. Hence why I said "particles" in the original post. The crux of the matter is I can't find a way of referencing a SpriteEngine image with a draw/pixel or even blit method... and I've been trying for ages now.
My guess is that if it can't be done directly maybe I'll have to draw to an ImageList object then copy that into place in the SpriteEngine and then display it - a drawn out process and therefore probably quite slow(?)
Otherwise I'll have to abandon the SpriteEngine and use DirectDrawSurfaces and write my own draw, collision check etc routines - something I'm not equipped for, yet...
Instead of changing the image why not "blend" particles over the image. i.e. you draw the car and then you draw the "mud" over the top.
How big are your images will anyone even see and appreciate the visual change? You could also build the car out of a number ofimages e.g. two for the front of the car. If the front left is damaged draw the damaged version of the front left image.
It is possible to access the pixels in the imagelist. I cannot remember how but I have. Don't forget to do a restore after you change the pixels in the image.
Speeeder
12-09-2006, 01:23 PM
Firstly the sample isn't mine, I've just tinkered around a bit with someone's to be easier (at least for me) to read ;)
Well, in my oppinion (and it's quite like czar's *bow*), if you wish to create some nice damaged effect, then you'll want to create more levels of damage to parts of the car that you draw. Personally, I think the most managable and upgradable way would be if you made a list class with pointers to classes that hold every image for a car (in TDirectDrawSurface), damaged or not, in a logical buildup. Then also create another class for the car instances, with pointers to the actual picture parts or theirs, and the drawing, hitchecking etc methods. And if the car took damage, the pointers to the pictures of the car would just change to a more damaged image. That should be very simple! :)
Also, for such a game I'd probably make a hitchecker so you'd have to add a list of vertexes or rectangles bounding the car, and the hitchecker would check if something's in that or not. Alot faster than pixel-by-pixel for sure, and pretty accurate, as cars mostly are pretty blocky, not overly bent or something. Well, at least you can cheat off some curves and that doesn't seem at all.
Powered by vBulletin® Version 4.2.5 Copyright © 2024 vBulletin Solutions Inc. All rights reserved.