Applying Shaders to everything except UI



  • Hello everyone,
    I'm experimenting with using shaders in my HaxePunk game and I was wondering:
    Is there a way to apply a shader to the scene, but not the game UI?

    For example, imagine blurring the screen when the player opens an inventory interface, or applying effects to the game world only.

    Thanks in advance.


  • administrators

    The way I've done this is to make my UI and game content separate scenes, something like this:

    class UIScene extends Scene {
        var gameScene:GameScene;
    
        public function new(g:GameScene) {
            super();
            gameScene = g;
            bgAlpha = 0;
        }
    
        public function update() {
            super.update();
            if (!gamePaused) gameScene.update();
        }
    }
    
    class GameScene extends Scene {
        // ...
    }
    

    And to activate both:

    var gameScene = new GameScene(),
        uiScene = new UIScene(gameScene);
    HXP.engine.pushScene(gameScene);
    HXP.engine.pushScene(uiScene);
    

    You can then apply shaders to either scene.



  • @bendmorris
    Hi, is it possible to have multiple scenes rendered at once?
    i try smth like this:

    var scene1:Scene = new Scene();
    var e1:Entity = new Entity(0, 0, Image.createRect(100, 100, 0xff0000));
    scene1.add(e1);
    
    var scene2:Scene = new Scene();
    scene2.bgAlpha = 0;
    var e2:Entity = new Entity(0, 0, Image.createRect(50, 50, 0x00ff00));
    scene2.add(e2);
    
    HXP.engine.pushScene(scene1);
    HXP.engine.pushScene(scene2);
    

    and i can only see scene2, the green square


Log in to reply
 

Looks like your connection to NodeBB was lost, please wait while we try to reconnect.