Adding mono project
adding game services static class to make it easier to access graphics device adding axiosengine factory with extension to create texture from list of textures
This commit is contained in:
32
axios/Engine/AxiosEngineFactory.cs
Normal file
32
axios/Engine/AxiosEngineFactory.cs
Normal file
@@ -0,0 +1,32 @@
|
||||
using Microsoft.Xna.Framework;
|
||||
using Microsoft.Xna.Framework.Graphics;
|
||||
using System.Collections.Generic;
|
||||
|
||||
namespace Axios.Engine.Factories
|
||||
{
|
||||
public class Texture2DFactory
|
||||
{
|
||||
public static Texture2D CreateFromList(List<Texture2D> textures, int width, int height)
|
||||
{
|
||||
if (textures.Count <= 0)
|
||||
return (Texture2D)null;
|
||||
Texture2D texture2D1 = new Texture2D(textures[0].GraphicsDevice, width, height);
|
||||
Color[] data1 = new Color[width * height];
|
||||
texture2D1.GetData<Color>(data1);
|
||||
Rectangle rectangle = new Rectangle(0, 0, textures[0].Width, textures[0].Height);
|
||||
foreach (Texture2D texture2D2 in textures)
|
||||
{
|
||||
Color[] data2 = new Color[texture2D2.Width * texture2D2.Height];
|
||||
texture2D2.GetData<Color>(data2);
|
||||
texture2D1.SetData<Color>(0, new Rectangle?(rectangle), data2, 0, texture2D2.Width * texture2D2.Height);
|
||||
rectangle.X += texture2D2.Width;
|
||||
if (rectangle.X >= width)
|
||||
{
|
||||
rectangle.X = 0;
|
||||
rectangle.Y += texture2D2.Height;
|
||||
}
|
||||
}
|
||||
return texture2D1;
|
||||
}
|
||||
}
|
||||
}
|
@@ -78,7 +78,8 @@ namespace Axios.Engine
|
||||
this._uiobjects = new List<AxiosUIObject>();
|
||||
prevuiobj = null;
|
||||
prevuifocusobj = null;
|
||||
|
||||
GameServices.AddService<GraphicsDevice>(this.ScreenManager.GraphicsDevice);
|
||||
GameServices.AddService<ContentManager>(this.ScreenManager.Game.Content);
|
||||
}
|
||||
|
||||
public void LoadLevelFromStream(Stream s)
|
||||
|
39
axios/Engine/GameServices.cs
Normal file
39
axios/Engine/GameServices.cs
Normal file
@@ -0,0 +1,39 @@
|
||||
using Microsoft.Xna.Framework;
|
||||
|
||||
namespace Axios.Engine
|
||||
{
|
||||
public static class GameServices
|
||||
{
|
||||
private static GameServiceContainer container;
|
||||
private static object lockobj;
|
||||
public static GameServiceContainer Instance
|
||||
{
|
||||
get
|
||||
{
|
||||
lock (GameServices.lockobj)
|
||||
{
|
||||
if (container == null)
|
||||
{
|
||||
container = new GameServiceContainer();
|
||||
}
|
||||
}
|
||||
return container;
|
||||
}
|
||||
}
|
||||
|
||||
public static T GetService<T>()
|
||||
{
|
||||
return (T)Instance.GetService(typeof(T));
|
||||
}
|
||||
|
||||
public static void AddService<T>(T service)
|
||||
{
|
||||
Instance.AddService(typeof(T), service);
|
||||
}
|
||||
|
||||
public static void RemoveService<T>()
|
||||
{
|
||||
Instance.RemoveService(typeof(T));
|
||||
}
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user