Search
 
SCRIPT & CODE EXAMPLE
 

JAVASCRIPT

phaser max size of group or pool

function create ()
{
    var Bullet = new Phaser.Class({

        Extends: Phaser.GameObjects.Image,

        initialize:

        function Bullet (scene)
        {
            Phaser.GameObjects.Image.call(this, scene, 0, 0, 'bullet');

            this.speed = Phaser.Math.GetSpeed(400, 1);
        },

        fire: function (x, y)
        {
            this.setPosition(x, y - 50);
        },

        update: function (time, delta)
        {
            this.y -= this.speed * delta;

            if (this.y < -50)
            {
                this.setActive(false);
                this.setVisible(false);
            }
        }

    });

    //  Limited to just 4 objects in the pool, not allowed to grow beyond it
    bullets = this.add.group({
        classType: Bullet,
        maxSize: 4,
        runChildUpdate: true
    });

    ship = this.add.sprite(400, 500, 'ship').setDepth(1);

    cursors = this.input.keyboard.createCursorKeys();

    speed = Phaser.Math.GetSpeed(300, 1);
}

function update (time, delta)
{
    if (cursors.left.isDown)
    {
        ship.x -= speed * delta;
    }
    else if (cursors.right.isDown)
    {
        ship.x += speed * delta;
    }

    if (cursors.up.isDown && time > lastFired)
    {
        var bullet = bullets.get();

        if (bullet)
        {
            bullet.fire(ship.x, ship.y);

            lastFired = time + 50;
        }
    }
}
Comment

PREVIOUS NEXT
Code Example
Javascript :: phaser reverse matrix columns 
Javascript :: short-circuit evaluation , use of || operator 
Javascript :: phaser wrap group 
Javascript :: Setting Multiples Properties With Array 
Javascript :: Gamification Details Component is not declared in any Angular module 
Javascript :: creating hashblock method using sha256 hashing algorithm 
Javascript :: Vue Js The specified value cannot be parsed, or is out of range 
Javascript :: Make Floating label TextInput with password show/hide in react native 
Javascript :: module imports renaming 
Javascript :: import local js file node 
Javascript :: electron write to csv 
Javascript :: javascript complier 
Javascript :: mdn javascript array 
Javascript :: prisma count non-null 
Javascript :: If you wish to set a method equal to another method in the class 
Javascript :: nestjs prisma controller 
Javascript :: create object in jquery dynamically 
Javascript :: Exporting Objects with the Exports Object in electron 
Javascript :: Deployment of react static page using node and express 
Javascript :: angular service await for data 
Javascript :: Check if a number starts with another number or not js 
Javascript :: Solution-1--solution options for reverse bits algorithm js 
Javascript :: how to decrypt md5 hash 
Javascript :: flutter webview javascript 
Javascript :: polymorphism js 
Javascript :: 2d arrays js 
Javascript :: static in class javascript 
Javascript :: vs code ouput stack 
Javascript :: javascript neue zeilekill 
Javascript :: what f a number exceeding 2^53 in javascript 
ADD CONTENT
Topic
Content
Source link
Name
6+7 =