Group.xy(index, x, y) allows you to set the x and y coordinates of a Group child at the given index.

Group.reverse() reverses the display order of all children in the Group.
New labs demo.
Fixed some Easing docs issues.
This commit is contained in:
photonstorm
2014-03-04 01:27:57 +00:00
parent 67ad898294
commit 8c2502d37d
6 changed files with 132 additions and 44 deletions
+2
View File
@@ -140,6 +140,8 @@ New features:
* A single Animation object now has 3 new events: onStart, onLoop and onComplete.
* Animation.loopCount holds the number of times the animation has looped since it last started.
* Tween.generateData(frameRate) allows you to generate tween data into an array, which can then be used however you wish (see new examples)
* Group.xy(index, x, y) allows you to set the x and y coordinates of a Group child at the given index.
* Group.reverse() reverses the display order of all children in the Group.
Updates:
+86 -21
View File
@@ -8,40 +8,105 @@ function preload() {
}
var font;
var images;
var dataV;
var dataH;
var dataH2;
var sine = 0;
var total = 24;
var posV = [];
var posH = [];
var text = [ 'phaser v2', 'this march', 'yay retro fonts!', 'shaders', 'filters', 'blend modes', 'full body physics', 'and cats', '(maybe not cats)', '------------' ];
var textIndex = 0;
function create() {
game.stage.smoothed = true;
font = game.add.retroFont('knightHawks', 31, 25, Phaser.RetroFont.TEXT_SET6, 10, 1, 1);
font.text = 'phaser v2';
var i;
var tween;
// Let's create 2 sets of generated tween data - one going vertically, one going horizontally, at different speeds
var tweenData = { x: 200, y: 64 };
for (var c = 0; c < 20; c++)
tween = game.make.tween(tweenData).to( { y: 500 }, 2000, Phaser.Easing.Sinusoidal.InOut);
tween.yoyo(true);
tween.interpolation(game.math.catmullRomInterpolation);
dataV = tween.generateData(60);
tween = game.make.tween(tweenData).to( { x: 600 }, 1500, Phaser.Easing.Sinusoidal.InOut);
tween.yoyo(true);
tween.interpolation(game.math.catmullRomInterpolation);
dataH = tween.generateData(60);
tween = game.make.tween(tweenData).to( { x: 600 }, 1500, Phaser.Easing.Elastic.InOut);
tween.yoyo(true);
tween.interpolation(game.math.catmullRomInterpolation);
dataH2 = tween.generateData(60);
images = game.add.group();
var tmp;
for (var i = 0; i < total; i++)
{
// var i = game.add.image(game.world.centerX, c * 32, font);
var i = game.add.image(game.world.centerX + (c * 10), 32, font);
// i.tint = Math.random() * 0xFFFFFF;
i.anchor.set(0.5, 1);
game.world.sendToBack(i);
// tween = game.add.tween(i).to( { y: 500 }, 2000, Phaser.Easing.Quadratic.InOut, true, i * 100, 1000, true);
// to: function (properties, duration, ease, autoStart, delay, repeat, yoyo) {
tween = game.add.tween(i).to( { y: 500 }, 2000, Phaser.Easing.Sinusoidal.InOut);
tween.delay(c * 10);
tween.yoyo(true);
tween.repeat(Number.MAX_SAFE_INTEGER);
tween.interpolation(game.math.bezierInterpolation);
tween.start();
tmp = images.create(game.world.centerX, 64, font);
tmp.anchor.set(0.5);
tmp.scale.set(2);
// tmp.alpha = (1.0 / total) * i;
posV.push(i * 4);
posH.push(i);
}
images.reverse();
game.time.events.loop(4000, updateText, this);
game.time.events.loop(6000, updateSine, this);
}
function updateSine() {
sine++;
if (sine === 2)
{
sine = 0;
}
}
function updateText() {
textIndex = game.math.wrapValue(textIndex, 1, text.length);
font.text = text[textIndex];
}
function update() {
// font.text = "phaser x: " + game.input.x + " y: " + game.input.y;
var pv, ph;
for (var i = 0; i < total; i++)
{
pv = posV[i];
ph = posH[i];
if (sine === 0)
{
images.getAt(i).x = dataH[ph].x;
}
else
{
images.getAt(i).x = dataH2[ph].x;
}
images.getAt(i).y = dataV[pv].y;
posV[i] = game.math.wrapValue(pv, 1, dataV.length);
posH[i] = game.math.wrapValue(ph, 1, dataH.length);
}
}
+11
View File
@@ -458,6 +458,17 @@ Phaser.Group.prototype.xy = function (index, x, y) {
}
/**
* Reverses all children in this Group. Note that this does not propagate, only direct children are re-ordered.
*
* @method Phaser.Group#reverse
*/
Phaser.Group.prototype.reverse = function () {
this.children.reverse();
}
/**
* Get the index position of the given child in this Group.
*
+1 -1
View File
@@ -586,7 +586,7 @@ Phaser.Math = {
/**
* Adds value to amount and ensures that the result always stays between 0 and max, by wrapping the value around.
* <p>Values must be positive integers, and are passed through Math.abs</p>
* Values must be positive integers, and are passed through Math.abs.
*
* @method Phaser.Math#wrapValue
* @param {number} value - The value to add the amount to.
+20 -20
View File
@@ -365,11 +365,11 @@ Phaser.Easing = {
/**
* Circular ease-in/out.
*
*
* @method Phaser.Easing.Circular#InOut
* @param {number} k - The value to be tweened.
* @returns {number} The tweened value.
*/
*/
InOut: function ( k ) {
if ( ( k *= 2 ) < 1) return - 0.5 * ( Math.sqrt( 1 - k * k) - 1);
@@ -388,11 +388,11 @@ Phaser.Easing = {
/**
* Elastic ease-in.
*
*
* @method Phaser.Easing.Elastic#In
* @param {number} k - The value to be tweened.
* @returns {number} The tweened value.
*/
*/
In: function ( k ) {
var s, a = 0.1, p = 0.4;
@@ -406,11 +406,11 @@ Phaser.Easing = {
/**
* Elastic ease-out.
*
*
* @method Phaser.Easing.Elastic#Out
* @param {number} k - The value to be tweened.
* @returns {number} The tweened value.
*/
*/
Out: function ( k ) {
var s, a = 0.1, p = 0.4;
@@ -424,11 +424,11 @@ Phaser.Easing = {
/**
* Elastic ease-in/out.
*
*
* @method Phaser.Easing.Elastic#InOut
* @param {number} k - The value to be tweened.
* @returns {number} The tweened value.
*/
*/
InOut: function ( k ) {
var s, a = 0.1, p = 0.4;
@@ -452,11 +452,11 @@ Phaser.Easing = {
/**
* Back ease-in.
*
*
* @method Phaser.Easing.Back#In
* @param {number} k - The value to be tweened.
* @returns {number} The tweened value.
*/
*/
In: function ( k ) {
var s = 1.70158;
@@ -466,11 +466,11 @@ Phaser.Easing = {
/**
* Back ease-out.
*
*
* @method Phaser.Easing.Back#Out
* @param {number} k - The value to be tweened.
* @returns {number} The tweened value.
*/
*/
Out: function ( k ) {
var s = 1.70158;
@@ -480,11 +480,11 @@ Phaser.Easing = {
/**
* Back ease-in/out.
*
*
* @method Phaser.Easing.Back#InOut
* @param {number} k - The value to be tweened.
* @returns {number} The tweened value.
*/
*/
InOut: function ( k ) {
var s = 1.70158 * 1.525;
@@ -504,11 +504,11 @@ Phaser.Easing = {
/**
* Bounce ease-in.
*
*
* @method Phaser.Easing.Bounce#In
* @param {number} k - The value to be tweened.
* @returns {number} The tweened value.
*/
*/
In: function ( k ) {
return 1 - Phaser.Easing.Bounce.Out( 1 - k );
@@ -517,11 +517,11 @@ Phaser.Easing = {
/**
* Bounce ease-out.
*
*
* @method Phaser.Easing.Bounce#Out
* @param {number} k - The value to be tweened.
* @returns {number} The tweened value.
*/
*/
Out: function ( k ) {
if ( k < ( 1 / 2.75 ) ) {
@@ -546,11 +546,11 @@ Phaser.Easing = {
/**
* Bounce ease-in/out.
*
*
* @method Phaser.Easing.Bounce#InOut
* @param {number} k - The value to be tweened.
* @returns {number} The tweened value.
*/
*/
InOut: function ( k ) {
if ( k < 0.5 ) return Phaser.Easing.Bounce.In( k * 2 ) * 0.5;
+12 -2
View File
@@ -310,9 +310,10 @@ Phaser.Tween.prototype = {
*
* @method Phaser.Tween#generateData
* @param {number} [frameRate=60] - The speed in frames per second that the data should be generated at. The higher the value, the larger the array it creates.
* @param {array} [data] - If given the generated data will be appended to this array, otherwise a new array will be returned.
* @return {array} An array of tweened values.
*/
generateData: function (frameRate) {
generateData: function (frameRate, data) {
if (this.game === null || this._object === null)
{
@@ -399,7 +400,16 @@ Phaser.Tween.prototype = {
output = output.concat(reversed);
}
return output;
if (typeof data !== 'undefined')
{
data = data.concat(output);
return data;
}
else
{
return output;
}
},