Archived

This topic is now archived and is closed to further replies.

DirectDraw Animation in C#

This topic is 4987 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

im trying to add animation to my spriteobject class, which is were i draw sprites and bitmaps from. the animation has all the frames in one picture. However when i try it out the entire picture is displayed but in the frames size. Any help woudl be appreciated this is my SpriteObject class: public enum SpriteType { SOLID = 0, TRANSPARENT = 1 } public class SpriteObject { //the objects surface description protected SurfaceDescription desc; // the objects surface protected Surface sprite; // the objects frames protected Rectangle[] frames; // the number of frames in the object protected int nFrames; //current frame being displayed protected int currentframe; //frames height protected int frameHeight; //frames width protected int frameWidth; //path to where the sprite is located protected string pathString; // Target Device protected Device targetDevice; //the objects enum saying whether its transparent or solid protected SpriteType objectType; //X position of the sprite protected int xPosition; //the Y position of the sprite protected int yPosition; public SpriteObject(string PathString, SpriteType ObjectType, int NFrames, int FrameWidth, int FrameHeight, int XPosition, int YPosition, Device TargetDevice) { nFrames = NFrames; pathString = PathString; frameWidth = FrameWidth; frameHeight = FrameHeight; targetDevice = TargetDevice; objectType = ObjectType; xPosition = XPosition; yPosition = YPosition; frames = new Rectangle[nFrames]; InitDisplay(); } //creates the sprite surface protected void InitDisplay() { desc = new SurfaceDescription(); desc.SurfaceCaps.OffScreenPlain = true; desc.Width = frameWidth; desc.Height = frameHeight; sprite = new Surface(pathString, desc, targetDevice); for(int i = 0; i = new Rectangle(pt,new Size(frameWidth, frameHeight)); } switch(objectType) { case SpriteType.TRANSPARENT: // Create a new color key and choose color = black; ColorKey tempKey = new ColorKey(); tempKey.ColorSpaceHighValue = 0; tempKey.ColorSpaceLowValue = 0; // Assign the color key to the surface sprite.SetColorKey(ColorKeyFlags.SourceDraw, tempKey); break; } } // draws the sprite public void DrawSprite(Surface TargetSurface) { if(this.objectType == SpriteType.TRANSPARENT) TargetSurface.DrawFast(xPosition,yPosition, sprite, frames[currentframe], DrawFastFlags.SourceColorKey | DrawFastFlags.Wait); else TargetSurface.DrawFast(xPosition,yPosition, sprite, frames[currentframe], DrawFastFlags.NoColorKey |DrawFastFlags.Wait); } } }

Share this post


Link to post
Share on other sites