Two new particle examples and a group animation example. Also fixed CocoonJS sound issue and Cache sound locked bug.

This commit is contained in:
photonstorm
2013-12-31 03:37:11 +00:00
parent 3b87ce9fc9
commit 86f6ddcbc8
15 changed files with 228 additions and 13 deletions
+12
View File
@@ -4,6 +4,10 @@
"file": "change+texture+on+click.js",
"title": "change texture on click"
},
{
"file": "group+creation.js",
"title": "group creation"
},
{
"file": "local+json+object.js",
"title": "local json object"
@@ -542,10 +546,18 @@
"file": "no+rotation.js",
"title": "no rotation"
},
{
"file": "rain.js",
"title": "rain"
},
{
"file": "random+sprite.js",
"title": "random sprite"
},
{
"file": "snow.js",
"title": "snow"
},
{
"file": "when+particles+collide.js",
"title": "when particles collide"
+40
View File
@@ -0,0 +1,40 @@
var game = new Phaser.Game(800, 600, Phaser.AUTO, 'phaser-example', { preload: preload, create: create });
function preload() {
game.load.atlas('seacreatures', 'assets/sprites/seacreatures_json.png', 'assets/sprites/seacreatures_json.json');
game.load.image('undersea', 'assets/pics/undersea.jpg');
game.load.image('coral', 'assets/pics/seabed.png');
}
function create() {
game.add.sprite(0, 0, 'undersea');
// Here we create our group and populate it with 6 sprites
var group = game.add.group();
for (var i = 0; i < 6; i++)
{
// They are evenly spaced out on the X coordinate, with a random Y coordinate
sprite = group.create(120 * i, game.rnd.integerInRange(100, 400), 'seacreatures', 'octopus0000');
}
// These are the frame names for the octopus animation. We use the generateFrames function to help create the array.
var frameNames = Phaser.Animation.generateFrameNames('octopus', 0, 24, '', 4);
// Here is the important part. Group.callAll will call a method that exists on every child in the Group.
// In this case we're saying: child.animations.add('swim', frameNames, 30, true, false)
// The second parameter ('animations') is really important and is the context in which the method is called.
// For animations the context is the Phaser.AnimationManager, which is linked to the child.animations property.
// Everything after the 2nd parameter is just the usual values you'd pass to the animations.add method.
group.callAll('animations.add', 'animations', 'swim', frameNames, 30, true, false);
// Here we just say 'play the swim animation', this time the 'play' method exists on the child itself, so we can set the context to null.
group.callAll('play', null, 'swim');
game.add.sprite(0, 466, 'coral');
}
Binary file not shown.

After

Width:  |  Height:  |  Size: 1.4 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.9 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 21 KiB

+1 -1
View File
@@ -1,7 +1,7 @@
var game = new Phaser.Game(800, 600, Phaser.CANVAS, 'phaser-example', { preload: preload, create: create, update: update, render: render });
var baseAlphaIncSpeed= 0.006;
var baseAlphaIncSpeed = 0.006;
function preload() {
game.load.spritesheet('item', 'assets/buttons/number-buttons-90x90.png', 90, 90);
+27
View File
@@ -0,0 +1,27 @@
// This example was created by Jens Anders Bakke
var game = new Phaser.Game(800, 600, Phaser.AUTO, 'phaser-example', { preload: preload, create: create });
function preload() {
game.load.spritesheet('rain', 'assets/sprites/rain.png', 17, 17);
}
function create() {
var emitter = game.add.emitter(game.world.centerX, 0, 400);
emitter.width = game.world.width;
// emitter.angle = 30; // uncomment to set an angle for the rain.
emitter.makeParticles('rain');
emitter.maxParticleScale = 0.5;
emitter.minParticleScale = 0.1;
emitter.setYSpeed(300, 500);
emitter.setXSpeed(-5, 5);
emitter.minRotation = 0;
emitter.maxRotation = 0;
emitter.start(false, 1600, 5, 0);
}
+100
View File
@@ -0,0 +1,100 @@
// This example was created by Jens Anders Bakke
var game = new Phaser.Game(800, 600, Phaser.AUTO, 'phaser-example', { preload: preload, create: create });
function preload() {
game.load.spritesheet('snowflakes', 'assets/sprites/snowflakes.png', 17, 17);
game.load.spritesheet('snowflakes_large', 'assets/sprites/snowflakes_large.png', 64, 64);
}
var max = 0;
var front_emitter;
var mid_emitter;
var back_emitter;
var update_interval = 4 * 60;
var i = 0;
function create() {
back_emitter = game.add.emitter(game.world.centerX, -32, 600);
back_emitter.makeParticles('snowflakes', [0, 1, 2, 3, 4, 5]);
back_emitter.maxParticleScale = 0.6;
back_emitter.minParticleScale = 0.2;
back_emitter.setYSpeed(20, 100);
back_emitter.gravity = 0;
back_emitter.width = game.world.width * 1.5;
back_emitter.minRotation = 0;
back_emitter.maxRotation = 40;
mid_emitter = game.add.emitter(game.world.centerX, -32, 250);
mid_emitter.makeParticles('snowflakes', [0, 1, 2, 3, 4, 5]);
mid_emitter.maxParticleScale = 1.2;
mid_emitter.minParticleScale = 0.8;
mid_emitter.setYSpeed(50, 150);
mid_emitter.gravity = 0;
mid_emitter.width = game.world.width * 1.5;
mid_emitter.minRotation = 0;
mid_emitter.maxRotation = 40;
front_emitter = game.add.emitter(game.world.centerX, -32, 50);
front_emitter.makeParticles('snowflakes_large', [0, 1, 2, 3, 4, 5]);
front_emitter.maxParticleScale = 1;
front_emitter.minParticleScale = 0.5;
front_emitter.setYSpeed(100, 200);
front_emitter.gravity = 0;
front_emitter.width = game.world.width * 1.5;
front_emitter.minRotation = 0;
front_emitter.maxRotation = 40;
changeWindDirection();
back_emitter.start(false, 14000, 20);
mid_emitter.start(false, 12000, 40);
front_emitter.start(false, 6000, 1000);
}
function update() {
i++;
if (i === update_interval)
{
changeWindDirection();
update_interval = Math.floor(Math.random() * 20) * 60; // 0 - 20sec @ 60fps
i = 0;
}
}
function changeWindDirection() {
var multi = Math.floor((max + 200) / 4),
frag = (Math.floor(Math.random() * 100) - multi);
max = max + frag;
if (max > 200) max = 150;
if (max < -200) max = -150;
setXSpeed(back_emitter, max);
setXSpeed(mid_emitter, max);
setXSpeed(front_emitter, max);
}
function setXSpeed(emitter, max) {
emitter.setXSpeed(max - 20, max);
emitter.forEachAlive(setParticleXSpeed, this, max);
}
function setParticleXSpeed(particle, max) {
particle.body.velocity.x = max - Math.floor(Math.random() * 30);
}
+31
View File
@@ -0,0 +1,31 @@
var game = new Phaser.Game(800, 600, Phaser.AUTO, 'phaser-example', { preload: preload, create: create });
function preload() {
game.load.atlas('seacreatures', 'assets/sprites/seacreatures_json.png', 'assets/sprites/seacreatures_json.json');
game.load.image('undersea', 'assets/pics/undersea.jpg');
game.load.image('coral', 'assets/pics/seabed.png');
}
function create() {
game.add.sprite(0, 0, 'undersea');
var group = game.add.group();
for (var i = 0; i < 6; i++)
{
sprite = group.create(120 * i, game.rnd.integerInRange(100, 400), 'seacreatures', 'octopus0000');
}
var frameNames = Phaser.Animation.generateFrameNames('octopus', 0, 24, '', 4);
group.callAll('animations.add', 'animations', 'swim', frameNames, 30, true, false);
group.callAll('play', null, 'swim');
game.add.sprite(0, 466, 'coral');
}
+2 -1
View File
@@ -56,7 +56,8 @@ function create() {
// vu4 = game.add.sprite(400, 250, 'vu3');
module = new Protracker();
module.buffer = game.cache.getBinary('globaltrash');
// module.buffer = game.cache.getBinary('globaltrash');
module.buffer = game.cache.getBinary('macrocosm');
module.parse();
module.play();