mirror of
https://github.com/AlexMacocian/MonoGame.Extended.git
synced 2026-07-15 15:09:29 +00:00
camera with background
This commit is contained in:
@@ -24,3 +24,14 @@
|
||||
/processorParam:TextureFormat=Color
|
||||
/build:shadedDark42.png
|
||||
|
||||
#begin hills.png
|
||||
/importer:TextureImporter
|
||||
/processor:TextureProcessor
|
||||
/processorParam:ColorKeyColor=255,0,255,255
|
||||
/processorParam:ColorKeyEnabled=True
|
||||
/processorParam:GenerateMipmaps=False
|
||||
/processorParam:PremultiplyAlpha=True
|
||||
/processorParam:ResizeToPowerOfTwo=False
|
||||
/processorParam:TextureFormat=Color
|
||||
/build:hills.png
|
||||
|
||||
|
||||
Binary file not shown.
|
After Width: | Height: | Size: 118 KiB |
@@ -0,0 +1,3 @@
|
||||
## [Simple Hills Background](https://www.gamedevmarket.net/asset/simple-hills-background-1030/)
|
||||
|
||||
hills.png
|
||||
@@ -11,6 +11,7 @@ namespace Game1
|
||||
private SpriteBatch _spriteBatch;
|
||||
private TextureRegion2D _textureRegion;
|
||||
private OrthographicCamera _camera;
|
||||
private Texture2D _backgroundTexture;
|
||||
|
||||
public Game1()
|
||||
{
|
||||
@@ -21,13 +22,17 @@ namespace Game1
|
||||
|
||||
protected override void Initialize()
|
||||
{
|
||||
_camera = new OrthographicCamera();
|
||||
_camera = new OrthographicCamera
|
||||
{
|
||||
Origin = new Vector2(GraphicsDevice.Viewport.Width / 2f, GraphicsDevice.Viewport.Height / 2f)
|
||||
};
|
||||
base.Initialize();
|
||||
}
|
||||
|
||||
protected override void LoadContent()
|
||||
{
|
||||
_spriteBatch = new SpriteBatch(GraphicsDevice);
|
||||
_backgroundTexture = Content.Load<Texture2D>("hills");
|
||||
|
||||
var texture = Content.Load<Texture2D>("shadedDark42");
|
||||
_textureRegion = new TextureRegion2D(texture, 5, 5, 32, 32);
|
||||
@@ -39,14 +44,33 @@ namespace Game1
|
||||
|
||||
protected override void Update(GameTime gameTime)
|
||||
{
|
||||
var deltaTime = (float) gameTime.ElapsedGameTime.TotalSeconds;
|
||||
var keyboardState = Keyboard.GetState();
|
||||
var gamePadState = GamePad.GetState(PlayerIndex.One);
|
||||
|
||||
if (gamePadState.Buttons.Back == ButtonState.Pressed || keyboardState.IsKeyDown(Keys.Escape))
|
||||
Exit();
|
||||
|
||||
var up = new Vector2(0, -250);
|
||||
var right = new Vector2(250, 0);
|
||||
|
||||
if (keyboardState.IsKeyDown(Keys.Q))
|
||||
_camera.Rotation -= deltaTime;
|
||||
|
||||
if (keyboardState.IsKeyDown(Keys.W))
|
||||
_camera.Rotation += deltaTime;
|
||||
|
||||
if (keyboardState.IsKeyDown(Keys.Up))
|
||||
_camera.Position += new Vector2(-1, -1);
|
||||
_camera.Position += up * deltaTime;
|
||||
|
||||
if (keyboardState.IsKeyDown(Keys.Down))
|
||||
_camera.Position += -up * deltaTime;
|
||||
|
||||
if (keyboardState.IsKeyDown(Keys.Left))
|
||||
_camera.Position += -right * deltaTime;
|
||||
|
||||
if (keyboardState.IsKeyDown(Keys.Right))
|
||||
_camera.Position += right * deltaTime;
|
||||
|
||||
base.Update(gameTime);
|
||||
}
|
||||
@@ -57,6 +81,7 @@ namespace Game1
|
||||
|
||||
var transformMatrix = _camera.CalculateTransformMatrix();
|
||||
_spriteBatch.Begin(transformMatrix: transformMatrix);
|
||||
_spriteBatch.Draw(_backgroundTexture, Vector2.Zero);
|
||||
_spriteBatch.Draw(_textureRegion, Vector2.Zero, Color.White);
|
||||
_spriteBatch.End();
|
||||
|
||||
|
||||
@@ -55,6 +55,7 @@
|
||||
<Reference Include="System.Xml" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<None Include="Content\read-me.md" />
|
||||
<Content Include="Icon.ico" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
|
||||
@@ -1,5 +1,4 @@
|
||||
using Microsoft.Xna.Framework;
|
||||
using Microsoft.Xna.Framework.Graphics;
|
||||
|
||||
namespace MonoGame.Extended
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user