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\AxiosRegularFile.cs" />
|
||||
<Compile Include="Engine\File\AxiosTitleFile.cs" />
|
||||
<Compile Include="Engine\Gleed2D\Camera.cs" />
|
||||
<Compile Include="Engine\Gleed2D\CircleItem.cs" />
|
||||
<Compile Include="Engine\Gleed2D\CustomProperty.cs" />
|
||||
<Compile Include="Engine\Gleed2D\Item.cs" />
|
||||
|
@ -215,6 +215,7 @@
|
||||
<Compile Include="Engine\File\AxiosIsolatedFile.cs" />
|
||||
<Compile Include="Engine\File\AxiosRegularFile.cs" />
|
||||
<Compile Include="Engine\File\AxiosTitleFile.cs" />
|
||||
<Compile Include="Engine\Gleed2D\Camera.cs" />
|
||||
<Compile Include="Engine\Gleed2D\CircleItem.cs" />
|
||||
<Compile Include="Engine\Gleed2D\CustomProperty.cs" />
|
||||
<Compile Include="Engine\Gleed2D\Item.cs" />
|
||||
|
@ -165,6 +165,7 @@
|
||||
<Compile Include="Engine\File\AxiosIsolatedFile.cs" />
|
||||
<Compile Include="Engine\File\AxiosRegularFile.cs" />
|
||||
<Compile Include="Engine\File\AxiosTitleFile.cs" />
|
||||
<Compile Include="Engine\Gleed2D\Camera.cs" />
|
||||
<Compile Include="Engine\Gleed2D\CircleItem.cs" />
|
||||
<Compile Include="Engine\Gleed2D\CustomProperty.cs" />
|
||||
<Compile Include="Engine\Gleed2D\Item.cs" />
|
||||
|
@ -74,6 +74,8 @@
|
||||
* - Adding a cache for loading in textures for Gleed2D
|
||||
* - Adding GetStream(FileMode) to get the stream of a file
|
||||
* - 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.Graphics;
|
||||
using GameStateManagement;
|
||||
using Axios.Engine.Gleed2D;
|
||||
|
||||
namespace Axios.Engine
|
||||
{
|
||||
@ -36,6 +37,10 @@ namespace Axios.Engine
|
||||
private AxiosUIObject prevuiobj;
|
||||
private AxiosUIObject prevuifocusobj;
|
||||
|
||||
protected Level Level;
|
||||
|
||||
private Camera camera;
|
||||
|
||||
public AxiosGameScreen()
|
||||
: base()
|
||||
{
|
||||
@ -46,6 +51,7 @@ namespace Axios.Engine
|
||||
this._uiobjects = new List<AxiosUIObject>();
|
||||
prevuiobj = null;
|
||||
prevuifocusobj = null;
|
||||
|
||||
}
|
||||
|
||||
/*public void AddGameObject<T>(T gameobject)
|
||||
@ -164,6 +170,7 @@ namespace Axios.Engine
|
||||
{
|
||||
base.Activate(instancePreserved);
|
||||
|
||||
|
||||
#if DEBUG
|
||||
if (!Axios.Settings.ScreenSaver)
|
||||
{
|
||||
@ -171,17 +178,36 @@ namespace Axios.Engine
|
||||
this.DebugSpriteFont = man.Load<SpriteFont>(this.DebugTextFont);
|
||||
}
|
||||
#endif
|
||||
camera = new Camera(ScreenManager.GraphicsDevice.Viewport.Width, ScreenManager.GraphicsDevice.Viewport.Height);
|
||||
}
|
||||
|
||||
public override void Draw(GameTime 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))
|
||||
((IDrawableAxiosGameObject)g).Draw(this, gameTime);
|
||||
|
||||
foreach(AxiosUIObject g in (from x in _uiobjects orderby x.DrawOrder select x))
|
||||
((IDrawableAxiosGameObject)g).Draw(this, gameTime);
|
||||
|
||||
//System.Diagnostics.Debugger.Break();
|
||||
|
||||
}
|
||||
|
||||
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);
|
||||
|
||||
_body = BodyFactory.CreateCircle(world, Radius, 1f);
|
||||
_body.Position = Position;
|
||||
_body.Position = ConvertUnits.ToSimUnits(Position);
|
||||
_body.UserData = this;
|
||||
}
|
||||
|
||||
|
@ -35,7 +35,7 @@ namespace Axios.Engine.Gleed2D
|
||||
v.Add(new Vector2(ConvertUnits.ToSimUnits(vec.X), ConvertUnits.ToSimUnits(vec.Y)));
|
||||
|
||||
_body = BodyFactory.CreateLoopShape(world, v);
|
||||
_body.Position = this.Position;
|
||||
_body.Position = ConvertUnits.ToSimUnits(this.Position);
|
||||
_body.UserData = this;
|
||||
}
|
||||
|
||||
|
@ -29,7 +29,7 @@ namespace Axios.Engine.Gleed2D
|
||||
base.load(cm, world, ref cache);
|
||||
|
||||
_body = BodyFactory.CreateRectangle(world, Width, Height, 1f);
|
||||
_body.Position = Position;
|
||||
_body.Position = ConvertUnits.ToSimUnits(Position);
|
||||
_body.UserData = this;
|
||||
}
|
||||
}
|
||||
|
@ -25,7 +25,7 @@ namespace Axios.Engine.Gleed2D
|
||||
/// <summary>
|
||||
/// The item's scale factor.
|
||||
/// </summary>
|
||||
public float Scale;
|
||||
public Vector2 Scale;
|
||||
|
||||
/// <summary>
|
||||
/// The color to tint the item's texture with (use white for no tint).
|
||||
|
Loading…
Reference in New Issue
Block a user