mirror of
https://github.com/photonstorm/phaser
synced 2024-11-23 13:13:43 +00:00
Fixed bug causing Text with empty or no given text to break. Added World.createSpring.
This commit is contained in:
parent
0584d3eadf
commit
8318a58f69
5 changed files with 128 additions and 14 deletions
68
examples/p2 physics/springs.js
Normal file
68
examples/p2 physics/springs.js
Normal file
|
@ -0,0 +1,68 @@
|
|||
|
||||
var game = new Phaser.Game(800, 600, Phaser.CANVAS, 'phaser-example', { preload: preload, create: create, update: update });
|
||||
|
||||
function preload() {
|
||||
|
||||
game.load.image('atari', 'assets/sprites/atari130xe.png');
|
||||
game.load.image('sky', 'assets/skies/sunset.png');
|
||||
|
||||
}
|
||||
|
||||
var sprite;
|
||||
var cursors;
|
||||
|
||||
function create() {
|
||||
|
||||
game.add.image(0, 0, 'sky');
|
||||
|
||||
// Enable p2 physics
|
||||
game.physics.startSystem(Phaser.Physics.P2JS);
|
||||
|
||||
// Add a sprite
|
||||
sprite = game.add.sprite(200, 200, 'atari');
|
||||
|
||||
// Enable if for physics. This creates a default rectangular body.
|
||||
game.physics.p2.enable(sprite);
|
||||
|
||||
// Create our spring
|
||||
var spring = game.physics.p2.createSpring(bodyA, bodyB, restLength, stiffness, damping, worldA, worldB, localA, localB);
|
||||
|
||||
// var spring = game.physics.p2.
|
||||
|
||||
// var spring = new p2.Spring(bodyA,bodyB, {
|
||||
// stiffness: k,
|
||||
// restLength: l,
|
||||
// damping : d
|
||||
// });
|
||||
|
||||
|
||||
|
||||
text = game.add.text(20, 20, 'move with arrow keys', { fill: '#ffffff' });
|
||||
|
||||
cursors = game.input.keyboard.createCursorKeys();
|
||||
|
||||
}
|
||||
|
||||
function update() {
|
||||
|
||||
// sprite.body.setZeroVelocity();
|
||||
|
||||
// if (cursors.left.isDown)
|
||||
// {
|
||||
// sprite.body.moveLeft(400);
|
||||
// }
|
||||
// else if (cursors.right.isDown)
|
||||
// {
|
||||
// sprite.body.moveRight(400);
|
||||
// }
|
||||
|
||||
// if (cursors.up.isDown)
|
||||
// {
|
||||
// sprite.body.moveUp(400);
|
||||
// }
|
||||
// else if (cursors.down.isDown)
|
||||
// {
|
||||
// sprite.body.moveDown(400);
|
||||
// }
|
||||
|
||||
}
|
10
examples/wip/blank text.js
Normal file
10
examples/wip/blank text.js
Normal file
|
@ -0,0 +1,10 @@
|
|||
var game = new Phaser.Game(800, 600, Phaser.CANVAS, 'phaser-example', { create: create });
|
||||
|
||||
function create() {
|
||||
|
||||
var style = { font: "65px Arial", fill: "#ff0044", align: "center" };
|
||||
var text = game.add.text(game.world.centerX, game.world.centerY, "x", style);
|
||||
|
||||
text.anchor.set(0.5);
|
||||
|
||||
}
|
|
@ -22,8 +22,13 @@ Phaser.Text = function (game, x, y, text, style) {
|
|||
|
||||
x = x || 0;
|
||||
y = y || 0;
|
||||
text = text || '';
|
||||
style = style || '';
|
||||
text = text || ' ';
|
||||
style = style || {};
|
||||
|
||||
if (text.length == 0)
|
||||
{
|
||||
text = ' ';
|
||||
}
|
||||
|
||||
/**
|
||||
* @property {Phaser.Game} game - A reference to the currently running Game.
|
||||
|
@ -103,7 +108,9 @@ Phaser.Text = function (game, x, y, text, style) {
|
|||
*/
|
||||
this.cameraOffset = new Phaser.Point();
|
||||
|
||||
PIXI.Text.call(this, text, style);
|
||||
this.setStyle(style);
|
||||
|
||||
PIXI.Text.call(this, text, this.style);
|
||||
|
||||
this.position.set(x, y);
|
||||
|
||||
|
|
|
@ -11,15 +11,15 @@
|
|||
* @classdesc Physics Spring Constructor
|
||||
* @constructor
|
||||
* @param {Phaser.Physics.P2} world - A reference to the P2 World.
|
||||
* @param {p2.Body} bodyA - First connected body.
|
||||
* @param {p2.Body} bodyB - Second connected body.
|
||||
* @param {Phaser.Physics.P2.Body} bodyA - First connected body.
|
||||
* @param {Phaser.Physics.P2.Body} bodyB - Second connected body.
|
||||
* @param {number} [restLength=1] - Rest length of the spring. A number > 0.
|
||||
* @param {number} [stiffness=100] - Stiffness of the spring. A number >= 0.
|
||||
* @param {number} [damping=1] - Damping of the spring. A number >= 0.
|
||||
* @param {Array} [worldA] - Where to hook the spring to body A, in world coordinates, i.e. [32, 32].
|
||||
* @param {Array} [worldB] - Where to hook the spring to body B, in world coordinates, i.e. [32, 32].
|
||||
* @param {Array} [localA] - Where to hook the spring to body A, in local body coordinates.
|
||||
* @param {Array} [localB] - Where to hook the spring to body B, in local body coordinates.
|
||||
* @param {Array} [worldA] - Where to hook the spring to body A in world coordinates. This value is an array by 2 elements, x and y, i.e: [32, 32].
|
||||
* @param {Array} [worldB] - Where to hook the spring to body B in world coordinates. This value is an array by 2 elements, x and y, i.e: [32, 32].
|
||||
* @param {Array} [localA] - Where to hook the spring to body A in local body coordinates. This value is an array by 2 elements, x and y, i.e: [32, 32].
|
||||
* @param {Array} [localB] - Where to hook the spring to body B in local body coordinates. This value is an array by 2 elements, x and y, i.e: [32, 32].
|
||||
*/
|
||||
Phaser.Physics.P2.Spring = function (world, bodyA, bodyB, restLength, stiffness, damping, worldA, worldB, localA, localB) {
|
||||
|
||||
|
@ -29,7 +29,7 @@ Phaser.Physics.P2.Spring = function (world, bodyA, bodyB, restLength, stiffness,
|
|||
this.game = world.game;
|
||||
|
||||
/**
|
||||
* @property {Phaser.Physics.P2.World} world - Local reference to P2 World.
|
||||
* @property {Phaser.Physics.P2} world - Local reference to P2 World.
|
||||
*/
|
||||
this.world = world;
|
||||
|
||||
|
@ -63,7 +63,7 @@ Phaser.Physics.P2.Spring = function (world, bodyA, bodyB, restLength, stiffness,
|
|||
options.localAnchorB = [ world.pxm(localB[0]), world.pxm(localB[1]) ];
|
||||
}
|
||||
|
||||
p2.Spring.call(this, bodyA, bodyB, options);
|
||||
p2.Spring.call(this, bodyA.data, bodyB.data, options);
|
||||
|
||||
}
|
||||
|
||||
|
|
|
@ -1031,7 +1031,33 @@ Phaser.Physics.P2.prototype = {
|
|||
},
|
||||
|
||||
/**
|
||||
* @method Phaser.Physics.P2.prototype.createBody
|
||||
* Creates a spring, connecting two bodies.
|
||||
*
|
||||
* @method Phaser.Physics.P2#createSpring
|
||||
* @param {Phaser.Physics.P2.Body} bodyA - First connected body.
|
||||
* @param {Phaser.Physics.P2.Body} bodyB - Second connected body.
|
||||
* @param {number} [restLength=1] - Rest length of the spring. A number > 0.
|
||||
* @param {number} [stiffness=100] - Stiffness of the spring. A number >= 0.
|
||||
* @param {number} [damping=1] - Damping of the spring. A number >= 0.
|
||||
* @param {number} [restLength=1] - Rest length of the spring. A number > 0.
|
||||
* @param {number} [stiffness=100] - Stiffness of the spring. A number >= 0.
|
||||
* @param {number} [damping=1] - Damping of the spring. A number >= 0.
|
||||
* @param {Array} [worldA] - Where to hook the spring to body A in world coordinates. This value is an array by 2 elements, x and y, i.e: [32, 32].
|
||||
* @param {Array} [worldB] - Where to hook the spring to body B in world coordinates. This value is an array by 2 elements, x and y, i.e: [32, 32].
|
||||
* @param {Array} [localA] - Where to hook the spring to body A in local body coordinates. This value is an array by 2 elements, x and y, i.e: [32, 32].
|
||||
* @param {Array} [localB] - Where to hook the spring to body B in local body coordinates. This value is an array by 2 elements, x and y, i.e: [32, 32].
|
||||
* @return {Phaser.Physics.P2.Spring} The spring
|
||||
*/
|
||||
createSpring: function (bodyA, bodyB, restLength, stiffness, damping, worldA, worldB, localA, localB) {
|
||||
|
||||
return new Phaser.Physics.P2.Spring(this, bodyA, bodyB, restLength, stiffness, damping, worldA, worldB, localA, localB);
|
||||
|
||||
},
|
||||
|
||||
/**
|
||||
* Creates a new Body and adds it to the World.
|
||||
*
|
||||
* @method Phaser.Physics.P2#createBody
|
||||
* @param {number} x - The x coordinate of Body.
|
||||
* @param {number} y - The y coordinate of Body.
|
||||
* @param {number} mass - The mass of the Body. A mass of 0 means a 'static' Body is created.
|
||||
|
@ -1043,6 +1069,7 @@ Phaser.Physics.P2.prototype = {
|
|||
* @param {(number[]|...number)} points - An array of 2d vectors that form the convex or concave polygon.
|
||||
* Either [[0,0], [0,1],...] or a flat array of numbers that will be interpreted as [x,y, x,y, ...],
|
||||
* or the arguments passed can be flat x,y values e.g. `setPolygon(options, x,y, x,y, x,y, ...)` where `x` and `y` are numbers.
|
||||
* @return {Phaser.Physics.P2.Body} The body
|
||||
*/
|
||||
createBody: function (x, y, mass, addToWorld, options, data) {
|
||||
|
||||
|
@ -1070,7 +1097,9 @@ Phaser.Physics.P2.prototype = {
|
|||
},
|
||||
|
||||
/**
|
||||
* @method Phaser.Physics.P2.prototype.createBody
|
||||
* Creates a new Particle and adds it to the World.
|
||||
*
|
||||
* @method Phaser.Physics.P2#createParticle
|
||||
* @param {number} x - The x coordinate of Body.
|
||||
* @param {number} y - The y coordinate of Body.
|
||||
* @param {number} mass - The mass of the Body. A mass of 0 means a 'static' Body is created.
|
||||
|
@ -1112,7 +1141,7 @@ Phaser.Physics.P2.prototype = {
|
|||
* Converts all of the polylines objects inside a Tiled ObjectGroup into physics bodies that are added to the world.
|
||||
* Note that the polylines must be created in such a way that they can withstand polygon decomposition.
|
||||
*
|
||||
* @method Phaser.Tilemap#createCollisionObjects
|
||||
* @method Phaser.Physics.P2#convertCollisionObjects
|
||||
* @param {Phaser.Tilemap} map - The Tilemap to get the map data from.
|
||||
* @param {number|string|Phaser.TilemapLayer} [layer] - The layer to operate on. If not given will default to map.currentLayer.
|
||||
* @param {boolean} [addToWorld=true] - If true it will automatically add each body to the world.
|
||||
|
|
Loading…
Reference in a new issue