Last active
December 16, 2016 04:50
-
-
Save prime31/79e0b404459dd26f7873a9b855de5bcc to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using Microsoft.Xna.Framework; | |
using Microsoft.Xna.Framework.Graphics; | |
using Microsoft.Xna.Framework.Input; | |
using Nez; | |
namespace TheWall | |
{ | |
public class Game2 : Game | |
{ | |
GraphicsDeviceManager _graphics; | |
SpriteBatch _spriteBatch; | |
Texture2D _moonTexture; | |
RenderTarget2D _renderTarget; | |
RenderTarget2D _renderTarget2; | |
public Game2() | |
{ | |
_graphics = new GraphicsDeviceManager( this ); | |
Content.RootDirectory = "Content"; | |
IsMouseVisible = true; | |
} | |
protected override void LoadContent() | |
{ | |
_spriteBatch = new SpriteBatch( GraphicsDevice ); | |
_moonTexture = Content.Load<Texture2D>( "moon.png" ); | |
} | |
protected override void Update( GameTime gameTime ) | |
{ | |
Input.update(); | |
if( Input.isKeyDown( Keys.A ) ) | |
{ | |
_renderTarget = new RenderTarget2D( _graphics.GraphicsDevice, 128, 128, false, SurfaceFormat.Color, DepthFormat.None, 0, RenderTargetUsage.PreserveContents ); | |
renderMoon( _renderTarget, Color.Red ); | |
} | |
if( Input.isKeyDown( Keys.B ) ) | |
{ | |
_renderTarget2 = new RenderTarget2D( _graphics.GraphicsDevice, 128, 128, false, SurfaceFormat.Color, DepthFormat.None, 0, RenderTargetUsage.PreserveContents ); | |
renderMoon( _renderTarget2, Color.Blue ); | |
} | |
base.Update( gameTime ); | |
} | |
void renderMoon( RenderTarget2D target, Color color ) | |
{ | |
_graphics.GraphicsDevice.SetRenderTarget( target ); | |
_spriteBatch.Begin( SpriteSortMode.Immediate, BlendState.AlphaBlend ); | |
_spriteBatch.Draw( _moonTexture, Vector2.Zero, color ); | |
_spriteBatch.End(); | |
_graphics.GraphicsDevice.SetRenderTarget( null ); | |
} | |
protected override void Draw( GameTime gameTime ) | |
{ | |
GraphicsDevice.Clear( Color.CornflowerBlue ); | |
_spriteBatch.Begin( SpriteSortMode.Immediate, BlendState.AlphaBlend ); | |
if( _renderTarget != null ) | |
_spriteBatch.Draw( _renderTarget, new Vector2( 150, 150 ), Color.White ); | |
if( _renderTarget2 != null ) | |
_spriteBatch.Draw( _renderTarget2, new Vector2( 0, 0 ), Color.White ); | |
_spriteBatch.End(); | |
base.Draw( gameTime ); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment