mirror of
https://github.com/wassname/phaser.git
synced 2026-07-04 17:20:31 +08:00
Adding in missing tests and fixing as we go
This commit is contained in:
@@ -143,7 +143,7 @@ module Phaser.Components {
|
||||
* @param clearAnimations {boolean} If this Sprite has a set of animation data already loaded you can choose to keep or clear it with this boolean
|
||||
* @return {Sprite} Sprite instance itself.
|
||||
*/
|
||||
public loadImage(key: string, clearAnimations: bool = true) {
|
||||
public loadImage(key: string, clearAnimations?: bool = true, updateBody?: bool = true) {
|
||||
|
||||
if (clearAnimations && this._sprite.animations.frameData !== null)
|
||||
{
|
||||
@@ -163,6 +163,12 @@ module Phaser.Components {
|
||||
this._sprite.frameBounds.width = this.width;
|
||||
this._sprite.frameBounds.height = this.height;
|
||||
}
|
||||
|
||||
if (updateBody)
|
||||
{
|
||||
this._sprite.body.bounds.width = this.width;
|
||||
this._sprite.body.bounds.height = this.height;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
+12
-1
@@ -201,7 +201,18 @@ module Phaser {
|
||||
|
||||
if (this._member != null && this._member.exists && this._member.visible && camera.isHidden(this._member) == false)
|
||||
{
|
||||
this._member.render.call(renderer, camera, this._member);
|
||||
//this._member.render.call(renderer, camera, this._member);
|
||||
// call = context first, then parameters
|
||||
if (this._member.type == Types.GROUP)
|
||||
{
|
||||
//console.log('group rend');
|
||||
this._member.render.call(this._member, renderer, camera, this._member);
|
||||
//this._member.render.call(this, renderer, camera, this._member);
|
||||
}
|
||||
else
|
||||
{
|
||||
this._member.render.call(renderer, camera, this._member);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -46,6 +46,10 @@ module Phaser {
|
||||
this._explode = true;
|
||||
this.on = false;
|
||||
|
||||
this.exists = true;
|
||||
this.active = true;
|
||||
this.visible = true;
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -73,6 +77,11 @@ module Phaser {
|
||||
*/
|
||||
public alive: bool;
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
public active: bool;
|
||||
|
||||
/**
|
||||
* The minimum possible velocity of a particle.
|
||||
* The default value is (-100,-100).
|
||||
@@ -217,29 +226,14 @@ module Phaser {
|
||||
{
|
||||
/*
|
||||
randomFrame = this.game.math.random()*totalFrames;
|
||||
if(BakedRotations > 0)
|
||||
particle.loadRotatedGraphic(Graphics,BakedRotations,randomFrame);
|
||||
else
|
||||
{
|
||||
particle.loadGraphic(Graphics,true);
|
||||
particle.frame = randomFrame;
|
||||
}
|
||||
*/
|
||||
}
|
||||
else
|
||||
{
|
||||
/*
|
||||
if (BakedRotations > 0)
|
||||
particle.loadRotatedGraphic(Graphics,BakedRotations);
|
||||
else
|
||||
particle.loadGraphic(Graphics);
|
||||
*/
|
||||
|
||||
if (graphics)
|
||||
{
|
||||
particle.texture.loadImage(graphics);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
if (collide > 0)
|
||||
@@ -255,6 +249,8 @@ module Phaser {
|
||||
}
|
||||
|
||||
particle.exists = false;
|
||||
// Center the origin for rotation assistance
|
||||
particle.origin.setTo(particle.body.bounds.halfWidth, particle.body.bounds.halfHeight);
|
||||
|
||||
this.add(particle);
|
||||
|
||||
@@ -264,6 +260,9 @@ module Phaser {
|
||||
return this;
|
||||
}
|
||||
|
||||
public preUpdate() { }
|
||||
public postUpdate() { }
|
||||
|
||||
/**
|
||||
* Called automatically by the game loop, decides when to launch particles and when to "die".
|
||||
*/
|
||||
|
||||
@@ -20,6 +20,7 @@ module Phaser {
|
||||
|
||||
super(game);
|
||||
|
||||
this.body.type = Types.BODY_DYNAMIC;
|
||||
this.lifespan = 0;
|
||||
this.friction = 500;
|
||||
|
||||
@@ -45,7 +46,7 @@ module Phaser {
|
||||
*/
|
||||
public update() {
|
||||
|
||||
//lifespan behavior
|
||||
// Lifespan behavior
|
||||
if (this.lifespan <= 0)
|
||||
{
|
||||
return;
|
||||
|
||||
+15
-10
@@ -23,10 +23,12 @@ module Phaser {
|
||||
* @param {Number} height Desired height of this node.
|
||||
* @param {Number} parent The parent branch or node. Pass null to create a root.
|
||||
*/
|
||||
constructor(x: number, y: number, width: number, height: number, parent: QuadTree = null) {
|
||||
constructor(manager: Phaser.Physics.PhysicsManager, x: number, y: number, width: number, height: number, parent: QuadTree = null) {
|
||||
|
||||
super(x, y, width, height);
|
||||
|
||||
QuadTree.physics = manager;
|
||||
|
||||
this._headA = this._tailA = new Phaser.LinkedList();
|
||||
this._headB = this._tailB = new Phaser.LinkedList();
|
||||
|
||||
@@ -102,6 +104,8 @@ module Phaser {
|
||||
private _overlapProcessed: bool;
|
||||
private _checkObject;
|
||||
|
||||
public static physics: Phaser.Physics.PhysicsManager;
|
||||
|
||||
/**
|
||||
* Flag for specifying that you want to add an object to the A list.
|
||||
*/
|
||||
@@ -392,7 +396,7 @@ module Phaser {
|
||||
{
|
||||
if (this._northWestTree == null)
|
||||
{
|
||||
this._northWestTree = new QuadTree(this._leftEdge, this._topEdge, this._halfWidth, this._halfHeight, this);
|
||||
this._northWestTree = new QuadTree(QuadTree.physics, this._leftEdge, this._topEdge, this._halfWidth, this._halfHeight, this);
|
||||
}
|
||||
|
||||
this._northWestTree.addObject();
|
||||
@@ -403,7 +407,7 @@ module Phaser {
|
||||
{
|
||||
if (this._southWestTree == null)
|
||||
{
|
||||
this._southWestTree = new QuadTree(this._leftEdge, this._midpointY, this._halfWidth, this._halfHeight, this);
|
||||
this._southWestTree = new QuadTree(QuadTree.physics, this._leftEdge, this._midpointY, this._halfWidth, this._halfHeight, this);
|
||||
}
|
||||
|
||||
this._southWestTree.addObject();
|
||||
@@ -417,7 +421,7 @@ module Phaser {
|
||||
{
|
||||
if (this._northEastTree == null)
|
||||
{
|
||||
this._northEastTree = new QuadTree(this._midpointX, this._topEdge, this._halfWidth, this._halfHeight, this);
|
||||
this._northEastTree = new QuadTree(QuadTree.physics, this._midpointX, this._topEdge, this._halfWidth, this._halfHeight, this);
|
||||
}
|
||||
|
||||
this._northEastTree.addObject();
|
||||
@@ -428,7 +432,7 @@ module Phaser {
|
||||
{
|
||||
if (this._southEastTree == null)
|
||||
{
|
||||
this._southEastTree = new QuadTree(this._midpointX, this._midpointY, this._halfWidth, this._halfHeight, this);
|
||||
this._southEastTree = new QuadTree(QuadTree.physics, this._midpointX, this._midpointY, this._halfWidth, this._halfHeight, this);
|
||||
}
|
||||
|
||||
this._southEastTree.addObject();
|
||||
@@ -441,7 +445,7 @@ module Phaser {
|
||||
{
|
||||
if (this._northWestTree == null)
|
||||
{
|
||||
this._northWestTree = new QuadTree(this._leftEdge, this._topEdge, this._halfWidth, this._halfHeight, this);
|
||||
this._northWestTree = new QuadTree(QuadTree.physics, this._leftEdge, this._topEdge, this._halfWidth, this._halfHeight, this);
|
||||
}
|
||||
|
||||
this._northWestTree.addObject();
|
||||
@@ -451,7 +455,7 @@ module Phaser {
|
||||
{
|
||||
if (this._northEastTree == null)
|
||||
{
|
||||
this._northEastTree = new QuadTree(this._midpointX, this._topEdge, this._halfWidth, this._halfHeight, this);
|
||||
this._northEastTree = new QuadTree(QuadTree.physics, this._midpointX, this._topEdge, this._halfWidth, this._halfHeight, this);
|
||||
}
|
||||
|
||||
this._northEastTree.addObject();
|
||||
@@ -461,7 +465,7 @@ module Phaser {
|
||||
{
|
||||
if (this._southEastTree == null)
|
||||
{
|
||||
this._southEastTree = new QuadTree(this._midpointX, this._midpointY, this._halfWidth, this._halfHeight, this);
|
||||
this._southEastTree = new QuadTree(QuadTree.physics, this._midpointX, this._midpointY, this._halfWidth, this._halfHeight, this);
|
||||
}
|
||||
|
||||
this._southEastTree.addObject();
|
||||
@@ -471,7 +475,7 @@ module Phaser {
|
||||
{
|
||||
if (this._southWestTree == null)
|
||||
{
|
||||
this._southWestTree = new QuadTree(this._leftEdge, this._midpointY, this._halfWidth, this._halfHeight, this);
|
||||
this._southWestTree = new QuadTree(QuadTree.physics, this._leftEdge, this._midpointY, this._halfWidth, this._halfHeight, this);
|
||||
}
|
||||
|
||||
this._southWestTree.addObject();
|
||||
@@ -621,7 +625,8 @@ module Phaser {
|
||||
continue;
|
||||
}
|
||||
|
||||
if (QuadTree._object.body.bounds.checkHullIntersection(this._checkObject.body.bounds))
|
||||
//if (QuadTree._object.body.bounds.checkHullIntersection(this._checkObject.body.bounds))
|
||||
if (QuadTree.physics.checkHullIntersection(QuadTree._object.body, this._checkObject.body))
|
||||
{
|
||||
//Execute callback functions if they exist
|
||||
if ((QuadTree._processingCallback == null) || QuadTree._processingCallback(QuadTree._object, this._checkObject))
|
||||
|
||||
@@ -139,7 +139,7 @@ module Phaser.Physics {
|
||||
return;
|
||||
}
|
||||
|
||||
this._velocityDelta = (this.computeVelocity(body.angularVelocity, body.angularAcceleration, body.angularDrag, body.maxAngular) - body.angularVelocity) / 2;
|
||||
this._velocityDelta = (this.computeVelocity(body.angularVelocity, body.gravity.x, body.angularAcceleration, body.angularDrag, body.maxAngular) - body.angularVelocity) / 2;
|
||||
body.angularVelocity += this._velocityDelta;
|
||||
body.angle += body.angularVelocity * this.game.time.elapsed;
|
||||
body.angularVelocity += this._velocityDelta;
|
||||
@@ -225,19 +225,8 @@ module Phaser.Physics {
|
||||
|
||||
}
|
||||
|
||||
private checkHullIntersection(body1: Body, body2:Body): bool {
|
||||
|
||||
public checkHullIntersection(body1: Body, body2:Body): bool {
|
||||
return ((body1.hullX + body1.hullWidth > body2.hullX) && (body1.hullX < body2.hullX + body2.hullWidth) && (body1.hullY + body1.hullHeight > body2.hullY) && (body1.hullY < body2.hullY + body2.hullHeight));
|
||||
|
||||
//if ((body1.hullX + body1.hullWidth > body2.hullX) && (body1.hullX < body2.hullX + body2.hullWidth) && (body1.hullY + body1.hullHeight > body2.hullY) && (body1.hullY < body2.hullY + body2.hullHeight))
|
||||
//{
|
||||
// return true;
|
||||
//}
|
||||
//else
|
||||
//{
|
||||
// return false;
|
||||
//}
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -753,7 +742,7 @@ module Phaser.Physics {
|
||||
|
||||
QuadTree.divisions = this.worldDivisions;
|
||||
|
||||
this._quadTree = new QuadTree(this.bounds.x, this.bounds.y, this.bounds.width, this.bounds.height);
|
||||
this._quadTree = new QuadTree(this, this.bounds.x, this.bounds.y, this.bounds.width, this.bounds.height);
|
||||
|
||||
this._quadTree.load(object1, object2, notifyCallback, processCallback, context);
|
||||
|
||||
|
||||
@@ -278,6 +278,8 @@ module Phaser {
|
||||
sprite.y = y;
|
||||
sprite.body.velocity.x = 0;
|
||||
sprite.body.velocity.y = 0;
|
||||
sprite.body.position.x = x;
|
||||
sprite.body.position.y = y;
|
||||
|
||||
}
|
||||
|
||||
|
||||
@@ -28,6 +28,8 @@ TODO:
|
||||
* Copy the setTransform from Sprite to Camera
|
||||
* Move Camera.scroll.x to just Camera.x/y
|
||||
* Apply Sprite scaling to Body.bounds
|
||||
* When you modify the sprite x/y directly the body position doesn't update, which leads to weird results. Need to work out who controls who.
|
||||
|
||||
|
||||
|
||||
V1.0.0
|
||||
|
||||
+17
-3
@@ -66,6 +66,22 @@
|
||||
<DependentUpon>scrollfactor 2.ts</DependentUpon>
|
||||
</Content>
|
||||
<TypeScriptCompile Include="physics\aabb 1.ts" />
|
||||
<TypeScriptCompile Include="particles\graphic emitter.ts" />
|
||||
<Content Include="particles\graphic emitter.js">
|
||||
<DependentUpon>graphic emitter.ts</DependentUpon>
|
||||
</Content>
|
||||
<TypeScriptCompile Include="particles\multiple streams.ts" />
|
||||
<Content Include="particles\multiple streams.js">
|
||||
<DependentUpon>multiple streams.ts</DependentUpon>
|
||||
</Content>
|
||||
<TypeScriptCompile Include="particles\sprite emitter.ts" />
|
||||
<Content Include="particles\sprite emitter.js">
|
||||
<DependentUpon>sprite emitter.ts</DependentUpon>
|
||||
</Content>
|
||||
<TypeScriptCompile Include="particles\when particles collide.ts" />
|
||||
<Content Include="particles\when particles collide.js">
|
||||
<DependentUpon>when particles collide.ts</DependentUpon>
|
||||
</Content>
|
||||
<Content Include="physics\aabb 1.js">
|
||||
<DependentUpon>aabb 1.ts</DependentUpon>
|
||||
</Content>
|
||||
@@ -158,8 +174,6 @@
|
||||
<DependentUpon>boot screen.ts</DependentUpon>
|
||||
</Content>
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<Folder Include="particles\" />
|
||||
</ItemGroup>
|
||||
<ItemGroup />
|
||||
<Import Project="$(VSToolsPath)\TypeScript\Microsoft.TypeScript.targets" />
|
||||
</Project>
|
||||
@@ -0,0 +1,14 @@
|
||||
/// <reference path="../../Phaser/Game.ts" />
|
||||
(function () {
|
||||
var game = new Phaser.Game(this, 'game', 800, 600, init, create);
|
||||
var emitter;
|
||||
function init() {
|
||||
game.loader.addImageFile('jet', 'assets/sprites/jets.png');
|
||||
game.loader.load();
|
||||
}
|
||||
function create() {
|
||||
emitter = game.add.emitter(game.stage.centerX, game.stage.centerY);
|
||||
emitter.makeParticles('jet', 50, false, 0);
|
||||
emitter.start(false, 10, 0.1);
|
||||
}
|
||||
})();
|
||||
@@ -0,0 +1,25 @@
|
||||
/// <reference path="../../Phaser/Game.ts" />
|
||||
|
||||
(function () {
|
||||
|
||||
var game = new Phaser.Game(this, 'game', 800, 600, init, create);
|
||||
|
||||
var emitter: Phaser.Emitter;
|
||||
|
||||
function init() {
|
||||
|
||||
game.loader.addImageFile('jet', 'assets/sprites/jets.png');
|
||||
|
||||
game.loader.load();
|
||||
|
||||
}
|
||||
|
||||
function create() {
|
||||
|
||||
emitter = game.add.emitter(game.stage.centerX, game.stage.centerY);
|
||||
emitter.makeParticles('jet', 50, false, 0);
|
||||
emitter.start(false, 10, 0.1);
|
||||
|
||||
}
|
||||
|
||||
})();
|
||||
@@ -0,0 +1,49 @@
|
||||
/// <reference path="../../Phaser/Game.ts" />
|
||||
(function () {
|
||||
var game = new Phaser.Game(this, 'game', 800, 600, init, create, update);
|
||||
var emitter1;
|
||||
var emitter2;
|
||||
var emitter3;
|
||||
var emitter4;
|
||||
var emitter5;
|
||||
var emitter6;
|
||||
function init() {
|
||||
game.loader.addImageFile('ball1', 'assets/sprites/aqua_ball.png');
|
||||
game.loader.addImageFile('ball2', 'assets/sprites/yellow_ball.png');
|
||||
game.loader.addImageFile('ball3', 'assets/sprites/red_ball.png');
|
||||
game.loader.addImageFile('ball4', 'assets/sprites/purple_ball.png');
|
||||
game.loader.addImageFile('ball5', 'assets/sprites/blue_ball.png');
|
||||
game.loader.addImageFile('ball6', 'assets/sprites/green_ball.png');
|
||||
game.loader.load();
|
||||
}
|
||||
function makeEmitter(emitter, x, y, graphic) {
|
||||
emitter = game.add.emitter(x, y);
|
||||
emitter.gravity = 100;
|
||||
emitter.bounce = 0.5;
|
||||
if(x == 0) {
|
||||
emitter.setXSpeed(200, 250);
|
||||
} else {
|
||||
emitter.setXSpeed(-200, -250);
|
||||
}
|
||||
emitter.setYSpeed(-50, -10);
|
||||
emitter.makeParticles(graphic, 250, false, 0);
|
||||
return emitter;
|
||||
}
|
||||
function create() {
|
||||
emitter1 = makeEmitter(emitter1, 0, 50, 'ball1');
|
||||
emitter2 = makeEmitter(emitter2, 0, 250, 'ball2');
|
||||
emitter3 = makeEmitter(emitter3, 0, 450, 'ball3');
|
||||
emitter4 = makeEmitter(emitter4, game.stage.width, 50, 'ball4');
|
||||
emitter5 = makeEmitter(emitter5, game.stage.width, 250, 'ball5');
|
||||
emitter6 = makeEmitter(emitter6, game.stage.width, 450, 'ball6');
|
||||
emitter1.start(false, 50, 0.05);
|
||||
emitter2.start(false, 50, 0.05);
|
||||
emitter3.start(false, 50, 0.05);
|
||||
emitter4.start(false, 50, 0.05);
|
||||
emitter5.start(false, 50, 0.05);
|
||||
emitter6.start(false, 50, 0.05);
|
||||
}
|
||||
function update() {
|
||||
//game.collide(leftEmitter, rightEmitter);
|
||||
}
|
||||
})();
|
||||
@@ -0,0 +1,73 @@
|
||||
/// <reference path="../../Phaser/Game.ts" />
|
||||
|
||||
(function () {
|
||||
|
||||
var game = new Phaser.Game(this, 'game', 800, 600, init, create, update);
|
||||
|
||||
var emitter1: Phaser.Emitter;
|
||||
var emitter2: Phaser.Emitter;
|
||||
var emitter3: Phaser.Emitter;
|
||||
var emitter4: Phaser.Emitter;
|
||||
var emitter5: Phaser.Emitter;
|
||||
var emitter6: Phaser.Emitter;
|
||||
|
||||
function init() {
|
||||
|
||||
game.loader.addImageFile('ball1', 'assets/sprites/aqua_ball.png');
|
||||
game.loader.addImageFile('ball2', 'assets/sprites/yellow_ball.png');
|
||||
game.loader.addImageFile('ball3', 'assets/sprites/red_ball.png');
|
||||
game.loader.addImageFile('ball4', 'assets/sprites/purple_ball.png');
|
||||
game.loader.addImageFile('ball5', 'assets/sprites/blue_ball.png');
|
||||
game.loader.addImageFile('ball6', 'assets/sprites/green_ball.png');
|
||||
|
||||
game.loader.load();
|
||||
|
||||
}
|
||||
|
||||
function makeEmitter(emitter, x, y, graphic) {
|
||||
|
||||
emitter = game.add.emitter(x, y);
|
||||
emitter.gravity = 100;
|
||||
emitter.bounce = 0.5;
|
||||
|
||||
if (x == 0)
|
||||
{
|
||||
emitter.setXSpeed(200, 250);
|
||||
}
|
||||
else
|
||||
{
|
||||
emitter.setXSpeed(-200, -250);
|
||||
}
|
||||
|
||||
emitter.setYSpeed(-50, -10);
|
||||
emitter.makeParticles(graphic, 250, false, 0);
|
||||
|
||||
return emitter;
|
||||
|
||||
}
|
||||
|
||||
function create() {
|
||||
|
||||
emitter1 = makeEmitter(emitter1, 0, 50, 'ball1');
|
||||
emitter2 = makeEmitter(emitter2, 0, 250, 'ball2');
|
||||
emitter3 = makeEmitter(emitter3, 0, 450, 'ball3');
|
||||
emitter4 = makeEmitter(emitter4, game.stage.width, 50, 'ball4');
|
||||
emitter5 = makeEmitter(emitter5, game.stage.width, 250, 'ball5');
|
||||
emitter6 = makeEmitter(emitter6, game.stage.width, 450, 'ball6');
|
||||
|
||||
emitter1.start(false, 50, 0.05);
|
||||
emitter2.start(false, 50, 0.05);
|
||||
emitter3.start(false, 50, 0.05);
|
||||
emitter4.start(false, 50, 0.05);
|
||||
emitter5.start(false, 50, 0.05);
|
||||
emitter6.start(false, 50, 0.05);
|
||||
|
||||
}
|
||||
|
||||
function update() {
|
||||
|
||||
//game.collide(leftEmitter, rightEmitter);
|
||||
|
||||
}
|
||||
|
||||
})();
|
||||
@@ -0,0 +1,46 @@
|
||||
var __extends = this.__extends || function (d, b) {
|
||||
function __() { this.constructor = d; }
|
||||
__.prototype = b.prototype;
|
||||
d.prototype = new __();
|
||||
};
|
||||
/// <reference path="../../Phaser/Game.ts" />
|
||||
/// <reference path="../../Phaser/gameobjects/Particle.ts" />
|
||||
/// <reference path="../../Phaser/gameobjects/Emitter.ts" />
|
||||
// Actually we could achieve the same result as this by using a sprite sheet and basic Particle
|
||||
// but it still shows you how to use it properly from TypeScript, so it was worth making
|
||||
var customParticle = (function (_super) {
|
||||
__extends(customParticle, _super);
|
||||
function customParticle(game) {
|
||||
_super.call(this, game);
|
||||
var s = [
|
||||
'carrot',
|
||||
'melon',
|
||||
'eggplant',
|
||||
'mushroom',
|
||||
'pineapple'
|
||||
];
|
||||
this.texture.loadImage(game.math.getRandom(s));
|
||||
}
|
||||
return customParticle;
|
||||
})(Phaser.Particle);
|
||||
(function () {
|
||||
var game = new Phaser.Game(this, 'game', 800, 600, init, create);
|
||||
var emitter;
|
||||
function init() {
|
||||
game.loader.addImageFile('carrot', 'assets/sprites/carrot.png');
|
||||
game.loader.addImageFile('melon', 'assets/sprites/melon.png');
|
||||
game.loader.addImageFile('eggplant', 'assets/sprites/eggplant.png');
|
||||
game.loader.addImageFile('mushroom', 'assets/sprites/mushroom.png');
|
||||
game.loader.addImageFile('pineapple', 'assets/sprites/pineapple.png');
|
||||
game.loader.load();
|
||||
}
|
||||
function create() {
|
||||
emitter = game.add.emitter(game.stage.centerX, 50);
|
||||
emitter.gravity = 100;
|
||||
// Here we tell the emitter to use our customParticle class
|
||||
// The customParticle needs to extend Particle and must take game:Game as the first constructor parameter, otherwise it's free as a bird
|
||||
emitter.particleClass = customParticle;
|
||||
emitter.makeParticles(null, 500, false, 0);
|
||||
emitter.start(false, 10, 0.05);
|
||||
}
|
||||
})();
|
||||
@@ -0,0 +1,52 @@
|
||||
/// <reference path="../../Phaser/Game.ts" />
|
||||
/// <reference path="../../Phaser/gameobjects/Particle.ts" />
|
||||
/// <reference path="../../Phaser/gameobjects/Emitter.ts" />
|
||||
|
||||
// Actually we could achieve the same result as this by using a sprite sheet and basic Particle
|
||||
// but it still shows you how to use it properly from TypeScript, so it was worth making
|
||||
class customParticle extends Phaser.Particle {
|
||||
|
||||
constructor(game:Phaser.Game) {
|
||||
|
||||
super(game);
|
||||
|
||||
var s = ['carrot', 'melon', 'eggplant', 'mushroom', 'pineapple'];
|
||||
|
||||
this.texture.loadImage(game.math.getRandom(s));
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
(function () {
|
||||
|
||||
var game = new Phaser.Game(this, 'game', 800, 600, init, create);
|
||||
|
||||
var emitter: Phaser.Emitter;
|
||||
|
||||
function init() {
|
||||
|
||||
game.loader.addImageFile('carrot', 'assets/sprites/carrot.png');
|
||||
game.loader.addImageFile('melon', 'assets/sprites/melon.png');
|
||||
game.loader.addImageFile('eggplant', 'assets/sprites/eggplant.png');
|
||||
game.loader.addImageFile('mushroom', 'assets/sprites/mushroom.png');
|
||||
game.loader.addImageFile('pineapple', 'assets/sprites/pineapple.png');
|
||||
|
||||
game.loader.load();
|
||||
|
||||
}
|
||||
|
||||
function create() {
|
||||
|
||||
emitter = game.add.emitter(game.stage.centerX, 50);
|
||||
emitter.gravity = 100;
|
||||
|
||||
// Here we tell the emitter to use our customParticle class
|
||||
// The customParticle needs to extend Particle and must take game:Game as the first constructor parameter, otherwise it's free as a bird
|
||||
emitter.particleClass = customParticle;
|
||||
|
||||
emitter.makeParticles(null, 500, false, 0);
|
||||
emitter.start(false, 10, 0.05);
|
||||
|
||||
}
|
||||
|
||||
})();
|
||||
@@ -0,0 +1,30 @@
|
||||
/// <reference path="../../Phaser/Game.ts" />
|
||||
(function () {
|
||||
var game = new Phaser.Game(this, 'game', 800, 600, init, create, update);
|
||||
var leftEmitter;
|
||||
var rightEmitter;
|
||||
function init() {
|
||||
game.loader.addImageFile('ball1', 'assets/sprites/aqua_ball.png');
|
||||
game.loader.addImageFile('ball2', 'assets/sprites/yellow_ball.png');
|
||||
game.loader.load();
|
||||
}
|
||||
function create() {
|
||||
leftEmitter = game.add.emitter(0, game.stage.centerY - 200);
|
||||
leftEmitter.gravity = 100;
|
||||
leftEmitter.bounce = 0.5;
|
||||
leftEmitter.setXSpeed(100, 200);
|
||||
leftEmitter.setYSpeed(-50, 50);
|
||||
leftEmitter.makeParticles('ball1', 250, false, 1);
|
||||
rightEmitter = game.add.emitter(game.stage.width + 20, game.stage.centerY - 200);
|
||||
rightEmitter.gravity = 100;
|
||||
rightEmitter.bounce = 0.5;
|
||||
rightEmitter.setXSpeed(-100, -200);
|
||||
rightEmitter.setYSpeed(-50, 50);
|
||||
rightEmitter.makeParticles('ball2', 250, false, 1);
|
||||
leftEmitter.start(false, 50, 0.05);
|
||||
rightEmitter.start(false, 50, 0.05);
|
||||
}
|
||||
function update() {
|
||||
//game.collide(leftEmitter, rightEmitter);
|
||||
}
|
||||
})();
|
||||
@@ -0,0 +1,46 @@
|
||||
/// <reference path="../../Phaser/Game.ts" />
|
||||
|
||||
(function () {
|
||||
|
||||
var game = new Phaser.Game(this, 'game', 800, 600, init, create, update);
|
||||
|
||||
var leftEmitter: Phaser.Emitter;
|
||||
var rightEmitter: Phaser.Emitter;
|
||||
|
||||
function init() {
|
||||
|
||||
game.loader.addImageFile('ball1', 'assets/sprites/aqua_ball.png');
|
||||
game.loader.addImageFile('ball2', 'assets/sprites/yellow_ball.png');
|
||||
|
||||
game.loader.load();
|
||||
|
||||
}
|
||||
|
||||
function create() {
|
||||
|
||||
leftEmitter = game.add.emitter(0, game.stage.centerY - 200);
|
||||
leftEmitter.gravity = 100;
|
||||
leftEmitter.bounce = 0.5;
|
||||
leftEmitter.setXSpeed(100, 200);
|
||||
leftEmitter.setYSpeed(-50, 50);
|
||||
leftEmitter.makeParticles('ball1', 250, false, 1);
|
||||
|
||||
rightEmitter = game.add.emitter(game.stage.width + 20, game.stage.centerY - 200);
|
||||
rightEmitter.gravity = 100;
|
||||
rightEmitter.bounce = 0.5;
|
||||
rightEmitter.setXSpeed(-100, -200);
|
||||
rightEmitter.setYSpeed(-50, 50);
|
||||
rightEmitter.makeParticles('ball2', 250, false, 1);
|
||||
|
||||
leftEmitter.start(false, 50, 0.05);
|
||||
rightEmitter.start(false, 50, 0.05);
|
||||
|
||||
}
|
||||
|
||||
function update() {
|
||||
|
||||
//game.collide(leftEmitter, rightEmitter);
|
||||
|
||||
}
|
||||
|
||||
})();
|
||||
+44
-30
@@ -406,9 +406,10 @@ var Phaser;
|
||||
* @param {Number} height Desired height of this node.
|
||||
* @param {Number} parent The parent branch or node. Pass null to create a root.
|
||||
*/
|
||||
function QuadTree(x, y, width, height, parent) {
|
||||
function QuadTree(manager, x, y, width, height, parent) {
|
||||
if (typeof parent === "undefined") { parent = null; }
|
||||
_super.call(this, x, y, width, height);
|
||||
QuadTree.physics = manager;
|
||||
this._headA = this._tailA = new Phaser.LinkedList();
|
||||
this._headB = this._tailB = new Phaser.LinkedList();
|
||||
//Copy the parent's children (if there are any)
|
||||
@@ -562,14 +563,14 @@ var Phaser;
|
||||
if((QuadTree._object.body.bounds.x > this._leftEdge) && (QuadTree._object.body.bounds.right < this._midpointX)) {
|
||||
if((QuadTree._object.body.bounds.y > this._topEdge) && (QuadTree._object.body.bounds.bottom < this._midpointY)) {
|
||||
if(this._northWestTree == null) {
|
||||
this._northWestTree = new QuadTree(this._leftEdge, this._topEdge, this._halfWidth, this._halfHeight, this);
|
||||
this._northWestTree = new QuadTree(QuadTree.physics, this._leftEdge, this._topEdge, this._halfWidth, this._halfHeight, this);
|
||||
}
|
||||
this._northWestTree.addObject();
|
||||
return;
|
||||
}
|
||||
if((QuadTree._object.body.bounds.y > this._midpointY) && (QuadTree._object.body.bounds.bottom < this._bottomEdge)) {
|
||||
if(this._southWestTree == null) {
|
||||
this._southWestTree = new QuadTree(this._leftEdge, this._midpointY, this._halfWidth, this._halfHeight, this);
|
||||
this._southWestTree = new QuadTree(QuadTree.physics, this._leftEdge, this._midpointY, this._halfWidth, this._halfHeight, this);
|
||||
}
|
||||
this._southWestTree.addObject();
|
||||
return;
|
||||
@@ -578,14 +579,14 @@ var Phaser;
|
||||
if((QuadTree._object.body.bounds.x > this._midpointX) && (QuadTree._object.body.bounds.right < this._rightEdge)) {
|
||||
if((QuadTree._object.body.bounds.y > this._topEdge) && (QuadTree._object.body.bounds.bottom < this._midpointY)) {
|
||||
if(this._northEastTree == null) {
|
||||
this._northEastTree = new QuadTree(this._midpointX, this._topEdge, this._halfWidth, this._halfHeight, this);
|
||||
this._northEastTree = new QuadTree(QuadTree.physics, this._midpointX, this._topEdge, this._halfWidth, this._halfHeight, this);
|
||||
}
|
||||
this._northEastTree.addObject();
|
||||
return;
|
||||
}
|
||||
if((QuadTree._object.body.bounds.y > this._midpointY) && (QuadTree._object.body.bounds.bottom < this._bottomEdge)) {
|
||||
if(this._southEastTree == null) {
|
||||
this._southEastTree = new QuadTree(this._midpointX, this._midpointY, this._halfWidth, this._halfHeight, this);
|
||||
this._southEastTree = new QuadTree(QuadTree.physics, this._midpointX, this._midpointY, this._halfWidth, this._halfHeight, this);
|
||||
}
|
||||
this._southEastTree.addObject();
|
||||
return;
|
||||
@@ -594,25 +595,25 @@ var Phaser;
|
||||
//If it wasn't completely contained we have to check out the partial overlaps
|
||||
if((QuadTree._object.body.bounds.right > this._leftEdge) && (QuadTree._object.body.bounds.x < this._midpointX) && (QuadTree._object.body.bounds.bottom > this._topEdge) && (QuadTree._object.body.bounds.y < this._midpointY)) {
|
||||
if(this._northWestTree == null) {
|
||||
this._northWestTree = new QuadTree(this._leftEdge, this._topEdge, this._halfWidth, this._halfHeight, this);
|
||||
this._northWestTree = new QuadTree(QuadTree.physics, this._leftEdge, this._topEdge, this._halfWidth, this._halfHeight, this);
|
||||
}
|
||||
this._northWestTree.addObject();
|
||||
}
|
||||
if((QuadTree._object.body.bounds.right > this._midpointX) && (QuadTree._object.body.bounds.x < this._rightEdge) && (QuadTree._object.body.bounds.bottom > this._topEdge) && (QuadTree._object.body.bounds.y < this._midpointY)) {
|
||||
if(this._northEastTree == null) {
|
||||
this._northEastTree = new QuadTree(this._midpointX, this._topEdge, this._halfWidth, this._halfHeight, this);
|
||||
this._northEastTree = new QuadTree(QuadTree.physics, this._midpointX, this._topEdge, this._halfWidth, this._halfHeight, this);
|
||||
}
|
||||
this._northEastTree.addObject();
|
||||
}
|
||||
if((QuadTree._object.body.bounds.right > this._midpointX) && (QuadTree._object.body.bounds.x < this._rightEdge) && (QuadTree._object.body.bounds.bottom > this._midpointY) && (QuadTree._object.body.bounds.y < this._bottomEdge)) {
|
||||
if(this._southEastTree == null) {
|
||||
this._southEastTree = new QuadTree(this._midpointX, this._midpointY, this._halfWidth, this._halfHeight, this);
|
||||
this._southEastTree = new QuadTree(QuadTree.physics, this._midpointX, this._midpointY, this._halfWidth, this._halfHeight, this);
|
||||
}
|
||||
this._southEastTree.addObject();
|
||||
}
|
||||
if((QuadTree._object.body.bounds.right > this._leftEdge) && (QuadTree._object.body.bounds.x < this._midpointX) && (QuadTree._object.body.bounds.bottom > this._midpointY) && (QuadTree._object.body.bounds.y < this._bottomEdge)) {
|
||||
if(this._southWestTree == null) {
|
||||
this._southWestTree = new QuadTree(this._leftEdge, this._midpointY, this._halfWidth, this._halfHeight, this);
|
||||
this._southWestTree = new QuadTree(QuadTree.physics, this._leftEdge, this._midpointY, this._halfWidth, this._halfHeight, this);
|
||||
}
|
||||
this._southWestTree.addObject();
|
||||
}
|
||||
@@ -707,7 +708,8 @@ var Phaser;
|
||||
QuadTree._iterator = QuadTree._iterator.next;
|
||||
continue;
|
||||
}
|
||||
if(QuadTree._object.body.bounds.checkHullIntersection(this._checkObject.body.bounds)) {
|
||||
//if (QuadTree._object.body.bounds.checkHullIntersection(this._checkObject.body.bounds))
|
||||
if(QuadTree.physics.checkHullIntersection(QuadTree._object.body, this._checkObject.body)) {
|
||||
//Execute callback functions if they exist
|
||||
if((QuadTree._processingCallback == null) || QuadTree._processingCallback(QuadTree._object, this._checkObject)) {
|
||||
this._overlapProcessed = true;
|
||||
@@ -1351,7 +1353,15 @@ var Phaser;
|
||||
while(this._i < this.length) {
|
||||
this._member = this.members[this._i++];
|
||||
if(this._member != null && this._member.exists && this._member.visible && camera.isHidden(this._member) == false) {
|
||||
this._member.render.call(renderer, camera, this._member);
|
||||
//this._member.render.call(renderer, camera, this._member);
|
||||
// call = context first, then parameters
|
||||
if(this._member.type == Phaser.Types.GROUP) {
|
||||
//console.log('group rend');
|
||||
this._member.render.call(this._member, renderer, camera, this._member);
|
||||
//this._member.render.call(this, renderer, camera, this._member);
|
||||
} else {
|
||||
this._member.render.call(renderer, camera, this._member);
|
||||
}
|
||||
}
|
||||
}
|
||||
if(this.alpha > 0) {
|
||||
@@ -5284,6 +5294,8 @@ var Phaser;
|
||||
sprite.y = y;
|
||||
sprite.body.velocity.x = 0;
|
||||
sprite.body.velocity.y = 0;
|
||||
sprite.body.position.x = x;
|
||||
sprite.body.position.y = y;
|
||||
};
|
||||
SpriteUtils.setBounds = /**
|
||||
* Set the world bounds that this GameObject can exist within. By default a GameObject can exist anywhere
|
||||
@@ -5408,8 +5420,9 @@ var Phaser;
|
||||
* @param clearAnimations {boolean} If this Sprite has a set of animation data already loaded you can choose to keep or clear it with this boolean
|
||||
* @return {Sprite} Sprite instance itself.
|
||||
*/
|
||||
function (key, clearAnimations) {
|
||||
function (key, clearAnimations, updateBody) {
|
||||
if (typeof clearAnimations === "undefined") { clearAnimations = true; }
|
||||
if (typeof updateBody === "undefined") { updateBody = true; }
|
||||
if(clearAnimations && this._sprite.animations.frameData !== null) {
|
||||
this._sprite.animations.destroy();
|
||||
}
|
||||
@@ -5421,6 +5434,10 @@ var Phaser;
|
||||
this._sprite.frameBounds.width = this.width;
|
||||
this._sprite.frameBounds.height = this.height;
|
||||
}
|
||||
if(updateBody) {
|
||||
this._sprite.body.bounds.width = this.width;
|
||||
this._sprite.body.bounds.height = this.height;
|
||||
}
|
||||
}
|
||||
};
|
||||
Texture.prototype.loadDynamicTexture = /**
|
||||
@@ -7563,6 +7580,7 @@ var Phaser;
|
||||
*/
|
||||
function Particle(game) {
|
||||
_super.call(this, game);
|
||||
this.body.type = Phaser.Types.BODY_DYNAMIC;
|
||||
this.lifespan = 0;
|
||||
this.friction = 500;
|
||||
}
|
||||
@@ -7571,7 +7589,7 @@ var Phaser;
|
||||
* be dead yet, and then has some special bounce behavior if there is some gravity on it.
|
||||
*/
|
||||
function () {
|
||||
//lifespan behavior
|
||||
// Lifespan behavior
|
||||
if(this.lifespan <= 0) {
|
||||
return;
|
||||
}
|
||||
@@ -7609,6 +7627,7 @@ var Phaser;
|
||||
* You can override this to add custom behavior like a sound or AI or something.
|
||||
*/
|
||||
function () {
|
||||
console.log('particle emitted', this.width, this.height);
|
||||
};
|
||||
return Particle;
|
||||
})(Phaser.Sprite);
|
||||
@@ -7660,6 +7679,9 @@ var Phaser;
|
||||
this._counter = 0;
|
||||
this._explode = true;
|
||||
this.on = false;
|
||||
this.exists = true;
|
||||
this.active = true;
|
||||
this.visible = true;
|
||||
}
|
||||
Emitter.prototype.destroy = /**
|
||||
* Clean up memory.
|
||||
@@ -7718,12 +7740,6 @@ var Phaser;
|
||||
}
|
||||
*/
|
||||
} else {
|
||||
/*
|
||||
if (BakedRotations > 0)
|
||||
particle.loadRotatedGraphic(Graphics,BakedRotations);
|
||||
else
|
||||
particle.loadGraphic(Graphics);
|
||||
*/
|
||||
if(graphics) {
|
||||
particle.texture.loadImage(graphics);
|
||||
}
|
||||
@@ -7737,11 +7753,17 @@ var Phaser;
|
||||
particle.body.allowCollisions = Phaser.Types.NONE;
|
||||
}
|
||||
particle.exists = false;
|
||||
// Center it
|
||||
particle.origin.setTo(particle.body.bounds.halfWidth, particle.body.bounds.halfHeight);
|
||||
this.add(particle);
|
||||
i++;
|
||||
}
|
||||
return this;
|
||||
};
|
||||
Emitter.prototype.preUpdate = function () {
|
||||
};
|
||||
Emitter.prototype.postUpdate = function () {
|
||||
};
|
||||
Emitter.prototype.update = /**
|
||||
* Called automatically by the game loop, decides when to launch particles and when to "die".
|
||||
*/
|
||||
@@ -10646,7 +10668,7 @@ var Phaser;
|
||||
if(body.type == Phaser.Types.BODY_DISABLED) {
|
||||
return;
|
||||
}
|
||||
this._velocityDelta = (this.computeVelocity(body.angularVelocity, body.angularAcceleration, body.angularDrag, body.maxAngular) - body.angularVelocity) / 2;
|
||||
this._velocityDelta = (this.computeVelocity(body.angularVelocity, body.gravity.x, body.angularAcceleration, body.angularDrag, body.maxAngular) - body.angularVelocity) / 2;
|
||||
body.angularVelocity += this._velocityDelta;
|
||||
body.angle += body.angularVelocity * this.game.time.elapsed;
|
||||
body.angularVelocity += this._velocityDelta;
|
||||
@@ -10711,15 +10733,7 @@ var Phaser;
|
||||
};
|
||||
PhysicsManager.prototype.checkHullIntersection = function (body1, body2) {
|
||||
return ((body1.hullX + body1.hullWidth > body2.hullX) && (body1.hullX < body2.hullX + body2.hullWidth) && (body1.hullY + body1.hullHeight > body2.hullY) && (body1.hullY < body2.hullY + body2.hullHeight));
|
||||
//if ((body1.hullX + body1.hullWidth > body2.hullX) && (body1.hullX < body2.hullX + body2.hullWidth) && (body1.hullY + body1.hullHeight > body2.hullY) && (body1.hullY < body2.hullY + body2.hullHeight))
|
||||
//{
|
||||
// return true;
|
||||
//}
|
||||
//else
|
||||
//{
|
||||
// return false;
|
||||
//}
|
||||
};
|
||||
};
|
||||
PhysicsManager.prototype.separateBodyX = /**
|
||||
* Separates the two objects on their x axis
|
||||
* @param object1 The first GameObject to separate
|
||||
@@ -11158,7 +11172,7 @@ var Phaser;
|
||||
object2 = null;
|
||||
}
|
||||
Phaser.QuadTree.divisions = this.worldDivisions;
|
||||
this._quadTree = new Phaser.QuadTree(this.bounds.x, this.bounds.y, this.bounds.width, this.bounds.height);
|
||||
this._quadTree = new Phaser.QuadTree(this, this.bounds.x, this.bounds.y, this.bounds.width, this.bounds.height);
|
||||
this._quadTree.load(object1, object2, notifyCallback, processCallback, context);
|
||||
this._quadTreeResult = this._quadTree.execute();
|
||||
this._quadTree.destroy();
|
||||
|
||||
@@ -16,7 +16,7 @@
|
||||
// This will cause it to rotate on its center
|
||||
fuji.origin.setTo(160, 100);
|
||||
game.add.tween(fuji).to({
|
||||
rotation: 360
|
||||
angle: 360
|
||||
}, 2000, Phaser.Easing.Linear.None, true, 0, true);
|
||||
}
|
||||
})();
|
||||
|
||||
@@ -26,7 +26,7 @@
|
||||
// This will cause it to rotate on its center
|
||||
fuji.origin.setTo(160, 100);
|
||||
|
||||
game.add.tween(fuji).to({ rotation: 360 }, 2000, Phaser.Easing.Linear.None, true, 0, true);
|
||||
game.add.tween(fuji).to({ angle: 360 }, 2000, Phaser.Easing.Linear.None, true, 0, true);
|
||||
|
||||
}
|
||||
|
||||
|
||||
@@ -16,7 +16,7 @@
|
||||
// Here we set the origin to be the bottom-right of the sprite
|
||||
fuji.origin.setTo(320, 200);
|
||||
game.add.tween(fuji).to({
|
||||
rotation: 360
|
||||
angle: 360
|
||||
}, 2000, Phaser.Easing.Linear.None, true, 0, true);
|
||||
}
|
||||
})();
|
||||
|
||||
@@ -26,7 +26,7 @@
|
||||
// Here we set the origin to be the bottom-right of the sprite
|
||||
fuji.origin.setTo(320, 200);
|
||||
|
||||
game.add.tween(fuji).to({ rotation: 360 }, 2000, Phaser.Easing.Linear.None, true, 0, true);
|
||||
game.add.tween(fuji).to({ angle: 360 }, 2000, Phaser.Easing.Linear.None, true, 0, true);
|
||||
|
||||
}
|
||||
|
||||
|
||||
@@ -17,7 +17,7 @@
|
||||
// Here we set the origin to the center of the sprite again, so we can rotate and scale it at the same time
|
||||
fuji.origin.setTo(160, 100);
|
||||
game.add.tween(fuji).to({
|
||||
rotation: 360
|
||||
angle: 360
|
||||
}, 2000, Phaser.Easing.Linear.None, true, 0, true);
|
||||
tweenUp = game.add.tween(fuji.scale);
|
||||
tweenUp.onComplete.add(scaleDown, this);
|
||||
|
||||
@@ -27,7 +27,7 @@
|
||||
// Here we set the origin to the center of the sprite again, so we can rotate and scale it at the same time
|
||||
fuji.origin.setTo(160, 100);
|
||||
|
||||
game.add.tween(fuji).to({ rotation: 360 }, 2000, Phaser.Easing.Linear.None, true, 0, true);
|
||||
game.add.tween(fuji).to({ angle: 360 }, 2000, Phaser.Easing.Linear.None, true, 0, true);
|
||||
|
||||
tweenUp = game.add.tween(fuji.scale);
|
||||
tweenUp.onComplete.add(scaleDown, this);
|
||||
|
||||
@@ -12,9 +12,11 @@
|
||||
swirl = game.add.sprite(game.stage.centerX, game.stage.centerY, 'swirl');
|
||||
// Increase the size of the sprite a little so it covers the edges of the stage
|
||||
swirl.scale.setTo(1.4, 1.4);
|
||||
// Set the origin to the middle of the Sprite to get the effect we need
|
||||
swirl.origin.setTo(swirl.frameBounds.halfWidth, swirl.frameBounds.halfHeight);
|
||||
// Create a tween that rotates a full 306 degrees and then repeats (loop set to true)
|
||||
game.add.tween(swirl).to({
|
||||
rotation: 360
|
||||
angle: 360
|
||||
}, 2000, Phaser.Easing.Linear.None, true, 0, true);
|
||||
}
|
||||
})();
|
||||
|
||||
@@ -22,8 +22,11 @@
|
||||
// Increase the size of the sprite a little so it covers the edges of the stage
|
||||
swirl.scale.setTo(1.4, 1.4);
|
||||
|
||||
// Set the origin to the middle of the Sprite to get the effect we need
|
||||
swirl.origin.setTo(swirl.frameBounds.halfWidth, swirl.frameBounds.halfHeight);
|
||||
|
||||
// Create a tween that rotates a full 306 degrees and then repeats (loop set to true)
|
||||
game.add.tween(swirl).to({ rotation: 360 }, 2000, Phaser.Easing.Linear.None, true, 0, true);
|
||||
game.add.tween(swirl).to({ angle: 360 }, 2000, Phaser.Easing.Linear.None, true, 0, true);
|
||||
|
||||
}
|
||||
|
||||
|
||||
@@ -12,8 +12,12 @@
|
||||
swirl = game.add.sprite(game.stage.centerX, game.stage.centerY, 'swirl');
|
||||
// Increase the size of the sprite a little so it covers the edges of the stage
|
||||
swirl.scale.setTo(1.4, 1.4);
|
||||
// Set the origin to the middle of the Sprite to get the effect we need
|
||||
swirl.origin.setTo(swirl.frameBounds.halfWidth, swirl.frameBounds.halfHeight);
|
||||
// Create a tween that rotates a full 306 degrees and then repeats (loop set to true)
|
||||
//game.add.tween(swirl).to({ rotation: 360 }, 2000, Phaser.Easing.Linear.None, true, 0, true);
|
||||
game.add.tween(swirl).to({
|
||||
angle: 360
|
||||
}, 2000, Phaser.Easing.Linear.None, true, 0, true);
|
||||
game.add.tween(swirl.scale).to({
|
||||
x: 4,
|
||||
y: 4
|
||||
|
||||
@@ -22,8 +22,11 @@
|
||||
// Increase the size of the sprite a little so it covers the edges of the stage
|
||||
swirl.scale.setTo(1.4, 1.4);
|
||||
|
||||
// Set the origin to the middle of the Sprite to get the effect we need
|
||||
swirl.origin.setTo(swirl.frameBounds.halfWidth, swirl.frameBounds.halfHeight);
|
||||
|
||||
// Create a tween that rotates a full 306 degrees and then repeats (loop set to true)
|
||||
//game.add.tween(swirl).to({ rotation: 360 }, 2000, Phaser.Easing.Linear.None, true, 0, true);
|
||||
game.add.tween(swirl).to({ angle: 360 }, 2000, Phaser.Easing.Linear.None, true, 0, true);
|
||||
game.add.tween(swirl.scale).to({ x: 4, y: 4 }, 1000, Phaser.Easing.Linear.None, true, 0, true, true);
|
||||
|
||||
}
|
||||
|
||||
Vendored
+10
-3
@@ -320,7 +320,7 @@ module Phaser {
|
||||
* @param {Number} height Desired height of this node.
|
||||
* @param {Number} parent The parent branch or node. Pass null to create a root.
|
||||
*/
|
||||
constructor(x: number, y: number, width: number, height: number, parent?: QuadTree);
|
||||
constructor(manager: Physics.PhysicsManager, x: number, y: number, width: number, height: number, parent?: QuadTree);
|
||||
private _iterator;
|
||||
private _ot;
|
||||
private _i;
|
||||
@@ -329,6 +329,7 @@ module Phaser {
|
||||
private _l;
|
||||
private _overlapProcessed;
|
||||
private _checkObject;
|
||||
static physics: Physics.PhysicsManager;
|
||||
/**
|
||||
* Flag for specifying that you want to add an object to the A list.
|
||||
*/
|
||||
@@ -3178,7 +3179,7 @@ module Phaser.Components {
|
||||
* @param clearAnimations {boolean} If this Sprite has a set of animation data already loaded you can choose to keep or clear it with this boolean
|
||||
* @return {Sprite} Sprite instance itself.
|
||||
*/
|
||||
public loadImage(key: string, clearAnimations?: bool): void;
|
||||
public loadImage(key: string, clearAnimations?: bool, updateBody?: bool): void;
|
||||
/**
|
||||
* Load a DynamicTexture as its texture.
|
||||
* @param texture {DynamicTexture} The texture object to be used by this sprite.
|
||||
@@ -4298,6 +4299,10 @@ module Phaser {
|
||||
*/
|
||||
public alive: bool;
|
||||
/**
|
||||
*
|
||||
*/
|
||||
public active: bool;
|
||||
/**
|
||||
* The minimum possible velocity of a particle.
|
||||
* The default value is (-100,-100).
|
||||
*/
|
||||
@@ -4383,6 +4388,8 @@ module Phaser {
|
||||
* @return This Emitter instance (nice for chaining stuff together, if you're into that).
|
||||
*/
|
||||
public makeParticles(graphics, quantity?: number, multiple?: bool, collide?: number): Emitter;
|
||||
public preUpdate(): void;
|
||||
public postUpdate(): void;
|
||||
/**
|
||||
* Called automatically by the game loop, decides when to launch particles and when to "die".
|
||||
*/
|
||||
@@ -6133,7 +6140,7 @@ module Phaser.Physics {
|
||||
* @returns {boolean} Returns true if the bodies were separated, otherwise false.
|
||||
*/
|
||||
public separate(body1: Body, body2: Body): bool;
|
||||
private checkHullIntersection(body1, body2);
|
||||
public checkHullIntersection(body1: Body, body2: Body): bool;
|
||||
/**
|
||||
* Separates the two objects on their x axis
|
||||
* @param object1 The first GameObject to separate
|
||||
|
||||
+44
-30
@@ -406,9 +406,10 @@ var Phaser;
|
||||
* @param {Number} height Desired height of this node.
|
||||
* @param {Number} parent The parent branch or node. Pass null to create a root.
|
||||
*/
|
||||
function QuadTree(x, y, width, height, parent) {
|
||||
function QuadTree(manager, x, y, width, height, parent) {
|
||||
if (typeof parent === "undefined") { parent = null; }
|
||||
_super.call(this, x, y, width, height);
|
||||
QuadTree.physics = manager;
|
||||
this._headA = this._tailA = new Phaser.LinkedList();
|
||||
this._headB = this._tailB = new Phaser.LinkedList();
|
||||
//Copy the parent's children (if there are any)
|
||||
@@ -562,14 +563,14 @@ var Phaser;
|
||||
if((QuadTree._object.body.bounds.x > this._leftEdge) && (QuadTree._object.body.bounds.right < this._midpointX)) {
|
||||
if((QuadTree._object.body.bounds.y > this._topEdge) && (QuadTree._object.body.bounds.bottom < this._midpointY)) {
|
||||
if(this._northWestTree == null) {
|
||||
this._northWestTree = new QuadTree(this._leftEdge, this._topEdge, this._halfWidth, this._halfHeight, this);
|
||||
this._northWestTree = new QuadTree(QuadTree.physics, this._leftEdge, this._topEdge, this._halfWidth, this._halfHeight, this);
|
||||
}
|
||||
this._northWestTree.addObject();
|
||||
return;
|
||||
}
|
||||
if((QuadTree._object.body.bounds.y > this._midpointY) && (QuadTree._object.body.bounds.bottom < this._bottomEdge)) {
|
||||
if(this._southWestTree == null) {
|
||||
this._southWestTree = new QuadTree(this._leftEdge, this._midpointY, this._halfWidth, this._halfHeight, this);
|
||||
this._southWestTree = new QuadTree(QuadTree.physics, this._leftEdge, this._midpointY, this._halfWidth, this._halfHeight, this);
|
||||
}
|
||||
this._southWestTree.addObject();
|
||||
return;
|
||||
@@ -578,14 +579,14 @@ var Phaser;
|
||||
if((QuadTree._object.body.bounds.x > this._midpointX) && (QuadTree._object.body.bounds.right < this._rightEdge)) {
|
||||
if((QuadTree._object.body.bounds.y > this._topEdge) && (QuadTree._object.body.bounds.bottom < this._midpointY)) {
|
||||
if(this._northEastTree == null) {
|
||||
this._northEastTree = new QuadTree(this._midpointX, this._topEdge, this._halfWidth, this._halfHeight, this);
|
||||
this._northEastTree = new QuadTree(QuadTree.physics, this._midpointX, this._topEdge, this._halfWidth, this._halfHeight, this);
|
||||
}
|
||||
this._northEastTree.addObject();
|
||||
return;
|
||||
}
|
||||
if((QuadTree._object.body.bounds.y > this._midpointY) && (QuadTree._object.body.bounds.bottom < this._bottomEdge)) {
|
||||
if(this._southEastTree == null) {
|
||||
this._southEastTree = new QuadTree(this._midpointX, this._midpointY, this._halfWidth, this._halfHeight, this);
|
||||
this._southEastTree = new QuadTree(QuadTree.physics, this._midpointX, this._midpointY, this._halfWidth, this._halfHeight, this);
|
||||
}
|
||||
this._southEastTree.addObject();
|
||||
return;
|
||||
@@ -594,25 +595,25 @@ var Phaser;
|
||||
//If it wasn't completely contained we have to check out the partial overlaps
|
||||
if((QuadTree._object.body.bounds.right > this._leftEdge) && (QuadTree._object.body.bounds.x < this._midpointX) && (QuadTree._object.body.bounds.bottom > this._topEdge) && (QuadTree._object.body.bounds.y < this._midpointY)) {
|
||||
if(this._northWestTree == null) {
|
||||
this._northWestTree = new QuadTree(this._leftEdge, this._topEdge, this._halfWidth, this._halfHeight, this);
|
||||
this._northWestTree = new QuadTree(QuadTree.physics, this._leftEdge, this._topEdge, this._halfWidth, this._halfHeight, this);
|
||||
}
|
||||
this._northWestTree.addObject();
|
||||
}
|
||||
if((QuadTree._object.body.bounds.right > this._midpointX) && (QuadTree._object.body.bounds.x < this._rightEdge) && (QuadTree._object.body.bounds.bottom > this._topEdge) && (QuadTree._object.body.bounds.y < this._midpointY)) {
|
||||
if(this._northEastTree == null) {
|
||||
this._northEastTree = new QuadTree(this._midpointX, this._topEdge, this._halfWidth, this._halfHeight, this);
|
||||
this._northEastTree = new QuadTree(QuadTree.physics, this._midpointX, this._topEdge, this._halfWidth, this._halfHeight, this);
|
||||
}
|
||||
this._northEastTree.addObject();
|
||||
}
|
||||
if((QuadTree._object.body.bounds.right > this._midpointX) && (QuadTree._object.body.bounds.x < this._rightEdge) && (QuadTree._object.body.bounds.bottom > this._midpointY) && (QuadTree._object.body.bounds.y < this._bottomEdge)) {
|
||||
if(this._southEastTree == null) {
|
||||
this._southEastTree = new QuadTree(this._midpointX, this._midpointY, this._halfWidth, this._halfHeight, this);
|
||||
this._southEastTree = new QuadTree(QuadTree.physics, this._midpointX, this._midpointY, this._halfWidth, this._halfHeight, this);
|
||||
}
|
||||
this._southEastTree.addObject();
|
||||
}
|
||||
if((QuadTree._object.body.bounds.right > this._leftEdge) && (QuadTree._object.body.bounds.x < this._midpointX) && (QuadTree._object.body.bounds.bottom > this._midpointY) && (QuadTree._object.body.bounds.y < this._bottomEdge)) {
|
||||
if(this._southWestTree == null) {
|
||||
this._southWestTree = new QuadTree(this._leftEdge, this._midpointY, this._halfWidth, this._halfHeight, this);
|
||||
this._southWestTree = new QuadTree(QuadTree.physics, this._leftEdge, this._midpointY, this._halfWidth, this._halfHeight, this);
|
||||
}
|
||||
this._southWestTree.addObject();
|
||||
}
|
||||
@@ -707,7 +708,8 @@ var Phaser;
|
||||
QuadTree._iterator = QuadTree._iterator.next;
|
||||
continue;
|
||||
}
|
||||
if(QuadTree._object.body.bounds.checkHullIntersection(this._checkObject.body.bounds)) {
|
||||
//if (QuadTree._object.body.bounds.checkHullIntersection(this._checkObject.body.bounds))
|
||||
if(QuadTree.physics.checkHullIntersection(QuadTree._object.body, this._checkObject.body)) {
|
||||
//Execute callback functions if they exist
|
||||
if((QuadTree._processingCallback == null) || QuadTree._processingCallback(QuadTree._object, this._checkObject)) {
|
||||
this._overlapProcessed = true;
|
||||
@@ -1351,7 +1353,15 @@ var Phaser;
|
||||
while(this._i < this.length) {
|
||||
this._member = this.members[this._i++];
|
||||
if(this._member != null && this._member.exists && this._member.visible && camera.isHidden(this._member) == false) {
|
||||
this._member.render.call(renderer, camera, this._member);
|
||||
//this._member.render.call(renderer, camera, this._member);
|
||||
// call = context first, then parameters
|
||||
if(this._member.type == Phaser.Types.GROUP) {
|
||||
//console.log('group rend');
|
||||
this._member.render.call(this._member, renderer, camera, this._member);
|
||||
//this._member.render.call(this, renderer, camera, this._member);
|
||||
} else {
|
||||
this._member.render.call(renderer, camera, this._member);
|
||||
}
|
||||
}
|
||||
}
|
||||
if(this.alpha > 0) {
|
||||
@@ -5284,6 +5294,8 @@ var Phaser;
|
||||
sprite.y = y;
|
||||
sprite.body.velocity.x = 0;
|
||||
sprite.body.velocity.y = 0;
|
||||
sprite.body.position.x = x;
|
||||
sprite.body.position.y = y;
|
||||
};
|
||||
SpriteUtils.setBounds = /**
|
||||
* Set the world bounds that this GameObject can exist within. By default a GameObject can exist anywhere
|
||||
@@ -5408,8 +5420,9 @@ var Phaser;
|
||||
* @param clearAnimations {boolean} If this Sprite has a set of animation data already loaded you can choose to keep or clear it with this boolean
|
||||
* @return {Sprite} Sprite instance itself.
|
||||
*/
|
||||
function (key, clearAnimations) {
|
||||
function (key, clearAnimations, updateBody) {
|
||||
if (typeof clearAnimations === "undefined") { clearAnimations = true; }
|
||||
if (typeof updateBody === "undefined") { updateBody = true; }
|
||||
if(clearAnimations && this._sprite.animations.frameData !== null) {
|
||||
this._sprite.animations.destroy();
|
||||
}
|
||||
@@ -5421,6 +5434,10 @@ var Phaser;
|
||||
this._sprite.frameBounds.width = this.width;
|
||||
this._sprite.frameBounds.height = this.height;
|
||||
}
|
||||
if(updateBody) {
|
||||
this._sprite.body.bounds.width = this.width;
|
||||
this._sprite.body.bounds.height = this.height;
|
||||
}
|
||||
}
|
||||
};
|
||||
Texture.prototype.loadDynamicTexture = /**
|
||||
@@ -7563,6 +7580,7 @@ var Phaser;
|
||||
*/
|
||||
function Particle(game) {
|
||||
_super.call(this, game);
|
||||
this.body.type = Phaser.Types.BODY_DYNAMIC;
|
||||
this.lifespan = 0;
|
||||
this.friction = 500;
|
||||
}
|
||||
@@ -7571,7 +7589,7 @@ var Phaser;
|
||||
* be dead yet, and then has some special bounce behavior if there is some gravity on it.
|
||||
*/
|
||||
function () {
|
||||
//lifespan behavior
|
||||
// Lifespan behavior
|
||||
if(this.lifespan <= 0) {
|
||||
return;
|
||||
}
|
||||
@@ -7609,6 +7627,7 @@ var Phaser;
|
||||
* You can override this to add custom behavior like a sound or AI or something.
|
||||
*/
|
||||
function () {
|
||||
console.log('particle emitted', this.width, this.height);
|
||||
};
|
||||
return Particle;
|
||||
})(Phaser.Sprite);
|
||||
@@ -7660,6 +7679,9 @@ var Phaser;
|
||||
this._counter = 0;
|
||||
this._explode = true;
|
||||
this.on = false;
|
||||
this.exists = true;
|
||||
this.active = true;
|
||||
this.visible = true;
|
||||
}
|
||||
Emitter.prototype.destroy = /**
|
||||
* Clean up memory.
|
||||
@@ -7718,12 +7740,6 @@ var Phaser;
|
||||
}
|
||||
*/
|
||||
} else {
|
||||
/*
|
||||
if (BakedRotations > 0)
|
||||
particle.loadRotatedGraphic(Graphics,BakedRotations);
|
||||
else
|
||||
particle.loadGraphic(Graphics);
|
||||
*/
|
||||
if(graphics) {
|
||||
particle.texture.loadImage(graphics);
|
||||
}
|
||||
@@ -7737,11 +7753,17 @@ var Phaser;
|
||||
particle.body.allowCollisions = Phaser.Types.NONE;
|
||||
}
|
||||
particle.exists = false;
|
||||
// Center it
|
||||
particle.origin.setTo(particle.body.bounds.halfWidth, particle.body.bounds.halfHeight);
|
||||
this.add(particle);
|
||||
i++;
|
||||
}
|
||||
return this;
|
||||
};
|
||||
Emitter.prototype.preUpdate = function () {
|
||||
};
|
||||
Emitter.prototype.postUpdate = function () {
|
||||
};
|
||||
Emitter.prototype.update = /**
|
||||
* Called automatically by the game loop, decides when to launch particles and when to "die".
|
||||
*/
|
||||
@@ -10646,7 +10668,7 @@ var Phaser;
|
||||
if(body.type == Phaser.Types.BODY_DISABLED) {
|
||||
return;
|
||||
}
|
||||
this._velocityDelta = (this.computeVelocity(body.angularVelocity, body.angularAcceleration, body.angularDrag, body.maxAngular) - body.angularVelocity) / 2;
|
||||
this._velocityDelta = (this.computeVelocity(body.angularVelocity, body.gravity.x, body.angularAcceleration, body.angularDrag, body.maxAngular) - body.angularVelocity) / 2;
|
||||
body.angularVelocity += this._velocityDelta;
|
||||
body.angle += body.angularVelocity * this.game.time.elapsed;
|
||||
body.angularVelocity += this._velocityDelta;
|
||||
@@ -10711,15 +10733,7 @@ var Phaser;
|
||||
};
|
||||
PhysicsManager.prototype.checkHullIntersection = function (body1, body2) {
|
||||
return ((body1.hullX + body1.hullWidth > body2.hullX) && (body1.hullX < body2.hullX + body2.hullWidth) && (body1.hullY + body1.hullHeight > body2.hullY) && (body1.hullY < body2.hullY + body2.hullHeight));
|
||||
//if ((body1.hullX + body1.hullWidth > body2.hullX) && (body1.hullX < body2.hullX + body2.hullWidth) && (body1.hullY + body1.hullHeight > body2.hullY) && (body1.hullY < body2.hullY + body2.hullHeight))
|
||||
//{
|
||||
// return true;
|
||||
//}
|
||||
//else
|
||||
//{
|
||||
// return false;
|
||||
//}
|
||||
};
|
||||
};
|
||||
PhysicsManager.prototype.separateBodyX = /**
|
||||
* Separates the two objects on their x axis
|
||||
* @param object1 The first GameObject to separate
|
||||
@@ -11158,7 +11172,7 @@ var Phaser;
|
||||
object2 = null;
|
||||
}
|
||||
Phaser.QuadTree.divisions = this.worldDivisions;
|
||||
this._quadTree = new Phaser.QuadTree(this.bounds.x, this.bounds.y, this.bounds.width, this.bounds.height);
|
||||
this._quadTree = new Phaser.QuadTree(this, this.bounds.x, this.bounds.y, this.bounds.width, this.bounds.height);
|
||||
this._quadTree.load(object1, object2, notifyCallback, processCallback, context);
|
||||
this._quadTreeResult = this._quadTree.execute();
|
||||
this._quadTree.destroy();
|
||||
|
||||
Reference in New Issue
Block a user