SpriteDatabase creates sprites
This commit is contained in:
@ -4,11 +4,19 @@ using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using System.Drawing;
|
||||
using System.Resources;
|
||||
|
||||
|
||||
namespace SpriteLibrary
|
||||
{
|
||||
internal enum AnimationType { SpriteDefinition=0, Rotation=1, Mirror=2 }
|
||||
internal class AnimationInfo
|
||||
{
|
||||
public AnimationType FieldsToUse = AnimationType.SpriteDefinition;
|
||||
public int AnimationToUse = 0;
|
||||
public int RotationDegrees=0;
|
||||
public bool MirrorHorizontally = false;
|
||||
public bool MirrorVertically = false;
|
||||
public Point StartPoint = new Point(-1, -1);
|
||||
public string ImageName = "";
|
||||
public int Width = -1;
|
||||
@ -41,5 +49,45 @@ namespace SpriteLibrary
|
||||
{
|
||||
return SpriteDatabase.CloneByXMLSerializing<SpriteInfo>(this);
|
||||
}
|
||||
|
||||
public Sprite CreateSprite(SpriteController ControllerToUse, SpriteDatabase TheDatabaseToUse)
|
||||
{
|
||||
Sprite DestSprite = null;
|
||||
for (int index = 0; index < Animations.Count; index++)
|
||||
{
|
||||
AnimationInfo CurrentAnimation = Animations[index];
|
||||
Image myImage = TheDatabaseToUse.GetImageFromName(CurrentAnimation.ImageName, true);
|
||||
if (myImage == null) return null; //break out if we do not have the image defined for this
|
||||
AnimationType AT = CurrentAnimation.FieldsToUse;
|
||||
if (index == 0) AT = AnimationType.SpriteDefinition; //the first one MUST be this.
|
||||
switch(AT)
|
||||
{
|
||||
case AnimationType.SpriteDefinition:
|
||||
if(DestSprite == null)//Creating the sprite from scratch
|
||||
{
|
||||
DestSprite = new Sprite(CurrentAnimation.StartPoint, ControllerToUse, myImage, CurrentAnimation.Width, CurrentAnimation.Height, CurrentAnimation.AnimSpeed, CurrentAnimation.NumFrames);
|
||||
}
|
||||
else
|
||||
{
|
||||
DestSprite.AddAnimation(CurrentAnimation.StartPoint, myImage, CurrentAnimation.Width, CurrentAnimation.Height, CurrentAnimation.AnimSpeed, CurrentAnimation.NumFrames);
|
||||
}
|
||||
break;
|
||||
case AnimationType.Rotation:
|
||||
DestSprite.AddAnimation(CurrentAnimation.AnimationToUse, CurrentAnimation.RotationDegrees);
|
||||
break;
|
||||
case AnimationType.Mirror:
|
||||
DestSprite.AddAnimation(CurrentAnimation.AnimationToUse, CurrentAnimation.MirrorHorizontally,CurrentAnimation.MirrorVertically);
|
||||
break;
|
||||
}
|
||||
}
|
||||
int sizepercent = ViewPercent;
|
||||
if (sizepercent < 5) sizepercent = 100;
|
||||
if (sizepercent > 300) sizepercent = 100;
|
||||
double delta = (double)sizepercent / 100.0; //turn it into a double, and into something we can multiply.
|
||||
DestSprite.SetSize(new Size((int)(DestSprite.GetSize.Width * delta), (int)(DestSprite.GetSize.Height * delta)));
|
||||
DestSprite.SetName(SpriteName);
|
||||
//We have created a new sprite. Now, return a duplicate of that sprite.
|
||||
return DestSprite;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user