Search the Community
Showing results for tags 'sprite group animation timer'.
-
In the Phaser examples there is 'Create Sprite in a group'. Here's the code: -------------------------------------------------------------- var game = new Phaser.Game(800, 600, Phaser.CANVAS, 'phaser-example', { preload: preload, create: create, render: render }); function preload() { game.load.image('ufo', 'assets/sprites/ufo.png'); game.load.image('baddie', 'assets/sprites/space-baddie.png'); } var friendAndFoe; var enemies; function create() { // Create some local groups for later use. friendAndFoe = game.add.group(); enemies = game.add.group(); // You can directly create a sprite and add it to a group // using just one line. friendAndFoe.create(200, 240, 'ufo'); // Create some enemies. for (var i = 0; i < 8; i++) { createBaddie(); } // Tap to create new baddie sprites. game.input.onTap.add(createBaddie, this); } function createBaddie() { enemies.create(360 + Math.random() * 200, 120 + Math.random() * 200,'baddie'); } function render() { game.debug.text('Tap screen or click to create new baddies.', 16, 24); } ------------------------------- What if you wanted to add the same sprite 'the baddie' over and over again automatically in a fixed location, no button use, using a timer instead? Let's say, so it built up a horizontal row of baddies and then a vertical row of baddies, maybe one baddie every two seconds with a corresponding audio file (just a short beep), the same audio file over and over with each baddie being spawned. There's another example; 'Create if null' - creates a sprite every second. Something like the two examples combined??? Don't get me wrong, lots of examples there. Anyone have any ideas how one might do the above? Because I don't see any examples like what I'm describing, sprites, animations, fixed locations, timers, audio files, etc.