mirror of
https://github.com/photonstorm/phaser
synced 2024-09-20 14:31:55 +00:00
Working my way through putting all the Tests back in and fixing issues as I go.
This commit is contained in:
parent
31c4d8cb14
commit
b20a6ff85a
22 changed files with 602 additions and 214 deletions
|
@ -174,7 +174,7 @@ module Phaser {
|
|||
* Calls render on all members of this Group who have a status of visible=true and exists=true
|
||||
* You can also call Object.render directly, which will bypass the visible/exists check.
|
||||
*/
|
||||
public render(renderer:IRenderer, camera: Camera) {
|
||||
public render(camera: Camera) {
|
||||
|
||||
if (camera.isHidden(this) == true)
|
||||
{
|
||||
|
@ -201,17 +201,13 @@ 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);
|
||||
// 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);
|
||||
this._member.render(camera);
|
||||
}
|
||||
else
|
||||
{
|
||||
this._member.render.call(renderer, camera, this._member);
|
||||
this.game.renderer.renderGameObject(this._member);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -225,6 +221,7 @@ module Phaser {
|
|||
{
|
||||
this.game.stage.context.restore();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -32,7 +32,7 @@ module Phaser {
|
|||
/**
|
||||
* Reference to the Renderer.renderSprite method. Can be overriden by custom classes.
|
||||
*/
|
||||
render;
|
||||
//render;
|
||||
|
||||
/**
|
||||
* Controls if both <code>update</code> and render are called by the core game loop.
|
||||
|
|
|
@ -31,7 +31,6 @@ module Phaser {
|
|||
super(game, x, y, key);
|
||||
|
||||
this.type = Phaser.Types.SCROLLZONE;
|
||||
this.render = game.renderer.renderScrollZone;
|
||||
|
||||
this.regions = [];
|
||||
|
||||
|
|
|
@ -27,7 +27,6 @@ module Phaser {
|
|||
|
||||
this.game = game;
|
||||
this.type = Phaser.Types.SPRITE;
|
||||
this.render = game.renderer.renderSprite;
|
||||
|
||||
this.exists = true;
|
||||
this.active = true;
|
||||
|
@ -42,6 +41,9 @@ module Phaser {
|
|||
this.y = y;
|
||||
this.z = 0; // not used yet
|
||||
|
||||
// If a texture has been given the body will be set to that size, otherwise 16x16
|
||||
this.body = new Phaser.Physics.Body(this, bodyType);
|
||||
|
||||
this.animations = new Phaser.Components.AnimationManager(this);
|
||||
this.texture = new Phaser.Components.Texture(this, key);
|
||||
this.cameraBlacklist = [];
|
||||
|
@ -50,10 +52,6 @@ module Phaser {
|
|||
this.origin = new Phaser.Vec2(0, 0);
|
||||
this.scale = new Phaser.Vec2(1, 1);
|
||||
this.skew = new Phaser.Vec2(0, 0);
|
||||
|
||||
// If a texture has been given the body will be set to that size, otherwise 16x16
|
||||
this.body = new Phaser.Physics.Body(this, bodyType);
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -66,11 +64,6 @@ module Phaser {
|
|||
*/
|
||||
public type: number;
|
||||
|
||||
/**
|
||||
* Reference to the Renderer.renderSprite method. Can be overriden by custom classes.
|
||||
*/
|
||||
public render;
|
||||
|
||||
/**
|
||||
* Controls if both <code>update</code> and render are called by the core game loop.
|
||||
*/
|
||||
|
|
|
@ -270,9 +270,10 @@ module Phaser.Physics {
|
|||
this.parent.texture.context.fillStyle = color;
|
||||
this.parent.texture.context.fillText('Sprite: (' + this.parent.frameBounds.width + ' x ' + this.parent.frameBounds.height + ')', x, y);
|
||||
//this.parent.texture.context.fillText('x: ' + this._parent.frameBounds.x.toFixed(1) + ' y: ' + this._parent.frameBounds.y.toFixed(1) + ' rotation: ' + this._parent.rotation.toFixed(1), x, y + 14);
|
||||
this.parent.texture.context.fillText('x: ' + this.bounds.x.toFixed(1) + ' y: ' + this.bounds.y.toFixed(1) + ' angle: ' + this.angle.toFixed(1), x, y + 14);
|
||||
this.parent.texture.context.fillText('x: ' + this.bounds.x.toFixed(1) + ' y: ' + this.bounds.y.toFixed(1) + ' angle: ' + this.angle.toFixed(0), x, y + 14);
|
||||
this.parent.texture.context.fillText('vx: ' + this.velocity.x.toFixed(1) + ' vy: ' + this.velocity.y.toFixed(1), x, y + 28);
|
||||
this.parent.texture.context.fillText('ax: ' + this.acceleration.x.toFixed(1) + ' ay: ' + this.acceleration.y.toFixed(1), x, y + 42);
|
||||
this.parent.texture.context.fillText('acx: ' + this.acceleration.x.toFixed(1) + ' acy: ' + this.acceleration.y.toFixed(1), x, y + 42);
|
||||
this.parent.texture.context.fillText('angVx: ' + this.angularVelocity.toFixed(1) + ' angAc: ' + this.angularAcceleration.toFixed(1), x, y + 56);
|
||||
|
||||
}
|
||||
|
||||
|
|
|
@ -36,12 +36,18 @@ module Phaser {
|
|||
private _camera: Camera;
|
||||
private _groupLength: number;
|
||||
|
||||
private _count: number;
|
||||
|
||||
public renderTotal: number;
|
||||
|
||||
public render() {
|
||||
|
||||
// Get a list of all the active cameras
|
||||
|
||||
this._cameraList = this._game.world.getAllCameras();
|
||||
|
||||
this._count = 0;
|
||||
|
||||
// Then iterate through world.group on them all (where not blacklisted, etc)
|
||||
for (var c = 0; c < this._cameraList.length; c++)
|
||||
{
|
||||
|
@ -49,11 +55,48 @@ module Phaser {
|
|||
|
||||
this._camera.preRender();
|
||||
|
||||
this._game.world.group.render(this, this._camera);
|
||||
this._game.world.group.render(this._camera);
|
||||
|
||||
this._camera.postRender();
|
||||
}
|
||||
|
||||
this.renderTotal = this._count;
|
||||
|
||||
}
|
||||
|
||||
public renderGameObject(object) {
|
||||
|
||||
if (object.type == Types.SPRITE)
|
||||
{
|
||||
this.renderSprite(this._camera, object);
|
||||
}
|
||||
else if (object.type == Types.SCROLLZONE)
|
||||
{
|
||||
this.renderScrollZone(this._camera, object);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Check whether this object is visible in a specific camera rectangle.
|
||||
* @param camera {Rectangle} The rectangle you want to check.
|
||||
* @return {boolean} Return true if bounds of this sprite intersects the given rectangle, otherwise return false.
|
||||
*/
|
||||
public inCamera(camera: Camera, sprite: Sprite): bool {
|
||||
|
||||
// Object fixed in place regardless of the camera scrolling? Then it's always visible
|
||||
if (sprite.scrollFactor.x == 0 && sprite.scrollFactor.y == 0)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
this._dx = sprite.frameBounds.x - camera.worldView.x;
|
||||
this._dy = sprite.frameBounds.y - camera.worldView.y;
|
||||
this._dw = sprite.frameBounds.width * sprite.scale.x;
|
||||
this._dh = sprite.frameBounds.height * sprite.scale.y;
|
||||
|
||||
return (camera.worldView.right > this._dx) && (camera.worldView.x < this._dx + this._dw) && (camera.worldView.bottom > this._dy) && (camera.worldView.y < this._dy + this._dh);
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -63,12 +106,13 @@ module Phaser {
|
|||
*/
|
||||
public renderSprite(camera: Camera, sprite: Sprite): bool {
|
||||
|
||||
// Render checks (needs inCamera check added)
|
||||
if (sprite.scale.x == 0 || sprite.scale.y == 0 || sprite.texture.alpha < 0.1)
|
||||
if (sprite.scale.x == 0 || sprite.scale.y == 0 || sprite.texture.alpha < 0.1 || this.inCamera(camera, sprite) == false)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
this._count++;
|
||||
|
||||
// Reset our temp vars
|
||||
this._ga = -1;
|
||||
this._sx = 0;
|
||||
|
@ -193,12 +237,13 @@ module Phaser {
|
|||
|
||||
public renderScrollZone(camera: Camera, scrollZone: ScrollZone): bool {
|
||||
|
||||
// Render checks (needs inCamera check added)
|
||||
if (scrollZone.scale.x == 0 || scrollZone.scale.y == 0 || scrollZone.texture.alpha < 0.1)
|
||||
if (scrollZone.scale.x == 0 || scrollZone.scale.y == 0 || scrollZone.texture.alpha < 0.1 || this.inCamera(camera, scrollZone) == false)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
this._count++;
|
||||
|
||||
// Reset our temp vars
|
||||
this._ga = -1;
|
||||
this._sx = 0;
|
||||
|
|
|
@ -17,6 +17,9 @@ module Phaser {
|
|||
|
||||
public render() {}
|
||||
|
||||
public renderGameObject(object) {
|
||||
}
|
||||
|
||||
public renderSprite(camera: Camera, sprite: Sprite): bool {
|
||||
return true;
|
||||
}
|
||||
|
|
|
@ -5,6 +5,7 @@ module Phaser {
|
|||
export interface IRenderer {
|
||||
|
||||
render();
|
||||
renderGameObject(object);
|
||||
renderSprite(camera: Camera, sprite: Sprite): bool;
|
||||
renderScrollZone(camera: Camera, sprite: ScrollZone): bool;
|
||||
|
||||
|
|
|
@ -3,6 +3,7 @@
|
|||
/// <reference path="../core/Rectangle.ts" />
|
||||
/// <reference path="../core/Circle.ts" />
|
||||
/// <reference path="../gameobjects/Sprite.ts" />
|
||||
/// <reference path="RectangleUtils.ts" />
|
||||
|
||||
/**
|
||||
* Phaser - SpriteUtils
|
||||
|
@ -154,28 +155,27 @@ module Phaser {
|
|||
*
|
||||
* @return Whether or not the point overlaps this object.
|
||||
*/
|
||||
/*
|
||||
static overlapsPoint(point: Point, inScreenSpace: bool = false, camera: Camera = null): bool {
|
||||
static overlapsPoint(sprite: Sprite, point: Point, inScreenSpace: bool = false, camera: Camera = null): bool {
|
||||
|
||||
if (!inScreenSpace)
|
||||
{
|
||||
return (point.x > this.x) && (point.x < this.x + this.width) && (point.y > this.y) && (point.y < this.y + this.height);
|
||||
return Phaser.RectangleUtils.containsPoint(sprite.body.bounds, point);
|
||||
//return (point.x > sprite.x) && (point.x < sprite.x + sprite.width) && (point.y > sprite.y) && (point.y < sprite.y + sprite.height);
|
||||
}
|
||||
|
||||
if (camera == null)
|
||||
{
|
||||
camera = this._game.camera;
|
||||
camera = sprite.game.camera;
|
||||
}
|
||||
|
||||
var X: number = point.x - camera.scroll.x;
|
||||
var Y: number = point.y - camera.scroll.y;
|
||||
//var x: number = point.x - camera.scroll.x;
|
||||
//var y: number = point.y - camera.scroll.y;
|
||||
|
||||
this.getScreenXY(this._point, camera);
|
||||
//this.getScreenXY(this._point, camera);
|
||||
|
||||
return (X > this._point.x) && (X < this._point.x + this.width) && (Y > this._point.y) && (Y < this._point.y + this.height);
|
||||
//return (x > this._point.x) && (X < this._point.x + this.width) && (Y > this._point.y) && (Y < this._point.y + this.height);
|
||||
|
||||
}
|
||||
*/
|
||||
|
||||
/**
|
||||
* Check and see if this object is currently on screen.
|
||||
|
@ -240,28 +240,6 @@ module Phaser {
|
|||
}
|
||||
*/
|
||||
|
||||
/**
|
||||
* Check whether this object is visible in a specific camera rectangle.
|
||||
* @param camera {Rectangle} The rectangle you want to check.
|
||||
* @return {boolean} Return true if bounds of this sprite intersects the given rectangle, otherwise return false.
|
||||
*/
|
||||
static inCamera(camera: Rectangle, cameraOffsetX: number, cameraOffsetY: number): bool {
|
||||
|
||||
// Object fixed in place regardless of the camera scrolling? Then it's always visible
|
||||
if (this.scrollFactor.x == 0 && this.scrollFactor.y == 0)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
this._dx = (this.frameBounds.x - camera.x);
|
||||
this._dy = (this.frameBounds.y - camera.y);
|
||||
this._dw = this.frameBounds.width * this.scale.x;
|
||||
this._dh = this.frameBounds.height * this.scale.y;
|
||||
|
||||
return (camera.right > this._dx) && (camera.x < this._dx + this._dw) && (camera.bottom > this._dy) && (camera.y < this._dy + this._dh);
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Handy for reviving game objects.
|
||||
* Resets their existence flags and position.
|
||||
|
@ -283,6 +261,19 @@ module Phaser {
|
|||
|
||||
}
|
||||
|
||||
static setOriginToCenter(sprite: Sprite, fromFrameBounds: bool = true, fromBody?: bool = false) {
|
||||
|
||||
if (fromFrameBounds)
|
||||
{
|
||||
sprite.origin.setTo(sprite.frameBounds.halfWidth, sprite.frameBounds.halfHeight);
|
||||
}
|
||||
else if (fromBody)
|
||||
{
|
||||
sprite.origin.setTo(sprite.body.bounds.halfWidth, sprite.body.bounds.halfHeight);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the world bounds that this GameObject can exist within. By default a GameObject can exist anywhere
|
||||
* in the world. But by setting the bounds (which are given in world dimensions, not screen dimensions)
|
||||
|
|
|
@ -52,6 +52,8 @@ V1.0.0
|
|||
* Removed Sprite.rotation - use Sprite.angle instead
|
||||
* Optimised separateX/Y and overlap so they don't use any temporary vars any more.
|
||||
* Added the new Physics.Body object to all Sprites. Used for all physics calculations in-game. Will be extended for Fixtures/Joints in future.
|
||||
* Added SpriteUtils.setOriginToCenter to quickly set the origin of a sprite based on either frameBounds or body.bounds
|
||||
|
||||
|
||||
|
||||
V0.9.6
|
||||
|
|
|
@ -71,6 +71,10 @@
|
|||
<DependentUpon>graphic emitter.ts</DependentUpon>
|
||||
</Content>
|
||||
<TypeScriptCompile Include="particles\multiple streams.ts" />
|
||||
<TypeScriptCompile Include="particles\mousetrail.ts" />
|
||||
<Content Include="particles\mousetrail.js">
|
||||
<DependentUpon>mousetrail.ts</DependentUpon>
|
||||
</Content>
|
||||
<Content Include="particles\multiple streams.js">
|
||||
<DependentUpon>multiple streams.ts</DependentUpon>
|
||||
</Content>
|
||||
|
@ -97,6 +101,10 @@
|
|||
<Content Include="scrollzones\ballscroller.js">
|
||||
<DependentUpon>ballscroller.ts</DependentUpon>
|
||||
</Content>
|
||||
<TypeScriptCompile Include="scrollzones\blasteroids.ts" />
|
||||
<Content Include="scrollzones\blasteroids.js">
|
||||
<DependentUpon>blasteroids.ts</DependentUpon>
|
||||
</Content>
|
||||
<Content Include="scrollzones\parallax.js">
|
||||
<DependentUpon>parallax.ts</DependentUpon>
|
||||
</Content>
|
||||
|
|
|
@ -8,7 +8,7 @@
|
|||
}
|
||||
function create() {
|
||||
emitter = game.add.emitter(game.stage.centerX, game.stage.centerY);
|
||||
emitter.makeParticles('jet', 50, false, 0);
|
||||
emitter.start(false, 10, 0.1);
|
||||
emitter.makeParticles('jet', 100, false, 0);
|
||||
emitter.start(false, 20, 0.1);
|
||||
}
|
||||
})();
|
||||
|
|
|
@ -17,8 +17,8 @@
|
|||
function create() {
|
||||
|
||||
emitter = game.add.emitter(game.stage.centerX, game.stage.centerY);
|
||||
emitter.makeParticles('jet', 50, false, 0);
|
||||
emitter.start(false, 10, 0.1);
|
||||
emitter.makeParticles('jet', 100, false, 0);
|
||||
emitter.start(false, 20, 0.1);
|
||||
|
||||
}
|
||||
|
||||
|
|
29
Tests/particles/mousetrail.js
Normal file
29
Tests/particles/mousetrail.js
Normal file
|
@ -0,0 +1,29 @@
|
|||
/// <reference path="../../Phaser/Game.ts" />
|
||||
(function () {
|
||||
var game = new Phaser.Game(this, 'game', 800, 600, init, create, update);
|
||||
var emitter;
|
||||
function init() {
|
||||
game.loader.addImageFile('jet', 'assets/sprites/particle1.png');
|
||||
game.loader.addImageFile('starfield', 'assets/misc/starfield.jpg');
|
||||
game.loader.load();
|
||||
}
|
||||
var scroller;
|
||||
var emitter;
|
||||
function create() {
|
||||
scroller = game.add.scrollZone('starfield', 0, 0, 1024, 1024);
|
||||
scroller.setSpeed(0, -1);
|
||||
emitter = game.add.emitter(game.stage.centerX, game.stage.centerY);
|
||||
emitter.makeParticles('jet', 200);
|
||||
emitter.globalCompositeOperation = 'lighter';
|
||||
emitter.gravity = 300;
|
||||
emitter.setXSpeed(-50, 50);
|
||||
emitter.setYSpeed(-50, -100);
|
||||
emitter.setRotation(0, 0);
|
||||
emitter.start(false, 50, 0.02);
|
||||
}
|
||||
function update() {
|
||||
emitter.x = game.input.x;
|
||||
emitter.y = game.input.y;
|
||||
//emitter.em
|
||||
}
|
||||
})();
|
46
Tests/particles/mousetrail.ts
Normal file
46
Tests/particles/mousetrail.ts
Normal file
|
@ -0,0 +1,46 @@
|
|||
/// <reference path="../../Phaser/Game.ts" />
|
||||
|
||||
(function () {
|
||||
|
||||
var game = new Phaser.Game(this, 'game', 800, 600, init, create, update);
|
||||
|
||||
var emitter: Phaser.Emitter;
|
||||
|
||||
function init() {
|
||||
|
||||
game.loader.addImageFile('jet', 'assets/sprites/particle1.png');
|
||||
game.loader.addImageFile('starfield', 'assets/misc/starfield.jpg');
|
||||
game.loader.load();
|
||||
|
||||
}
|
||||
|
||||
var scroller: Phaser.ScrollZone;
|
||||
var emitter: Phaser.Emitter;
|
||||
|
||||
function create() {
|
||||
|
||||
scroller = game.add.scrollZone('starfield', 0, 0, 1024, 1024);
|
||||
scroller.setSpeed(0, -1);
|
||||
|
||||
emitter = game.add.emitter(game.stage.centerX, game.stage.centerY);
|
||||
emitter.makeParticles('jet', 200);
|
||||
|
||||
emitter.globalCompositeOperation = 'lighter';
|
||||
|
||||
emitter.gravity = 300;
|
||||
emitter.setXSpeed(-50, 50);
|
||||
emitter.setYSpeed(-50, -100);
|
||||
emitter.setRotation(0, 0);
|
||||
emitter.start(false, 50, 0.02);
|
||||
|
||||
}
|
||||
|
||||
function update() {
|
||||
|
||||
emitter.x = game.input.x;
|
||||
emitter.y = game.input.y;
|
||||
//emitter.em
|
||||
|
||||
}
|
||||
|
||||
})();
|
139
Tests/phaser.js
139
Tests/phaser.js
|
@ -1337,7 +1337,7 @@ var Phaser;
|
|||
* Calls render on all members of this Group who have a status of visible=true and exists=true
|
||||
* You can also call Object.render directly, which will bypass the visible/exists check.
|
||||
*/
|
||||
function (renderer, camera) {
|
||||
function (camera) {
|
||||
if(camera.isHidden(this) == true) {
|
||||
return;
|
||||
}
|
||||
|
@ -1353,14 +1353,10 @@ 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);
|
||||
// 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);
|
||||
this._member.render(camera);
|
||||
} else {
|
||||
this.game.renderer.renderGameObject(this._member);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -5053,6 +5049,7 @@ var Phaser;
|
|||
/// <reference path="../core/Rectangle.ts" />
|
||||
/// <reference path="../core/Circle.ts" />
|
||||
/// <reference path="../gameobjects/Sprite.ts" />
|
||||
/// <reference path="RectangleUtils.ts" />
|
||||
/**
|
||||
* Phaser - SpriteUtils
|
||||
*
|
||||
|
@ -5074,7 +5071,7 @@ var Phaser;
|
|||
out.push(new Phaser.Point(sprite.x, sprite.y + sprite.height));
|
||||
return out;
|
||||
};
|
||||
SpriteUtils.onScreen = /**
|
||||
SpriteUtils.overlapsPoint = /**
|
||||
* Checks to see if some <code>GameObject</code> overlaps this <code>GameObject</code> or <code>Group</code>.
|
||||
* If the group has a LOT of things in it, it might be faster to use <code>Collision.overlaps()</code>.
|
||||
* WARNING: Currently tilemaps do NOT support screen space overlap checks!
|
||||
|
@ -5190,29 +5187,22 @@ var Phaser;
|
|||
*
|
||||
* @return Whether or not the point overlaps this object.
|
||||
*/
|
||||
/*
|
||||
static overlapsPoint(point: Point, inScreenSpace: bool = false, camera: Camera = null): bool {
|
||||
|
||||
if (!inScreenSpace)
|
||||
{
|
||||
return (point.x > this.x) && (point.x < this.x + this.width) && (point.y > this.y) && (point.y < this.y + this.height);
|
||||
}
|
||||
|
||||
if (camera == null)
|
||||
{
|
||||
camera = this._game.camera;
|
||||
}
|
||||
|
||||
var X: number = point.x - camera.scroll.x;
|
||||
var Y: number = point.y - camera.scroll.y;
|
||||
|
||||
this.getScreenXY(this._point, camera);
|
||||
|
||||
return (X > this._point.x) && (X < this._point.x + this.width) && (Y > this._point.y) && (Y < this._point.y + this.height);
|
||||
|
||||
}
|
||||
*/
|
||||
/**
|
||||
function overlapsPoint(sprite, point, inScreenSpace, camera) {
|
||||
if (typeof inScreenSpace === "undefined") { inScreenSpace = false; }
|
||||
if (typeof camera === "undefined") { camera = null; }
|
||||
if(!inScreenSpace) {
|
||||
return Phaser.RectangleUtils.containsPoint(sprite.body.bounds, point);
|
||||
//return (point.x > sprite.x) && (point.x < sprite.x + sprite.width) && (point.y > sprite.y) && (point.y < sprite.y + sprite.height);
|
||||
}
|
||||
if(camera == null) {
|
||||
camera = sprite.game.camera;
|
||||
}
|
||||
//var x: number = point.x - camera.scroll.x;
|
||||
//var y: number = point.y - camera.scroll.y;
|
||||
//this.getScreenXY(this._point, camera);
|
||||
//return (x > this._point.x) && (X < this._point.x + this.width) && (Y > this._point.y) && (Y < this._point.y + this.height);
|
||||
};
|
||||
SpriteUtils.onScreen = /**
|
||||
* Check and see if this object is currently on screen.
|
||||
*
|
||||
* @param camera {Camera} Specify which game camera you want. If null getScreenXY() will just grab the first global camera.
|
||||
|
@ -5250,7 +5240,7 @@ var Phaser;
|
|||
point.y += (point.y > 0) ? 0.0000001 : -0.0000001;
|
||||
return point;
|
||||
};
|
||||
SpriteUtils.inCamera = /**
|
||||
SpriteUtils.reset = /**
|
||||
* Set the world bounds that this GameObject can exist within based on the size of the current game world.
|
||||
*
|
||||
* @param action {number} The action to take if the object hits the world bounds, either OUT_OF_BOUNDS_KILL or OUT_OF_BOUNDS_STOP
|
||||
|
@ -5264,22 +5254,6 @@ var Phaser;
|
|||
}
|
||||
*/
|
||||
/**
|
||||
* Check whether this object is visible in a specific camera rectangle.
|
||||
* @param camera {Rectangle} The rectangle you want to check.
|
||||
* @return {boolean} Return true if bounds of this sprite intersects the given rectangle, otherwise return false.
|
||||
*/
|
||||
function inCamera(camera, cameraOffsetX, cameraOffsetY) {
|
||||
// Object fixed in place regardless of the camera scrolling? Then it's always visible
|
||||
if(this.scrollFactor.x == 0 && this.scrollFactor.y == 0) {
|
||||
return true;
|
||||
}
|
||||
this._dx = (this.frameBounds.x - camera.x);
|
||||
this._dy = (this.frameBounds.y - camera.y);
|
||||
this._dw = this.frameBounds.width * this.scale.x;
|
||||
this._dh = this.frameBounds.height * this.scale.y;
|
||||
return (camera.right > this._dx) && (camera.x < this._dx + this._dw) && (camera.bottom > this._dy) && (camera.y < this._dy + this._dh);
|
||||
};
|
||||
SpriteUtils.reset = /**
|
||||
* Handy for reviving game objects.
|
||||
* Resets their existence flags and position.
|
||||
*
|
||||
|
@ -5297,6 +5271,15 @@ var Phaser;
|
|||
sprite.body.position.x = x;
|
||||
sprite.body.position.y = y;
|
||||
};
|
||||
SpriteUtils.setOriginToCenter = function setOriginToCenter(sprite, fromFrameBounds, fromBody) {
|
||||
if (typeof fromFrameBounds === "undefined") { fromFrameBounds = true; }
|
||||
if (typeof fromBody === "undefined") { fromBody = false; }
|
||||
if(fromFrameBounds) {
|
||||
sprite.origin.setTo(sprite.frameBounds.halfWidth, sprite.frameBounds.halfHeight);
|
||||
} else if(fromBody) {
|
||||
sprite.origin.setTo(sprite.body.bounds.halfWidth, sprite.body.bounds.halfHeight);
|
||||
}
|
||||
};
|
||||
SpriteUtils.setBounds = /**
|
||||
* Set the world bounds that this GameObject can exist within. By default a GameObject can exist anywhere
|
||||
* in the world. But by setting the bounds (which are given in world dimensions, not screen dimensions)
|
||||
|
@ -5968,9 +5951,10 @@ var Phaser;
|
|||
this.parent.texture.context.fillStyle = color;
|
||||
this.parent.texture.context.fillText('Sprite: (' + this.parent.frameBounds.width + ' x ' + this.parent.frameBounds.height + ')', x, y);
|
||||
//this.parent.texture.context.fillText('x: ' + this._parent.frameBounds.x.toFixed(1) + ' y: ' + this._parent.frameBounds.y.toFixed(1) + ' rotation: ' + this._parent.rotation.toFixed(1), x, y + 14);
|
||||
this.parent.texture.context.fillText('x: ' + this.bounds.x.toFixed(1) + ' y: ' + this.bounds.y.toFixed(1) + ' angle: ' + this.angle.toFixed(1), x, y + 14);
|
||||
this.parent.texture.context.fillText('x: ' + this.bounds.x.toFixed(1) + ' y: ' + this.bounds.y.toFixed(1) + ' angle: ' + this.angle.toFixed(0), x, y + 14);
|
||||
this.parent.texture.context.fillText('vx: ' + this.velocity.x.toFixed(1) + ' vy: ' + this.velocity.y.toFixed(1), x, y + 28);
|
||||
this.parent.texture.context.fillText('ax: ' + this.acceleration.x.toFixed(1) + ' ay: ' + this.acceleration.y.toFixed(1), x, y + 42);
|
||||
this.parent.texture.context.fillText('acx: ' + this.acceleration.x.toFixed(1) + ' acy: ' + this.acceleration.y.toFixed(1), x, y + 42);
|
||||
this.parent.texture.context.fillText('angVx: ' + this.angularVelocity.toFixed(1) + ' angAc: ' + this.angularAcceleration.toFixed(1), x, y + 56);
|
||||
};
|
||||
return Body;
|
||||
})();
|
||||
|
@ -6030,7 +6014,6 @@ var Phaser;
|
|||
this.angleOffset = 0;
|
||||
this.game = game;
|
||||
this.type = Phaser.Types.SPRITE;
|
||||
this.render = game.renderer.renderSprite;
|
||||
this.exists = true;
|
||||
this.active = true;
|
||||
this.visible = true;
|
||||
|
@ -6042,6 +6025,8 @@ var Phaser;
|
|||
this.y = y;
|
||||
this.z = 0// not used yet
|
||||
;
|
||||
// If a texture has been given the body will be set to that size, otherwise 16x16
|
||||
this.body = new Phaser.Physics.Body(this, bodyType);
|
||||
this.animations = new Phaser.Components.AnimationManager(this);
|
||||
this.texture = new Phaser.Components.Texture(this, key);
|
||||
this.cameraBlacklist = [];
|
||||
|
@ -6049,8 +6034,6 @@ var Phaser;
|
|||
this.origin = new Phaser.Vec2(0, 0);
|
||||
this.scale = new Phaser.Vec2(1, 1);
|
||||
this.skew = new Phaser.Vec2(0, 0);
|
||||
// If a texture has been given the body will be set to that size, otherwise 16x16
|
||||
this.body = new Phaser.Physics.Body(this, bodyType);
|
||||
}
|
||||
Object.defineProperty(Sprite.prototype, "angle", {
|
||||
get: /**
|
||||
|
@ -7627,7 +7610,6 @@ 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);
|
||||
|
@ -7731,13 +7713,6 @@ var Phaser;
|
|||
if(multiple) {
|
||||
/*
|
||||
randomFrame = this.game.math.random()*totalFrames;
|
||||
if(BakedRotations > 0)
|
||||
particle.loadRotatedGraphic(Graphics,BakedRotations,randomFrame);
|
||||
else
|
||||
{
|
||||
particle.loadGraphic(Graphics,true);
|
||||
particle.frame = randomFrame;
|
||||
}
|
||||
*/
|
||||
} else {
|
||||
if(graphics) {
|
||||
|
@ -7753,7 +7728,7 @@ var Phaser;
|
|||
particle.body.allowCollisions = Phaser.Types.NONE;
|
||||
}
|
||||
particle.exists = false;
|
||||
// Center it
|
||||
// Center the origin for rotation assistance
|
||||
particle.origin.setTo(particle.body.bounds.halfWidth, particle.body.bounds.halfHeight);
|
||||
this.add(particle);
|
||||
i++;
|
||||
|
@ -8108,7 +8083,6 @@ var Phaser;
|
|||
if (typeof height === "undefined") { height = 0; }
|
||||
_super.call(this, game, x, y, key);
|
||||
this.type = Phaser.Types.SCROLLZONE;
|
||||
this.render = game.renderer.renderScrollZone;
|
||||
this.regions = [];
|
||||
if(this.texture.loaded) {
|
||||
if(width > this.width || height > this.height) {
|
||||
|
@ -14278,6 +14252,8 @@ var Phaser;
|
|||
}
|
||||
HeadlessRenderer.prototype.render = function () {
|
||||
};
|
||||
HeadlessRenderer.prototype.renderGameObject = function (object) {
|
||||
};
|
||||
HeadlessRenderer.prototype.renderSprite = function (camera, sprite) {
|
||||
return true;
|
||||
};
|
||||
|
@ -14316,13 +14292,38 @@ var Phaser;
|
|||
CanvasRenderer.prototype.render = function () {
|
||||
// Get a list of all the active cameras
|
||||
this._cameraList = this._game.world.getAllCameras();
|
||||
this._count = 0;
|
||||
// Then iterate through world.group on them all (where not blacklisted, etc)
|
||||
for(var c = 0; c < this._cameraList.length; c++) {
|
||||
this._camera = this._cameraList[c];
|
||||
this._camera.preRender();
|
||||
this._game.world.group.render(this, this._camera);
|
||||
this._game.world.group.render(this._camera);
|
||||
this._camera.postRender();
|
||||
}
|
||||
this.renderTotal = this._count;
|
||||
};
|
||||
CanvasRenderer.prototype.renderGameObject = function (object) {
|
||||
if(object.type == Phaser.Types.SPRITE) {
|
||||
this.renderSprite(this._camera, object);
|
||||
} else if(object.type == Phaser.Types.SCROLLZONE) {
|
||||
this.renderScrollZone(this._camera, object);
|
||||
}
|
||||
};
|
||||
CanvasRenderer.prototype.inCamera = /**
|
||||
* Check whether this object is visible in a specific camera rectangle.
|
||||
* @param camera {Rectangle} The rectangle you want to check.
|
||||
* @return {boolean} Return true if bounds of this sprite intersects the given rectangle, otherwise return false.
|
||||
*/
|
||||
function (camera, sprite) {
|
||||
// Object fixed in place regardless of the camera scrolling? Then it's always visible
|
||||
if(sprite.scrollFactor.x == 0 && sprite.scrollFactor.y == 0) {
|
||||
return true;
|
||||
}
|
||||
this._dx = sprite.frameBounds.x - camera.worldView.x;
|
||||
this._dy = sprite.frameBounds.y - camera.worldView.y;
|
||||
this._dw = sprite.frameBounds.width * sprite.scale.x;
|
||||
this._dh = sprite.frameBounds.height * sprite.scale.y;
|
||||
return (camera.worldView.right > this._dx) && (camera.worldView.x < this._dx + this._dw) && (camera.worldView.bottom > this._dy) && (camera.worldView.y < this._dy + this._dh);
|
||||
};
|
||||
CanvasRenderer.prototype.renderSprite = /**
|
||||
* Render this sprite to specific camera. Called by game loop after update().
|
||||
|
@ -14330,10 +14331,10 @@ var Phaser;
|
|||
* @return {boolean} Return false if not rendered, otherwise return true.
|
||||
*/
|
||||
function (camera, sprite) {
|
||||
// Render checks (needs inCamera check added)
|
||||
if(sprite.scale.x == 0 || sprite.scale.y == 0 || sprite.texture.alpha < 0.1) {
|
||||
if(sprite.scale.x == 0 || sprite.scale.y == 0 || sprite.texture.alpha < 0.1 || this.inCamera(camera, sprite) == false) {
|
||||
return false;
|
||||
}
|
||||
this._count++;
|
||||
// Reset our temp vars
|
||||
this._ga = -1;
|
||||
this._sx = 0;
|
||||
|
@ -14425,10 +14426,10 @@ var Phaser;
|
|||
return true;
|
||||
};
|
||||
CanvasRenderer.prototype.renderScrollZone = function (camera, scrollZone) {
|
||||
// Render checks (needs inCamera check added)
|
||||
if(scrollZone.scale.x == 0 || scrollZone.scale.y == 0 || scrollZone.texture.alpha < 0.1) {
|
||||
if(scrollZone.scale.x == 0 || scrollZone.scale.y == 0 || scrollZone.texture.alpha < 0.1 || this.inCamera(camera, scrollZone) == false) {
|
||||
return false;
|
||||
}
|
||||
this._count++;
|
||||
// Reset our temp vars
|
||||
this._ga = -1;
|
||||
this._sx = 0;
|
||||
|
|
99
Tests/scrollzones/blasteroids.js
Normal file
99
Tests/scrollzones/blasteroids.js
Normal file
|
@ -0,0 +1,99 @@
|
|||
/// <reference path="../../Phaser/Game.ts" />
|
||||
/// <reference path="../../Phaser/gameobjects/ScrollZone.ts" />
|
||||
(function () {
|
||||
var game = new Phaser.Game(this, 'game', 800, 600, init, create, update, render);
|
||||
function init() {
|
||||
game.loader.addImageFile('nashwan', 'assets/sprites/xenon2_ship.png');
|
||||
game.loader.addImageFile('starfield', 'assets/misc/starfield.jpg');
|
||||
game.loader.addImageFile('jet', 'assets/sprites/particle1.png');
|
||||
game.loader.addImageFile('bullet', 'assets/misc/bullet1.png');
|
||||
game.loader.load();
|
||||
}
|
||||
var scroller;
|
||||
var emitter;
|
||||
var ship;
|
||||
var bullets;
|
||||
var speed = 0;
|
||||
var fireRate = 0;
|
||||
var shipMotion;
|
||||
function create() {
|
||||
scroller = game.add.scrollZone('starfield', 0, 0, 1024, 1024);
|
||||
emitter = game.add.emitter(game.stage.centerX + 16, game.stage.centerY + 12);
|
||||
emitter.makeParticles('jet', 250, false, 0);
|
||||
emitter.setRotation(0, 0);
|
||||
// Looks like a smoke trail!
|
||||
//emitter.globalCompositeOperation = 'xor';
|
||||
// Looks way cool :)
|
||||
emitter.globalCompositeOperation = 'lighter';
|
||||
bullets = game.add.group(50);
|
||||
// Create our bullet pool
|
||||
for(var i = 0; i < 50; i++) {
|
||||
var tempBullet = new Phaser.Sprite(game, game.stage.centerX, game.stage.centerY, 'bullet');
|
||||
tempBullet.exists = false;
|
||||
tempBullet.angleOffset = 90;
|
||||
//tempBullet.setBounds(-100, -100, 900, 700);
|
||||
//tempBullet.outOfBoundsAction = Phaser.GameObject.OUT_OF_BOUNDS_KILL;
|
||||
bullets.add(tempBullet);
|
||||
}
|
||||
ship = game.add.sprite(game.stage.centerX, game.stage.centerY, 'nashwan', Phaser.Types.BODY_DYNAMIC);
|
||||
Phaser.SpriteUtils.setOriginToCenter(ship);
|
||||
// We do this because the ship was drawn facing up, but 0 degrees is pointing to the right
|
||||
ship.angleOffset = 90;
|
||||
game.input.onDown.add(test, this);
|
||||
}
|
||||
function test(event) {
|
||||
game.stage.scale.startFullScreen();
|
||||
}
|
||||
function update() {
|
||||
ship.body.angularVelocity = 0;
|
||||
if(game.input.keyboard.isDown(Phaser.Keyboard.LEFT)) {
|
||||
ship.body.angularVelocity = -200;
|
||||
} else if(game.input.keyboard.isDown(Phaser.Keyboard.RIGHT)) {
|
||||
ship.body.angularVelocity = 200;
|
||||
}
|
||||
if(game.input.keyboard.isDown(Phaser.Keyboard.UP)) {
|
||||
speed += 0.1;
|
||||
if(speed > 10) {
|
||||
speed = 10;
|
||||
}
|
||||
} else {
|
||||
speed -= 0.1;
|
||||
if(speed < 0) {
|
||||
speed = 0;
|
||||
}
|
||||
}
|
||||
shipMotion = game.motion.velocityFromAngle(ship.angle, speed);
|
||||
scroller.setSpeed(shipMotion.x, shipMotion.y);
|
||||
// emit particles
|
||||
if(speed > 2) {
|
||||
// We use the opposite of the motion because the jets emit out the back of the ship
|
||||
// The 20 and 30 values just keep them nice and fast
|
||||
emitter.setXSpeed(-(shipMotion.x * 20), -(shipMotion.x * 30));
|
||||
emitter.setYSpeed(-(shipMotion.y * 20), -(shipMotion.y * 30));
|
||||
emitter.emitParticle();
|
||||
}
|
||||
if(game.input.keyboard.isDown(Phaser.Keyboard.SPACEBAR)) {
|
||||
fire();
|
||||
}
|
||||
}
|
||||
function render() {
|
||||
ship.body.renderDebugInfo(32, 32);
|
||||
}
|
||||
function recycleBullet(bullet) {
|
||||
if(bullet.exists && bullet.x < -40 || bullet.x > 840 || bullet.y < -40 || bullet.y > 640) {
|
||||
bullet.exists = false;
|
||||
}
|
||||
}
|
||||
function fire() {
|
||||
if(game.time.now > fireRate) {
|
||||
var b = bullets.getFirstAvailable();
|
||||
b.x = ship.x;
|
||||
b.y = ship.y - 26;
|
||||
var bulletMotion = game.motion.velocityFromAngle(ship.angle, 400);
|
||||
b.revive();
|
||||
b.angle = ship.angle;
|
||||
b.body.velocity.setTo(bulletMotion.x, bulletMotion.y);
|
||||
fireRate = game.time.now + 100;
|
||||
}
|
||||
}
|
||||
})();
|
158
Tests/scrollzones/blasteroids.ts
Normal file
158
Tests/scrollzones/blasteroids.ts
Normal file
|
@ -0,0 +1,158 @@
|
|||
/// <reference path="../../Phaser/Game.ts" />
|
||||
/// <reference path="../../Phaser/gameobjects/ScrollZone.ts" />
|
||||
|
||||
(function () {
|
||||
|
||||
var game = new Phaser.Game(this, 'game', 800, 600, init, create, update, render);
|
||||
|
||||
function init() {
|
||||
|
||||
game.loader.addImageFile('nashwan', 'assets/sprites/xenon2_ship.png');
|
||||
game.loader.addImageFile('starfield', 'assets/misc/starfield.jpg');
|
||||
game.loader.addImageFile('jet', 'assets/sprites/particle1.png');
|
||||
game.loader.addImageFile('bullet', 'assets/misc/bullet1.png');
|
||||
|
||||
game.loader.load();
|
||||
|
||||
}
|
||||
|
||||
var scroller: Phaser.ScrollZone;
|
||||
var emitter: Phaser.Emitter;
|
||||
var ship: Phaser.Sprite;
|
||||
var bullets: Phaser.Group;
|
||||
|
||||
var speed: number = 0;
|
||||
var fireRate: number = 0;
|
||||
var shipMotion: Phaser.Point;
|
||||
|
||||
function create() {
|
||||
|
||||
scroller = game.add.scrollZone('starfield', 0, 0, 1024, 1024);
|
||||
|
||||
emitter = game.add.emitter(game.stage.centerX + 16, game.stage.centerY + 12);
|
||||
emitter.makeParticles('jet', 250, false, 0);
|
||||
emitter.setRotation(0, 0);
|
||||
|
||||
// Looks like a smoke trail!
|
||||
//emitter.globalCompositeOperation = 'xor';
|
||||
|
||||
// Looks way cool :)
|
||||
emitter.globalCompositeOperation = 'lighter';
|
||||
|
||||
bullets = game.add.group(50);
|
||||
|
||||
// Create our bullet pool
|
||||
for (var i = 0; i < 50; i++)
|
||||
{
|
||||
var tempBullet = new Phaser.Sprite(game, game.stage.centerX, game.stage.centerY, 'bullet');
|
||||
tempBullet.exists = false;
|
||||
tempBullet.angleOffset = 90;
|
||||
//tempBullet.setBounds(-100, -100, 900, 700);
|
||||
//tempBullet.outOfBoundsAction = Phaser.GameObject.OUT_OF_BOUNDS_KILL;
|
||||
bullets.add(tempBullet);
|
||||
}
|
||||
|
||||
ship = game.add.sprite(game.stage.centerX, game.stage.centerY, 'nashwan', Phaser.Types.BODY_DYNAMIC);
|
||||
Phaser.SpriteUtils.setOriginToCenter(ship);
|
||||
|
||||
// We do this because the ship was drawn facing up, but 0 degrees is pointing to the right
|
||||
ship.angleOffset = 90;
|
||||
|
||||
game.input.onDown.add(test, this);
|
||||
|
||||
}
|
||||
|
||||
function test(event) {
|
||||
|
||||
game.stage.scale.startFullScreen();
|
||||
|
||||
}
|
||||
|
||||
function update() {
|
||||
|
||||
ship.body.angularVelocity = 0;
|
||||
|
||||
if (game.input.keyboard.isDown(Phaser.Keyboard.LEFT))
|
||||
{
|
||||
ship.body.angularVelocity = -200;
|
||||
}
|
||||
else if (game.input.keyboard.isDown(Phaser.Keyboard.RIGHT))
|
||||
{
|
||||
ship.body.angularVelocity = 200;
|
||||
}
|
||||
|
||||
if (game.input.keyboard.isDown(Phaser.Keyboard.UP))
|
||||
{
|
||||
speed += 0.1;
|
||||
|
||||
if (speed > 10)
|
||||
{
|
||||
speed = 10;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
speed -= 0.1;
|
||||
|
||||
if (speed < 0) {
|
||||
speed = 0;
|
||||
}
|
||||
}
|
||||
|
||||
shipMotion = game.motion.velocityFromAngle(ship.angle, speed);
|
||||
|
||||
scroller.setSpeed(shipMotion.x, shipMotion.y);
|
||||
|
||||
// emit particles
|
||||
if (speed > 2)
|
||||
{
|
||||
// We use the opposite of the motion because the jets emit out the back of the ship
|
||||
// The 20 and 30 values just keep them nice and fast
|
||||
emitter.setXSpeed(-(shipMotion.x * 20), -(shipMotion.x * 30));
|
||||
emitter.setYSpeed(-(shipMotion.y * 20), -(shipMotion.y * 30));
|
||||
emitter.emitParticle();
|
||||
}
|
||||
|
||||
if (game.input.keyboard.isDown(Phaser.Keyboard.SPACEBAR))
|
||||
{
|
||||
fire();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
function render() {
|
||||
|
||||
ship.body.renderDebugInfo(32, 32);
|
||||
|
||||
}
|
||||
|
||||
function recycleBullet(bullet:Phaser.Sprite) {
|
||||
|
||||
if (bullet.exists && bullet.x < -40 || bullet.x > 840 || bullet.y < -40 || bullet.y > 640)
|
||||
{
|
||||
bullet.exists = false;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
function fire() {
|
||||
|
||||
if (game.time.now > fireRate)
|
||||
{
|
||||
var b:Phaser.Sprite = bullets.getFirstAvailable();
|
||||
|
||||
b.x = ship.x;
|
||||
b.y = ship.y - 26;
|
||||
|
||||
var bulletMotion = game.motion.velocityFromAngle(ship.angle, 400);
|
||||
|
||||
b.revive();
|
||||
b.angle = ship.angle;
|
||||
b.body.velocity.setTo(bulletMotion.x, bulletMotion.y);
|
||||
|
||||
fireRate = game.time.now + 100;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
})();
|
|
@ -2,11 +2,13 @@
|
|||
(function () {
|
||||
var game = new Phaser.Game(this, 'game', 800, 600, init, create);
|
||||
function init() {
|
||||
console.log('>>>>>>>>>>>>>>>>>>>>>>>> init');
|
||||
// Using Phasers asset loader we load up a PNG from the assets folder
|
||||
game.loader.addImageFile('bunny', 'assets/sprites/bunny.png');
|
||||
game.loader.load();
|
||||
}
|
||||
function create() {
|
||||
console.log('>>>>>>>>>>>>>>>>>>>>>>>> create');
|
||||
// This will create a Sprite positioned at the top-left of the game (0,0)
|
||||
// Try changing the 0, 0 values
|
||||
game.add.sprite(0, 0, 'bunny');
|
||||
|
|
|
@ -6,6 +6,8 @@
|
|||
|
||||
function init() {
|
||||
|
||||
console.log('>>>>>>>>>>>>>>>>>>>>>>>> init');
|
||||
|
||||
// Using Phasers asset loader we load up a PNG from the assets folder
|
||||
game.loader.addImageFile('bunny', 'assets/sprites/bunny.png');
|
||||
game.loader.load();
|
||||
|
@ -14,6 +16,8 @@
|
|||
|
||||
function create() {
|
||||
|
||||
console.log('>>>>>>>>>>>>>>>>>>>>>>>> create');
|
||||
|
||||
// This will create a Sprite positioned at the top-left of the game (0,0)
|
||||
// Try changing the 0, 0 values
|
||||
game.add.sprite(0, 0, 'bunny');
|
||||
|
|
38
build/phaser.d.ts
vendored
38
build/phaser.d.ts
vendored
|
@ -248,10 +248,6 @@ module Phaser {
|
|||
*/
|
||||
type: number;
|
||||
/**
|
||||
* Reference to the Renderer.renderSprite method. Can be overriden by custom classes.
|
||||
*/
|
||||
render;
|
||||
/**
|
||||
* Controls if both <code>update</code> and render are called by the core game loop.
|
||||
*/
|
||||
exists: bool;
|
||||
|
@ -975,7 +971,7 @@ module Phaser {
|
|||
* Calls render on all members of this Group who have a status of visible=true and exists=true
|
||||
* You can also call Object.render directly, which will bypass the visible/exists check.
|
||||
*/
|
||||
public render(renderer: IRenderer, camera: Camera): void;
|
||||
public render(camera: Camera): void;
|
||||
/**
|
||||
* The maximum capacity of this group. Default is 0, meaning no max capacity, and the group can just grow.
|
||||
*/
|
||||
|
@ -3050,6 +3046,16 @@ module Phaser {
|
|||
static _tempPoint: Point;
|
||||
static getAsPoints(sprite: Sprite): Point[];
|
||||
/**
|
||||
* Checks to see if a point in 2D world space overlaps this <code>GameObject</code>.
|
||||
*
|
||||
* @param point {Point} The point in world space you want to check.
|
||||
* @param inScreenSpace {boolean} Whether to take scroll factors into account when checking for overlap.
|
||||
* @param camera {Camera} Specify which game camera you want. If null getScreenXY() will just grab the first global camera.
|
||||
*
|
||||
* @return Whether or not the point overlaps this object.
|
||||
*/
|
||||
static overlapsPoint(sprite: Sprite, point: Point, inScreenSpace?: bool, camera?: Camera): bool;
|
||||
/**
|
||||
* Check and see if this object is currently on screen.
|
||||
*
|
||||
* @param camera {Camera} Specify which game camera you want. If null getScreenXY() will just grab the first global camera.
|
||||
|
@ -3067,12 +3073,6 @@ module Phaser {
|
|||
*/
|
||||
static getScreenXY(sprite: Sprite, point?: Point, camera?: Camera): Point;
|
||||
/**
|
||||
* Check whether this object is visible in a specific camera rectangle.
|
||||
* @param camera {Rectangle} The rectangle you want to check.
|
||||
* @return {boolean} Return true if bounds of this sprite intersects the given rectangle, otherwise return false.
|
||||
*/
|
||||
static inCamera(camera: Rectangle, cameraOffsetX: number, cameraOffsetY: number): bool;
|
||||
/**
|
||||
* Handy for reviving game objects.
|
||||
* Resets their existence flags and position.
|
||||
*
|
||||
|
@ -3080,6 +3080,7 @@ module Phaser {
|
|||
* @param y {number} The new Y position of this object.
|
||||
*/
|
||||
static reset(sprite: Sprite, x: number, y: number): void;
|
||||
static setOriginToCenter(sprite: Sprite, fromFrameBounds?: bool, fromBody?: bool): void;
|
||||
/**
|
||||
* Set the world bounds that this GameObject can exist within. By default a GameObject can exist anywhere
|
||||
* in the world. But by setting the bounds (which are given in world dimensions, not screen dimensions)
|
||||
|
@ -3468,10 +3469,6 @@ module Phaser {
|
|||
*/
|
||||
public type: number;
|
||||
/**
|
||||
* Reference to the Renderer.renderSprite method. Can be overriden by custom classes.
|
||||
*/
|
||||
public render;
|
||||
/**
|
||||
* Controls if both <code>update</code> and render are called by the core game loop.
|
||||
*/
|
||||
public exists: bool;
|
||||
|
@ -7727,6 +7724,7 @@ module Phaser {
|
|||
module Phaser {
|
||||
interface IRenderer {
|
||||
render();
|
||||
renderGameObject(object);
|
||||
renderSprite(camera: Camera, sprite: Sprite): bool;
|
||||
renderScrollZone(camera: Camera, sprite: ScrollZone): bool;
|
||||
}
|
||||
|
@ -7739,6 +7737,7 @@ module Phaser {
|
|||
*/
|
||||
private _game;
|
||||
public render(): void;
|
||||
public renderGameObject(object): void;
|
||||
public renderSprite(camera: Camera, sprite: Sprite): bool;
|
||||
public renderScrollZone(camera: Camera, scrollZone: ScrollZone): bool;
|
||||
}
|
||||
|
@ -7766,7 +7765,16 @@ module Phaser {
|
|||
private _cameraList;
|
||||
private _camera;
|
||||
private _groupLength;
|
||||
private _count;
|
||||
public renderTotal: number;
|
||||
public render(): void;
|
||||
public renderGameObject(object): void;
|
||||
/**
|
||||
* Check whether this object is visible in a specific camera rectangle.
|
||||
* @param camera {Rectangle} The rectangle you want to check.
|
||||
* @return {boolean} Return true if bounds of this sprite intersects the given rectangle, otherwise return false.
|
||||
*/
|
||||
public inCamera(camera: Camera, sprite: Sprite): bool;
|
||||
/**
|
||||
* Render this sprite to specific camera. Called by game loop after update().
|
||||
* @param camera {Camera} Camera this sprite will be rendered to.
|
||||
|
|
139
build/phaser.js
139
build/phaser.js
|
@ -1337,7 +1337,7 @@ var Phaser;
|
|||
* Calls render on all members of this Group who have a status of visible=true and exists=true
|
||||
* You can also call Object.render directly, which will bypass the visible/exists check.
|
||||
*/
|
||||
function (renderer, camera) {
|
||||
function (camera) {
|
||||
if(camera.isHidden(this) == true) {
|
||||
return;
|
||||
}
|
||||
|
@ -1353,14 +1353,10 @@ 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);
|
||||
// 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);
|
||||
this._member.render(camera);
|
||||
} else {
|
||||
this.game.renderer.renderGameObject(this._member);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -5053,6 +5049,7 @@ var Phaser;
|
|||
/// <reference path="../core/Rectangle.ts" />
|
||||
/// <reference path="../core/Circle.ts" />
|
||||
/// <reference path="../gameobjects/Sprite.ts" />
|
||||
/// <reference path="RectangleUtils.ts" />
|
||||
/**
|
||||
* Phaser - SpriteUtils
|
||||
*
|
||||
|
@ -5074,7 +5071,7 @@ var Phaser;
|
|||
out.push(new Phaser.Point(sprite.x, sprite.y + sprite.height));
|
||||
return out;
|
||||
};
|
||||
SpriteUtils.onScreen = /**
|
||||
SpriteUtils.overlapsPoint = /**
|
||||
* Checks to see if some <code>GameObject</code> overlaps this <code>GameObject</code> or <code>Group</code>.
|
||||
* If the group has a LOT of things in it, it might be faster to use <code>Collision.overlaps()</code>.
|
||||
* WARNING: Currently tilemaps do NOT support screen space overlap checks!
|
||||
|
@ -5190,29 +5187,22 @@ var Phaser;
|
|||
*
|
||||
* @return Whether or not the point overlaps this object.
|
||||
*/
|
||||
/*
|
||||
static overlapsPoint(point: Point, inScreenSpace: bool = false, camera: Camera = null): bool {
|
||||
|
||||
if (!inScreenSpace)
|
||||
{
|
||||
return (point.x > this.x) && (point.x < this.x + this.width) && (point.y > this.y) && (point.y < this.y + this.height);
|
||||
}
|
||||
|
||||
if (camera == null)
|
||||
{
|
||||
camera = this._game.camera;
|
||||
}
|
||||
|
||||
var X: number = point.x - camera.scroll.x;
|
||||
var Y: number = point.y - camera.scroll.y;
|
||||
|
||||
this.getScreenXY(this._point, camera);
|
||||
|
||||
return (X > this._point.x) && (X < this._point.x + this.width) && (Y > this._point.y) && (Y < this._point.y + this.height);
|
||||
|
||||
}
|
||||
*/
|
||||
/**
|
||||
function overlapsPoint(sprite, point, inScreenSpace, camera) {
|
||||
if (typeof inScreenSpace === "undefined") { inScreenSpace = false; }
|
||||
if (typeof camera === "undefined") { camera = null; }
|
||||
if(!inScreenSpace) {
|
||||
return Phaser.RectangleUtils.containsPoint(sprite.body.bounds, point);
|
||||
//return (point.x > sprite.x) && (point.x < sprite.x + sprite.width) && (point.y > sprite.y) && (point.y < sprite.y + sprite.height);
|
||||
}
|
||||
if(camera == null) {
|
||||
camera = sprite.game.camera;
|
||||
}
|
||||
//var x: number = point.x - camera.scroll.x;
|
||||
//var y: number = point.y - camera.scroll.y;
|
||||
//this.getScreenXY(this._point, camera);
|
||||
//return (x > this._point.x) && (X < this._point.x + this.width) && (Y > this._point.y) && (Y < this._point.y + this.height);
|
||||
};
|
||||
SpriteUtils.onScreen = /**
|
||||
* Check and see if this object is currently on screen.
|
||||
*
|
||||
* @param camera {Camera} Specify which game camera you want. If null getScreenXY() will just grab the first global camera.
|
||||
|
@ -5250,7 +5240,7 @@ var Phaser;
|
|||
point.y += (point.y > 0) ? 0.0000001 : -0.0000001;
|
||||
return point;
|
||||
};
|
||||
SpriteUtils.inCamera = /**
|
||||
SpriteUtils.reset = /**
|
||||
* Set the world bounds that this GameObject can exist within based on the size of the current game world.
|
||||
*
|
||||
* @param action {number} The action to take if the object hits the world bounds, either OUT_OF_BOUNDS_KILL or OUT_OF_BOUNDS_STOP
|
||||
|
@ -5264,22 +5254,6 @@ var Phaser;
|
|||
}
|
||||
*/
|
||||
/**
|
||||
* Check whether this object is visible in a specific camera rectangle.
|
||||
* @param camera {Rectangle} The rectangle you want to check.
|
||||
* @return {boolean} Return true if bounds of this sprite intersects the given rectangle, otherwise return false.
|
||||
*/
|
||||
function inCamera(camera, cameraOffsetX, cameraOffsetY) {
|
||||
// Object fixed in place regardless of the camera scrolling? Then it's always visible
|
||||
if(this.scrollFactor.x == 0 && this.scrollFactor.y == 0) {
|
||||
return true;
|
||||
}
|
||||
this._dx = (this.frameBounds.x - camera.x);
|
||||
this._dy = (this.frameBounds.y - camera.y);
|
||||
this._dw = this.frameBounds.width * this.scale.x;
|
||||
this._dh = this.frameBounds.height * this.scale.y;
|
||||
return (camera.right > this._dx) && (camera.x < this._dx + this._dw) && (camera.bottom > this._dy) && (camera.y < this._dy + this._dh);
|
||||
};
|
||||
SpriteUtils.reset = /**
|
||||
* Handy for reviving game objects.
|
||||
* Resets their existence flags and position.
|
||||
*
|
||||
|
@ -5297,6 +5271,15 @@ var Phaser;
|
|||
sprite.body.position.x = x;
|
||||
sprite.body.position.y = y;
|
||||
};
|
||||
SpriteUtils.setOriginToCenter = function setOriginToCenter(sprite, fromFrameBounds, fromBody) {
|
||||
if (typeof fromFrameBounds === "undefined") { fromFrameBounds = true; }
|
||||
if (typeof fromBody === "undefined") { fromBody = false; }
|
||||
if(fromFrameBounds) {
|
||||
sprite.origin.setTo(sprite.frameBounds.halfWidth, sprite.frameBounds.halfHeight);
|
||||
} else if(fromBody) {
|
||||
sprite.origin.setTo(sprite.body.bounds.halfWidth, sprite.body.bounds.halfHeight);
|
||||
}
|
||||
};
|
||||
SpriteUtils.setBounds = /**
|
||||
* Set the world bounds that this GameObject can exist within. By default a GameObject can exist anywhere
|
||||
* in the world. But by setting the bounds (which are given in world dimensions, not screen dimensions)
|
||||
|
@ -5968,9 +5951,10 @@ var Phaser;
|
|||
this.parent.texture.context.fillStyle = color;
|
||||
this.parent.texture.context.fillText('Sprite: (' + this.parent.frameBounds.width + ' x ' + this.parent.frameBounds.height + ')', x, y);
|
||||
//this.parent.texture.context.fillText('x: ' + this._parent.frameBounds.x.toFixed(1) + ' y: ' + this._parent.frameBounds.y.toFixed(1) + ' rotation: ' + this._parent.rotation.toFixed(1), x, y + 14);
|
||||
this.parent.texture.context.fillText('x: ' + this.bounds.x.toFixed(1) + ' y: ' + this.bounds.y.toFixed(1) + ' angle: ' + this.angle.toFixed(1), x, y + 14);
|
||||
this.parent.texture.context.fillText('x: ' + this.bounds.x.toFixed(1) + ' y: ' + this.bounds.y.toFixed(1) + ' angle: ' + this.angle.toFixed(0), x, y + 14);
|
||||
this.parent.texture.context.fillText('vx: ' + this.velocity.x.toFixed(1) + ' vy: ' + this.velocity.y.toFixed(1), x, y + 28);
|
||||
this.parent.texture.context.fillText('ax: ' + this.acceleration.x.toFixed(1) + ' ay: ' + this.acceleration.y.toFixed(1), x, y + 42);
|
||||
this.parent.texture.context.fillText('acx: ' + this.acceleration.x.toFixed(1) + ' acy: ' + this.acceleration.y.toFixed(1), x, y + 42);
|
||||
this.parent.texture.context.fillText('angVx: ' + this.angularVelocity.toFixed(1) + ' angAc: ' + this.angularAcceleration.toFixed(1), x, y + 56);
|
||||
};
|
||||
return Body;
|
||||
})();
|
||||
|
@ -6030,7 +6014,6 @@ var Phaser;
|
|||
this.angleOffset = 0;
|
||||
this.game = game;
|
||||
this.type = Phaser.Types.SPRITE;
|
||||
this.render = game.renderer.renderSprite;
|
||||
this.exists = true;
|
||||
this.active = true;
|
||||
this.visible = true;
|
||||
|
@ -6042,6 +6025,8 @@ var Phaser;
|
|||
this.y = y;
|
||||
this.z = 0// not used yet
|
||||
;
|
||||
// If a texture has been given the body will be set to that size, otherwise 16x16
|
||||
this.body = new Phaser.Physics.Body(this, bodyType);
|
||||
this.animations = new Phaser.Components.AnimationManager(this);
|
||||
this.texture = new Phaser.Components.Texture(this, key);
|
||||
this.cameraBlacklist = [];
|
||||
|
@ -6049,8 +6034,6 @@ var Phaser;
|
|||
this.origin = new Phaser.Vec2(0, 0);
|
||||
this.scale = new Phaser.Vec2(1, 1);
|
||||
this.skew = new Phaser.Vec2(0, 0);
|
||||
// If a texture has been given the body will be set to that size, otherwise 16x16
|
||||
this.body = new Phaser.Physics.Body(this, bodyType);
|
||||
}
|
||||
Object.defineProperty(Sprite.prototype, "angle", {
|
||||
get: /**
|
||||
|
@ -7627,7 +7610,6 @@ 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);
|
||||
|
@ -7731,13 +7713,6 @@ var Phaser;
|
|||
if(multiple) {
|
||||
/*
|
||||
randomFrame = this.game.math.random()*totalFrames;
|
||||
if(BakedRotations > 0)
|
||||
particle.loadRotatedGraphic(Graphics,BakedRotations,randomFrame);
|
||||
else
|
||||
{
|
||||
particle.loadGraphic(Graphics,true);
|
||||
particle.frame = randomFrame;
|
||||
}
|
||||
*/
|
||||
} else {
|
||||
if(graphics) {
|
||||
|
@ -7753,7 +7728,7 @@ var Phaser;
|
|||
particle.body.allowCollisions = Phaser.Types.NONE;
|
||||
}
|
||||
particle.exists = false;
|
||||
// Center it
|
||||
// Center the origin for rotation assistance
|
||||
particle.origin.setTo(particle.body.bounds.halfWidth, particle.body.bounds.halfHeight);
|
||||
this.add(particle);
|
||||
i++;
|
||||
|
@ -8108,7 +8083,6 @@ var Phaser;
|
|||
if (typeof height === "undefined") { height = 0; }
|
||||
_super.call(this, game, x, y, key);
|
||||
this.type = Phaser.Types.SCROLLZONE;
|
||||
this.render = game.renderer.renderScrollZone;
|
||||
this.regions = [];
|
||||
if(this.texture.loaded) {
|
||||
if(width > this.width || height > this.height) {
|
||||
|
@ -14278,6 +14252,8 @@ var Phaser;
|
|||
}
|
||||
HeadlessRenderer.prototype.render = function () {
|
||||
};
|
||||
HeadlessRenderer.prototype.renderGameObject = function (object) {
|
||||
};
|
||||
HeadlessRenderer.prototype.renderSprite = function (camera, sprite) {
|
||||
return true;
|
||||
};
|
||||
|
@ -14316,13 +14292,38 @@ var Phaser;
|
|||
CanvasRenderer.prototype.render = function () {
|
||||
// Get a list of all the active cameras
|
||||
this._cameraList = this._game.world.getAllCameras();
|
||||
this._count = 0;
|
||||
// Then iterate through world.group on them all (where not blacklisted, etc)
|
||||
for(var c = 0; c < this._cameraList.length; c++) {
|
||||
this._camera = this._cameraList[c];
|
||||
this._camera.preRender();
|
||||
this._game.world.group.render(this, this._camera);
|
||||
this._game.world.group.render(this._camera);
|
||||
this._camera.postRender();
|
||||
}
|
||||
this.renderTotal = this._count;
|
||||
};
|
||||
CanvasRenderer.prototype.renderGameObject = function (object) {
|
||||
if(object.type == Phaser.Types.SPRITE) {
|
||||
this.renderSprite(this._camera, object);
|
||||
} else if(object.type == Phaser.Types.SCROLLZONE) {
|
||||
this.renderScrollZone(this._camera, object);
|
||||
}
|
||||
};
|
||||
CanvasRenderer.prototype.inCamera = /**
|
||||
* Check whether this object is visible in a specific camera rectangle.
|
||||
* @param camera {Rectangle} The rectangle you want to check.
|
||||
* @return {boolean} Return true if bounds of this sprite intersects the given rectangle, otherwise return false.
|
||||
*/
|
||||
function (camera, sprite) {
|
||||
// Object fixed in place regardless of the camera scrolling? Then it's always visible
|
||||
if(sprite.scrollFactor.x == 0 && sprite.scrollFactor.y == 0) {
|
||||
return true;
|
||||
}
|
||||
this._dx = sprite.frameBounds.x - camera.worldView.x;
|
||||
this._dy = sprite.frameBounds.y - camera.worldView.y;
|
||||
this._dw = sprite.frameBounds.width * sprite.scale.x;
|
||||
this._dh = sprite.frameBounds.height * sprite.scale.y;
|
||||
return (camera.worldView.right > this._dx) && (camera.worldView.x < this._dx + this._dw) && (camera.worldView.bottom > this._dy) && (camera.worldView.y < this._dy + this._dh);
|
||||
};
|
||||
CanvasRenderer.prototype.renderSprite = /**
|
||||
* Render this sprite to specific camera. Called by game loop after update().
|
||||
|
@ -14330,10 +14331,10 @@ var Phaser;
|
|||
* @return {boolean} Return false if not rendered, otherwise return true.
|
||||
*/
|
||||
function (camera, sprite) {
|
||||
// Render checks (needs inCamera check added)
|
||||
if(sprite.scale.x == 0 || sprite.scale.y == 0 || sprite.texture.alpha < 0.1) {
|
||||
if(sprite.scale.x == 0 || sprite.scale.y == 0 || sprite.texture.alpha < 0.1 || this.inCamera(camera, sprite) == false) {
|
||||
return false;
|
||||
}
|
||||
this._count++;
|
||||
// Reset our temp vars
|
||||
this._ga = -1;
|
||||
this._sx = 0;
|
||||
|
@ -14425,10 +14426,10 @@ var Phaser;
|
|||
return true;
|
||||
};
|
||||
CanvasRenderer.prototype.renderScrollZone = function (camera, scrollZone) {
|
||||
// Render checks (needs inCamera check added)
|
||||
if(scrollZone.scale.x == 0 || scrollZone.scale.y == 0 || scrollZone.texture.alpha < 0.1) {
|
||||
if(scrollZone.scale.x == 0 || scrollZone.scale.y == 0 || scrollZone.texture.alpha < 0.1 || this.inCamera(camera, scrollZone) == false) {
|
||||
return false;
|
||||
}
|
||||
this._count++;
|
||||
// Reset our temp vars
|
||||
this._ga = -1;
|
||||
this._sx = 0;
|
||||
|
|
Loading…
Reference in a new issue