Modfying draw method in AxiosGameScreen to draw Gleed2D textures
This commit is contained in:
parent
d14f65d779
commit
f57659e2e1
@ -172,6 +172,7 @@
|
|||||||
<Compile Include="Engine\File\AxiosIsolatedFile.cs" />
|
<Compile Include="Engine\File\AxiosIsolatedFile.cs" />
|
||||||
<Compile Include="Engine\File\AxiosRegularFile.cs" />
|
<Compile Include="Engine\File\AxiosRegularFile.cs" />
|
||||||
<Compile Include="Engine\File\AxiosTitleFile.cs" />
|
<Compile Include="Engine\File\AxiosTitleFile.cs" />
|
||||||
|
<Compile Include="Engine\Gleed2D\Camera.cs" />
|
||||||
<Compile Include="Engine\Gleed2D\CircleItem.cs" />
|
<Compile Include="Engine\Gleed2D\CircleItem.cs" />
|
||||||
<Compile Include="Engine\Gleed2D\CustomProperty.cs" />
|
<Compile Include="Engine\Gleed2D\CustomProperty.cs" />
|
||||||
<Compile Include="Engine\Gleed2D\Item.cs" />
|
<Compile Include="Engine\Gleed2D\Item.cs" />
|
||||||
|
@ -215,6 +215,7 @@
|
|||||||
<Compile Include="Engine\File\AxiosIsolatedFile.cs" />
|
<Compile Include="Engine\File\AxiosIsolatedFile.cs" />
|
||||||
<Compile Include="Engine\File\AxiosRegularFile.cs" />
|
<Compile Include="Engine\File\AxiosRegularFile.cs" />
|
||||||
<Compile Include="Engine\File\AxiosTitleFile.cs" />
|
<Compile Include="Engine\File\AxiosTitleFile.cs" />
|
||||||
|
<Compile Include="Engine\Gleed2D\Camera.cs" />
|
||||||
<Compile Include="Engine\Gleed2D\CircleItem.cs" />
|
<Compile Include="Engine\Gleed2D\CircleItem.cs" />
|
||||||
<Compile Include="Engine\Gleed2D\CustomProperty.cs" />
|
<Compile Include="Engine\Gleed2D\CustomProperty.cs" />
|
||||||
<Compile Include="Engine\Gleed2D\Item.cs" />
|
<Compile Include="Engine\Gleed2D\Item.cs" />
|
||||||
|
@ -165,6 +165,7 @@
|
|||||||
<Compile Include="Engine\File\AxiosIsolatedFile.cs" />
|
<Compile Include="Engine\File\AxiosIsolatedFile.cs" />
|
||||||
<Compile Include="Engine\File\AxiosRegularFile.cs" />
|
<Compile Include="Engine\File\AxiosRegularFile.cs" />
|
||||||
<Compile Include="Engine\File\AxiosTitleFile.cs" />
|
<Compile Include="Engine\File\AxiosTitleFile.cs" />
|
||||||
|
<Compile Include="Engine\Gleed2D\Camera.cs" />
|
||||||
<Compile Include="Engine\Gleed2D\CircleItem.cs" />
|
<Compile Include="Engine\Gleed2D\CircleItem.cs" />
|
||||||
<Compile Include="Engine\Gleed2D\CustomProperty.cs" />
|
<Compile Include="Engine\Gleed2D\CustomProperty.cs" />
|
||||||
<Compile Include="Engine\Gleed2D\Item.cs" />
|
<Compile Include="Engine\Gleed2D\Item.cs" />
|
||||||
|
@ -74,6 +74,8 @@
|
|||||||
* - Adding a cache for loading in textures for Gleed2D
|
* - Adding a cache for loading in textures for Gleed2D
|
||||||
* - Adding GetStream(FileMode) to get the stream of a file
|
* - Adding GetStream(FileMode) to get the stream of a file
|
||||||
* - Adding support to load a Gleed2D level from a stream
|
* - Adding support to load a Gleed2D level from a stream
|
||||||
|
* - Adjusting units for Gleed2D position for Farseer bodies
|
||||||
|
* - Modfying draw method in AxiosGameScreen to draw Gleed2D textures
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
@ -11,6 +11,7 @@ using Microsoft.Xna.Framework;
|
|||||||
using Microsoft.Xna.Framework.Content;
|
using Microsoft.Xna.Framework.Content;
|
||||||
using Microsoft.Xna.Framework.Graphics;
|
using Microsoft.Xna.Framework.Graphics;
|
||||||
using GameStateManagement;
|
using GameStateManagement;
|
||||||
|
using Axios.Engine.Gleed2D;
|
||||||
|
|
||||||
namespace Axios.Engine
|
namespace Axios.Engine
|
||||||
{
|
{
|
||||||
@ -36,6 +37,10 @@ namespace Axios.Engine
|
|||||||
private AxiosUIObject prevuiobj;
|
private AxiosUIObject prevuiobj;
|
||||||
private AxiosUIObject prevuifocusobj;
|
private AxiosUIObject prevuifocusobj;
|
||||||
|
|
||||||
|
protected Level Level;
|
||||||
|
|
||||||
|
private Camera camera;
|
||||||
|
|
||||||
public AxiosGameScreen()
|
public AxiosGameScreen()
|
||||||
: base()
|
: base()
|
||||||
{
|
{
|
||||||
@ -46,6 +51,7 @@ namespace Axios.Engine
|
|||||||
this._uiobjects = new List<AxiosUIObject>();
|
this._uiobjects = new List<AxiosUIObject>();
|
||||||
prevuiobj = null;
|
prevuiobj = null;
|
||||||
prevuifocusobj = null;
|
prevuifocusobj = null;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/*public void AddGameObject<T>(T gameobject)
|
/*public void AddGameObject<T>(T gameobject)
|
||||||
@ -163,6 +169,7 @@ namespace Axios.Engine
|
|||||||
public override void Activate(bool instancePreserved)
|
public override void Activate(bool instancePreserved)
|
||||||
{
|
{
|
||||||
base.Activate(instancePreserved);
|
base.Activate(instancePreserved);
|
||||||
|
|
||||||
|
|
||||||
#if DEBUG
|
#if DEBUG
|
||||||
if (!Axios.Settings.ScreenSaver)
|
if (!Axios.Settings.ScreenSaver)
|
||||||
@ -171,17 +178,36 @@ namespace Axios.Engine
|
|||||||
this.DebugSpriteFont = man.Load<SpriteFont>(this.DebugTextFont);
|
this.DebugSpriteFont = man.Load<SpriteFont>(this.DebugTextFont);
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
camera = new Camera(ScreenManager.GraphicsDevice.Viewport.Width, ScreenManager.GraphicsDevice.Viewport.Height);
|
||||||
}
|
}
|
||||||
|
|
||||||
public override void Draw(GameTime gameTime)
|
public override void Draw(GameTime gameTime)
|
||||||
{
|
{
|
||||||
base.Draw(gameTime);
|
base.Draw(gameTime);
|
||||||
|
|
||||||
|
if (Level != null)
|
||||||
|
{
|
||||||
|
foreach (Layer layer in Level.Layers)
|
||||||
|
{
|
||||||
|
Vector2 oldcameraposition = camera.Position;
|
||||||
|
camera.Position *= layer.ScrollSpeed;
|
||||||
|
|
||||||
|
ScreenManager.SpriteBatch.Begin(0, null, null, null, null, null, camera.matrix);
|
||||||
|
layer.draw(ScreenManager.SpriteBatch);
|
||||||
|
ScreenManager.SpriteBatch.End();
|
||||||
|
|
||||||
|
camera.Position = oldcameraposition;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
foreach (AxiosGameObject g in (from x in (from i in _gameObjects where i is IDrawableAxiosGameObject select (IDrawableAxiosGameObject)i) orderby x.DrawOrder select x))
|
foreach (AxiosGameObject g in (from x in (from i in _gameObjects where i is IDrawableAxiosGameObject select (IDrawableAxiosGameObject)i) orderby x.DrawOrder select x))
|
||||||
((IDrawableAxiosGameObject)g).Draw(this, gameTime);
|
((IDrawableAxiosGameObject)g).Draw(this, gameTime);
|
||||||
|
|
||||||
foreach(AxiosUIObject g in (from x in _uiobjects orderby x.DrawOrder select x))
|
foreach(AxiosUIObject g in (from x in _uiobjects orderby x.DrawOrder select x))
|
||||||
((IDrawableAxiosGameObject)g).Draw(this, gameTime);
|
((IDrawableAxiosGameObject)g).Draw(this, gameTime);
|
||||||
|
|
||||||
|
//System.Diagnostics.Debugger.Break();
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public override void Update(GameTime gameTime, bool otherScreenHasFocus, bool coveredByOtherScreen)
|
public override void Update(GameTime gameTime, bool otherScreenHasFocus, bool coveredByOtherScreen)
|
||||||
|
82
axios/Engine/Gleed2D/Camera.cs
Normal file
82
axios/Engine/Gleed2D/Camera.cs
Normal file
@ -0,0 +1,82 @@
|
|||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Text;
|
||||||
|
using Microsoft.Xna.Framework;
|
||||||
|
|
||||||
|
namespace Axios.Engine.Gleed2D
|
||||||
|
{
|
||||||
|
public class Camera
|
||||||
|
{
|
||||||
|
Vector2 position;
|
||||||
|
public Vector2 Position
|
||||||
|
{
|
||||||
|
get
|
||||||
|
{
|
||||||
|
return position;
|
||||||
|
}
|
||||||
|
set
|
||||||
|
{
|
||||||
|
position = value;
|
||||||
|
updatematrix();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
float rotation;
|
||||||
|
public float Rotation
|
||||||
|
{
|
||||||
|
get
|
||||||
|
{
|
||||||
|
return rotation;
|
||||||
|
}
|
||||||
|
set
|
||||||
|
{
|
||||||
|
rotation = value;
|
||||||
|
updatematrix();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
float scale;
|
||||||
|
public float Scale
|
||||||
|
{
|
||||||
|
get
|
||||||
|
{
|
||||||
|
return scale;
|
||||||
|
}
|
||||||
|
set
|
||||||
|
{
|
||||||
|
scale = value;
|
||||||
|
updatematrix();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public Matrix matrix;
|
||||||
|
Vector2 viewport; //width and height of the viewport
|
||||||
|
|
||||||
|
|
||||||
|
public Camera(float width, float height)
|
||||||
|
{
|
||||||
|
position = Vector2.Zero;
|
||||||
|
rotation = 0;
|
||||||
|
scale = 1.0f;
|
||||||
|
viewport = new Vector2(width, height);
|
||||||
|
updatematrix();
|
||||||
|
}
|
||||||
|
|
||||||
|
void updatematrix()
|
||||||
|
{
|
||||||
|
matrix = Matrix.CreateTranslation(-position.X, -position.Y, 0.0f) *
|
||||||
|
Matrix.CreateRotationZ(rotation) *
|
||||||
|
Matrix.CreateScale(scale) *
|
||||||
|
Matrix.CreateTranslation(viewport.X / 2, viewport.Y / 2, 0.0f);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void updateviewport(float width, float height)
|
||||||
|
{
|
||||||
|
viewport.X = width;
|
||||||
|
viewport.Y = height;
|
||||||
|
updatematrix();
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
@ -28,7 +28,7 @@ namespace Axios.Engine.Gleed2D
|
|||||||
base.load(cm, world, ref cache);
|
base.load(cm, world, ref cache);
|
||||||
|
|
||||||
_body = BodyFactory.CreateCircle(world, Radius, 1f);
|
_body = BodyFactory.CreateCircle(world, Radius, 1f);
|
||||||
_body.Position = Position;
|
_body.Position = ConvertUnits.ToSimUnits(Position);
|
||||||
_body.UserData = this;
|
_body.UserData = this;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -35,7 +35,7 @@ namespace Axios.Engine.Gleed2D
|
|||||||
v.Add(new Vector2(ConvertUnits.ToSimUnits(vec.X), ConvertUnits.ToSimUnits(vec.Y)));
|
v.Add(new Vector2(ConvertUnits.ToSimUnits(vec.X), ConvertUnits.ToSimUnits(vec.Y)));
|
||||||
|
|
||||||
_body = BodyFactory.CreateLoopShape(world, v);
|
_body = BodyFactory.CreateLoopShape(world, v);
|
||||||
_body.Position = this.Position;
|
_body.Position = ConvertUnits.ToSimUnits(this.Position);
|
||||||
_body.UserData = this;
|
_body.UserData = this;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -29,7 +29,7 @@ namespace Axios.Engine.Gleed2D
|
|||||||
base.load(cm, world, ref cache);
|
base.load(cm, world, ref cache);
|
||||||
|
|
||||||
_body = BodyFactory.CreateRectangle(world, Width, Height, 1f);
|
_body = BodyFactory.CreateRectangle(world, Width, Height, 1f);
|
||||||
_body.Position = Position;
|
_body.Position = ConvertUnits.ToSimUnits(Position);
|
||||||
_body.UserData = this;
|
_body.UserData = this;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -25,7 +25,7 @@ namespace Axios.Engine.Gleed2D
|
|||||||
/// <summary>
|
/// <summary>
|
||||||
/// The item's scale factor.
|
/// The item's scale factor.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public float Scale;
|
public Vector2 Scale;
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// The color to tint the item's texture with (use white for no tint).
|
/// The color to tint the item's texture with (use white for no tint).
|
||||||
|
Loading…
Reference in New Issue
Block a user