Search
 
SCRIPT & CODE EXAMPLE
 

JAVASCRIPT

phaser wrap in camera bounds

    create ()
    {
        this.graphics = this.add.graphics();

        this.shapes = new Array(15).fill(null).map(
            () => new Phaser.Geom.Circle(Phaser.Math.Between(0, 800), Phaser.Math.Between(0, 600), Phaser.Math.Between(25, 75))
        );

        this.rect = Phaser.Geom.Rectangle.Clone(this.cameras.main);
    }

    update ()
    {
        this.shapes.forEach(function (shape, i) {
            shape.x += (1 + 0.1 * i);
            shape.y += (1 + 0.1 * i);
        });

        Phaser.Actions.WrapInRectangle(this.shapes, this.rect, 72);

        this.draw();
    }

    // Locals methods, they are not part of Phaser.scene
    color (i)
    {
        return 0x001100 * (i % 15) + 0x000033 * (i % 5);
    }

    draw ()
    {
        this.graphics.clear();

        this.shapes.forEach((shape, i) => {
            this.graphics
            .fillStyle(this.color(i), 0.5)
            .fillCircleShape(shape);
        }, this);
    }
Comment

PREVIOUS NEXT
Code Example
Javascript :: phaser add frames to existing animation 
Javascript :: phaser chained animation 
Javascript :: phaser export animation to json 
Javascript :: phaser animation on start event 
Javascript :: phaser show animation play through js 
Javascript :: react-native-fbsdk-next 
Javascript :: unicons add all icons 
Javascript :: toast waning 
Javascript :: multiple pagination angular material 
Javascript :: how to map elements from 1st object react js 
Javascript :: React "Nothing was returned from render Error" Solution 
Javascript :: TypeError: (0 , import_dev.useParams) is not a function remix 
Javascript :: white space below image next image 
Javascript :: Get index of child elements with event listener in JavaScript 
Javascript :: DataTables warning: table id=datatable - Ajax error 
Javascript :: arrow functions basic usages in javascript 
Javascript :: mongoose schema example 
Javascript :: npm read email 
Javascript :: array objects 
Javascript :: mongoose remove 
Javascript :: Update an object as state with React hooks 
Javascript :: javascript run function 
Javascript :: var function js 
Javascript :: java script removing first three indexes 
Javascript :: node.js folder structure 
Javascript :: angularjs select placeholder 
Javascript :: curl to javascript fetch 
Javascript :: document.addeventlistener 
Javascript :: add role command discord.js 
Javascript :: add array type to sequelize migration 
ADD CONTENT
Topic
Content
Source link
Name
1+3 =