mirror of
https://github.com/Memorix101/UnityXNA/
synced 2024-12-30 15:25:35 +01:00
89 lines
2.3 KiB
C#
89 lines
2.3 KiB
C#
|
#region File Description
|
|||
|
//-----------------------------------------------------------------------------
|
|||
|
// Animation.cs
|
|||
|
//
|
|||
|
// Microsoft XNA Community Game Platform
|
|||
|
// Copyright (C) Microsoft Corporation. All rights reserved.
|
|||
|
//-----------------------------------------------------------------------------
|
|||
|
#endregion
|
|||
|
|
|||
|
using System;
|
|||
|
using Microsoft.Xna.Framework.Graphics;
|
|||
|
|
|||
|
namespace Platformer
|
|||
|
{
|
|||
|
/// <summary>
|
|||
|
/// Represents an animated texture.
|
|||
|
/// </summary>
|
|||
|
/// <remarks>
|
|||
|
/// Currently, this class assumes that each frame of animation is
|
|||
|
/// as wide as each animation is tall. The number of frames in the
|
|||
|
/// animation are inferred from this.
|
|||
|
/// </remarks>
|
|||
|
class Animation
|
|||
|
{
|
|||
|
/// <summary>
|
|||
|
/// All frames in the animation arranged horizontally.
|
|||
|
/// </summary>
|
|||
|
public Texture2D Texture
|
|||
|
{
|
|||
|
get { return texture; }
|
|||
|
}
|
|||
|
Texture2D texture;
|
|||
|
|
|||
|
/// <summary>
|
|||
|
/// Duration of time to show each frame.
|
|||
|
/// </summary>
|
|||
|
public float FrameTime
|
|||
|
{
|
|||
|
get { return frameTime; }
|
|||
|
}
|
|||
|
float frameTime;
|
|||
|
|
|||
|
/// <summary>
|
|||
|
/// When the end of the animation is reached, should it
|
|||
|
/// continue playing from the beginning?
|
|||
|
/// </summary>
|
|||
|
public bool IsLooping
|
|||
|
{
|
|||
|
get { return isLooping; }
|
|||
|
}
|
|||
|
bool isLooping;
|
|||
|
|
|||
|
/// <summary>
|
|||
|
/// Gets the number of frames in the animation.
|
|||
|
/// </summary>
|
|||
|
public int FrameCount
|
|||
|
{
|
|||
|
get { return Texture.Width / FrameWidth; }
|
|||
|
}
|
|||
|
|
|||
|
/// <summary>
|
|||
|
/// Gets the width of a frame in the animation.
|
|||
|
/// </summary>
|
|||
|
public int FrameWidth
|
|||
|
{
|
|||
|
// Assume square frames.
|
|||
|
get { return Texture.Height; }
|
|||
|
}
|
|||
|
|
|||
|
/// <summary>
|
|||
|
/// Gets the height of a frame in the animation.
|
|||
|
/// </summary>
|
|||
|
public int FrameHeight
|
|||
|
{
|
|||
|
get { return Texture.Height; }
|
|||
|
}
|
|||
|
|
|||
|
/// <summary>
|
|||
|
/// Constructors a new animation.
|
|||
|
/// </summary>
|
|||
|
public Animation(Texture2D texture, float frameTime, bool isLooping)
|
|||
|
{
|
|||
|
this.texture = texture;
|
|||
|
this.frameTime = frameTime;
|
|||
|
this.isLooping = isLooping;
|
|||
|
}
|
|||
|
}
|
|||
|
}
|