2012-05-08 03:20:22 +00:00
|
|
|
using System;
|
|
|
|
using System.Collections.Generic;
|
|
|
|
using System.Linq;
|
|
|
|
using System.Text;
|
|
|
|
using System.Xml;
|
|
|
|
using System.Xml.Serialization;
|
|
|
|
using Microsoft.Xna.Framework;
|
|
|
|
using Microsoft.Xna.Framework.Graphics;
|
|
|
|
using Microsoft.Xna.Framework.Content;
|
|
|
|
using System.IO;
|
|
|
|
using FarseerPhysics.Dynamics;
|
|
|
|
using FarseerPhysics.Common;
|
|
|
|
using FarseerPhysics.SamplesFramework;
|
|
|
|
using FarseerPhysics.Factories;
|
|
|
|
|
|
|
|
namespace Axios.Engine.Glee2D
|
|
|
|
{
|
|
|
|
public partial class TextureItem : Item
|
|
|
|
{
|
|
|
|
/// <summary>
|
|
|
|
/// The item's rotation in radians.
|
|
|
|
/// </summary>
|
|
|
|
public float Rotation;
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
/// The item's scale factor.
|
|
|
|
/// </summary>
|
|
|
|
public float Scale;
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
/// The color to tint the item's texture with (use white for no tint).
|
|
|
|
/// </summary>
|
|
|
|
public Color TintColor;
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
/// If true, the texture is flipped horizontally when drawn.
|
|
|
|
/// </summary>
|
|
|
|
public bool FlipHorizontally;
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
/// If true, the texture is flipped vertically when drawn.
|
|
|
|
/// </summary>
|
|
|
|
public bool FlipVertically;
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
/// The path to the texture's filename (including the extension) relative to ContentRootFolder.
|
|
|
|
/// </summary>
|
|
|
|
public String texture_filename;
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
/// The texture_filename without extension. For using in Content.Load<Texture2D>().
|
|
|
|
/// </summary>
|
|
|
|
public String asset_name;
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
/// The XNA texture to be drawn. Can be loaded either from file (using "texture_filename")
|
|
|
|
/// or via the Content Pipeline (using "asset_name") - then you must ensure that the texture
|
|
|
|
/// exists as an asset in your project.
|
|
|
|
/// Loading is done in the Item's load() method.
|
|
|
|
/// </summary>
|
|
|
|
Texture2D texture;
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
/// The item's origin relative to the upper left corner of the texture. Usually the middle of the texture.
|
|
|
|
/// Used for placing and rotating the texture when drawn.
|
|
|
|
/// </summary>
|
|
|
|
public Vector2 Origin;
|
|
|
|
|
|
|
|
|
|
|
|
public TextureItem()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
/// Called by Level.FromFile(filename) on each Item after the deserialization process.
|
|
|
|
/// Loads all assets needed by the TextureItem, especially the Texture2D.
|
|
|
|
/// You must provide your own implementation. However, you can rely on all public fields being
|
|
|
|
/// filled by the level deserialization process.
|
|
|
|
/// </summary>
|
2012-05-12 22:45:03 +00:00
|
|
|
public override void load(ContentManager cm, World world, ref Dictionary<string, Texture2D> cache)
|
2012-05-08 03:20:22 +00:00
|
|
|
{
|
|
|
|
//throw new NotImplementedException();
|
|
|
|
|
|
|
|
//TODO: provide your own implementation of how a TextureItem loads its assets
|
|
|
|
//for example:
|
|
|
|
//this.texture = Texture2D.FromFile(<GraphicsDevice>, texture_filename);
|
|
|
|
//or by using the Content Pipeline:
|
2012-05-12 22:45:03 +00:00
|
|
|
if (!cache.ContainsKey(asset_name))
|
|
|
|
{
|
|
|
|
cache[asset_name] = cm.Load<Texture2D>(asset_name);
|
|
|
|
}
|
|
|
|
this.texture = cache[asset_name];
|
|
|
|
//this.texture = cm.Load<Texture2D>(asset_name);
|
2012-05-08 03:20:22 +00:00
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
public override void draw(SpriteBatch sb)
|
|
|
|
{
|
|
|
|
if (!Visible) return;
|
|
|
|
SpriteEffects effects = SpriteEffects.None;
|
|
|
|
if (FlipHorizontally) effects |= SpriteEffects.FlipHorizontally;
|
|
|
|
if (FlipVertically) effects |= SpriteEffects.FlipVertically;
|
|
|
|
sb.Draw(texture, Position, null, TintColor, Rotation, Origin, Scale, effects, 0);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|