Skip to content

Instantly share code, notes, and snippets.

@Alan-FGR Alan-FGR/Program.cs
Created Sep 1, 2017

Embed
What would you like to do?
Multiple Scenes on Nez.FNA
// YOU NEED MY MULTISCENE BRANCH: https://github.com/Alan-FGR/Nez/tree/multiscene
class TestScene : MScene
{
public override void initialize()
{
base.initialize();
setDesignResolution(640,360,SceneResolutionPolicy.ShowAll);
renderer = new DefaultRenderer();
renderer.renderTexture = new RenderTexture(640,360);
addRenderer(renderer);
Physics.gravity = Vector2.Zero;
var p = createEntity("player");
p.addComponent(new PlayerController());
p.position = Vector2.One * 150;
}
}
class TestUIScene : MScene, IFinalRenderDelegate
{
public override void initialize()
{
base.initialize();
setDesignResolution(640,360,SceneResolutionPolicy.ShowAll);
renderer = new DefaultRenderer();
renderer.renderTexture = new RenderTexture(640,360);
addRenderer(renderer);
var canvas = createEntity("ui").addComponent(new UICanvas());
var skin = Skin.createDefaultSkin();
var table = canvas.stage.addElement(new Window("window", skin)).setMovable(true).setResizable(true);
table.pad(10).setPosition(10, 10);
table.padTop(30);
var button = new TextButton("click", skin);
table.add(button).size(100,20).setRow();
table.pack();
finalRenderDelegate = this;
}
public Scene scene { get; set; }
public void onAddedToScene(){}
public void onSceneBackBufferSizeChanged(int newWidth, int newHeight){}
public void handleFinalRender(Color letterboxColor, RenderTarget2D source, Rectangle finalRenderDestinationRect, SamplerState samplerState)
{
renderer.render(scene);
Core.graphicsDevice.setRenderTarget( null );
Graphics.instance.batcher.begin( BlendState.Opaque, samplerState, null, null );
Graphics.instance.batcher.draw( TestGame.gameScene_.renderer.renderTexture, finalRenderDestinationRect );
Graphics.instance.batcher.end();
Graphics.instance.batcher.begin( BlendState.AlphaBlend, samplerState, DepthStencilState.None, RasterizerState.CullNone, null );
Graphics.instance.batcher.draw( renderer.renderTexture, finalRenderDestinationRect );
Graphics.instance.batcher.end();
}
}
public class MScene : Scene
{
public Renderer renderer;
}
class TestGame : Core
{
public static MScene gameScene_;
protected override void Initialize()
{
base.Initialize();
Window.AllowUserResizing = true;
debugRenderEnabled = true;
Screen.setSize(1281,721);
Transform.shouldRoundPosition = false;
gameScene_ = new TestScene();
gameScene_.begin();
var UIscene = new TestUIScene();
UIscene.begin();
scenes.Add(gameScene_);
scenes.Add(UIscene);
}
}
class Program
{
private static TestGame game;
static void Main(string[] args)
{
game = new TestGame();
game.Run();
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.