Browse Source

add player sprite with looping animation

GitOrigin-RevId: 2e77393290
master
Colin McMillen 4 years ago
parent
commit
fb50667459
  1. 19
      Jumpy.Shared/JumpyGame.cs

19
Jumpy.Shared/JumpyGame.cs

@ -8,6 +8,7 @@ namespace Jumpy {
public class JumpyGame : Game {
GraphicsDeviceManager graphics;
SpriteBatch spriteBatch;
Texture2D playerTexture;
SpriteFont font;
KeyboardInput keyboardInput = new KeyboardInput();
bool fullScreen = false;
@ -24,9 +25,6 @@ namespace Jumpy {
display = (IDisplay) Services.GetService(typeof(IDisplay));
display.Initialize(Window, graphics);
display.SetFullScreen(fullScreen);
// TODO: something like this for mobile devices?
// graphics.SupportedOrientations =
// DisplayOrientation.LandscapeLeft | DisplayOrientation.LandscapeRight;
base.Initialize();
}
@ -35,6 +33,7 @@ namespace Jumpy {
protected override void LoadContent() {
spriteBatch = new SpriteBatch(GraphicsDevice);
font = Content.Load<SpriteFont>("font");
playerTexture = Content.Load<Texture2D>("player");
}
// Called once per game. Unloads all game content.
@ -64,10 +63,22 @@ namespace Jumpy {
protected override void Draw(GameTime gameTime) {
GraphicsDevice.Clear(Color.CornflowerBlue);
int frameNum = gameTime.TotalGameTime.Milliseconds / 250;
if (frameNum == 3) {
frameNum = 1;
}
int sourceX = 144 * frameNum + 144 * 6;
int sourceY = 144 * 0;
Rectangle source = new Rectangle(sourceX, sourceY, 144, 144);
// Vector2 position = new Vector2(0, 0);
Vector2 position = new Vector2(100, 100);
Vector2 spriteCenter = new Vector2(144 / 2, 144 / 2);
spriteBatch.Begin();
spriteBatch.DrawString(font, "hello world", new Vector2(100, 100), Color.Black);
spriteBatch.Draw(playerTexture, position, source, Color.White, 0f, spriteCenter, Vector2.One, SpriteEffects.FlipHorizontally, 0f);
spriteBatch.End();
// spriteBatch.DrawString(font, "hello world", new Vector2(100, 100), Color.Black);
base.Draw(gameTime);
}
}

Loading…
Cancel
Save