Git Product home page Git Product logo

duelingmanbros's Issues

Figure out how to share stuff (like clouds) between game states

https://github.com/BdR76/phaserbackground
Example?

// -------------------------------------// define the game state screen1// -------------------------------------
var mygame = {};
mygame.Screen1 = function(game) {
    this.game = game;
};
mygame.Screen1.prototype = {
    create: function() {
        // random background and random text position        
        addRandomPolkaDots(this.game);
        var x = this.game.rnd.integerInRange(0, 500);
        var y = this.game.rnd.integerInRange(0, 400);

        // add text       
        var style = {
            font: "65px Arial",
            fill: "#ff0044",
            align: "center"
        };
        var text = this.game.add.text(x, y, "Screen 1\nTap to switch.", style);
        // tap input handler        this.game.input.onDown.add(this.doTap, this);        
        // -- FADE IN --       
        console.log('create -- fade in..');
        doFadeIn(this.game, true);
    },
    doTap: function() {
        // -- FADE OUT --       
        console.log('doTap -- fade out..');
        var t = doFadeIn(this.game, false);
        t.onComplete.add(this.switchToScreen2, this);
    },
    switchToScreen2: function() {
        this.game.state.start('Screen1');
    }
}; // -------------------------------------// 
global functions can be called from all states // -------------------------------------
function addRandomPolkaDots(gm) {
    var graphics = gm.add.graphics(0, 0);
    // add random dots   
    for (var i = 0; i < 10; i++) {
        // random position and radius     
        var x = this.game.rnd.integerInRange(0, 500);
        var y = this.game.rnd.integerInRange(0, 400);
        var r = this.game.rnd.integerInRange(10, 100);
        // draw a circle 
        graphics.lineStyle(0);
        graphics.beginFill(0x4400ff, 0.5);
        graphics.drawCircle(x, y, r);
    };
}

function doFadeIn(gm, bFadeIn) {
    // fade in or out   
    var alphaFrom = 0.0;
    var alphaGoal = 1.0;
    if (bFadeIn == true) {
        alphaFrom = 1.0;
        alphaGoal = 0.0;
    } // set blaack box  
    var blackbox = gm.add.graphics(0, 0);
    blackbox.beginFill(000000, alphaFrom);
    blackbox.drawRect(0, 0, 800, 600); // tween alpha to fade in or out  
    var tw = gm.add.tween(blackbox);
    tw.to({
        alpha: alphaGoal
    }, 1000, Phaser.Easing.Linear.None, true);
    return tw;
} // -------------------------------------// define Phaser game and add states// -------------------------------------
var game = new Phaser.Game(800, 600, Phaser.CANVAS, 'game');
game.state.add('Screen1', mygame.Screen1);
game.state.add('Screen2', mygame.Screen1);
// just testing, re-use the same state.
.game.state.start('Screen1');

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.