Skip to content

Instantly share code, notes, and snippets.

@demonixis
Created May 21, 2012 06:12
Show Gist options
  • Save demonixis/2760756 to your computer and use it in GitHub Desktop.
Save demonixis/2760756 to your computer and use it in GitHub Desktop.
YNA Framework - Create custom Sprite with no texture
using System;
using System.Collections.Generic;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics;
using Microsoft.Xna.Framework.Input;
using Yna;
using Yna.Display;
namespace Yna.Test
{
public class RawSpriteState : Yna.YnState
{
Sprite background;
Sprite player;
public RawSpriteState() : base ()
{
}
public override void Initialize()
{
base.Initialize();
background = new Sprite(Vector2.Zero, "2d//green-world");
player = new Sprite(new Rectangle(0, 0, 50, 50), Color.Azure);
player.ForceInsideOutsideScreen = true;
Add(background);
Add(player);
}
public override void Update(GameTime gameTime)
{
base.Update(gameTime);
if (YnG.Keys.Escape)
YnG.Quit();
if (YnG.Keys.Up)
player.Y = player.Y - 1 * gameTime.ElapsedGameTime.Milliseconds;
if (YnG.Keys.Down)
player.Y = player.Y + 1 * gameTime.ElapsedGameTime.Milliseconds;
if (YnG.Keys.Left)
player.X = player.X - 1 * gameTime.ElapsedGameTime.Milliseconds;
if (YnG.Keys.Right)
player.X = player.X + 1 * gameTime.ElapsedGameTime.Milliseconds;
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment