Skip to content
This repository has been archived by the owner on Apr 15, 2022. It is now read-only.

Commit

Permalink
Camera: Deprecated "camera-stationary" and gave "camera-update" a sta…
Browse files Browse the repository at this point in the history
…tionary property instead.
  • Loading branch information
probityrules committed Dec 18, 2015
1 parent f1c1417 commit 8829fda
Show file tree
Hide file tree
Showing 4 changed files with 72 additions and 42 deletions.
69 changes: 39 additions & 30 deletions lib/platypus.combined.js
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ this.platypus = this.platypus || {};
* @type String
* @static
**/
platypus.buildDate = /*=date*/"Fri, 18 Dec 2015 01:36:59 GMT"; // injected by build process
platypus.buildDate = /*=date*/"Fri, 18 Dec 2015 14:34:26 GMT"; // injected by build process

})();

Expand Down Expand Up @@ -786,7 +786,7 @@ platypus.Scene = (function () {
}
messages.length = 0;

this.time = new Date().getTime();
this.time = Date.now();
this.timeElapsed = {
name: '',
time: 0
Expand All @@ -802,32 +802,17 @@ platypus.Scene = (function () {
* @param {*} event This is a message object or other value to pass along to component functions.
**/
proto.trigger = function (eventId, event) {
var i = 0,
time = 0;
var i = 0;

if (this.storedMessages) {
this.storedMessages.push({
message: eventId,
value: event
});
} else {
if (eventId === 'tick') {
time = new Date().getTime();
this.timeElapsed.name = 'Non-Engine';
this.timeElapsed.time = time - this.time;
this.trigger('time-elapsed', this.timeElapsed);
this.time = time;
}
for (i = 0; i < this.layers.length; i++) {
this.layers[i].trigger(eventId, event);
}
if (eventId === 'tick') {
time = new Date().getTime();
this.timeElapsed.name = 'Engine Total';
this.timeElapsed.time = time - this.time;
this.trigger('time-elapsed', this.timeElapsed);
this.time = time;
}
}
};

Expand Down Expand Up @@ -5408,11 +5393,13 @@ platypus.Entity = (function () {
* @class Camera
* @uses platypus.Component
*/
/*global console, createjs, PIXI, platypus, springroll */
/*global console, createjs, PIXI, platypus, include */
/*jslint plusplus:true */
(function () {
"use strict";

var Application = include("springroll.Application");

return platypus.createComponentClass({
id: 'Camera',
properties: {
Expand Down Expand Up @@ -5558,7 +5545,8 @@ platypus.Entity = (function () {
viewport: new platypus.AABB(),
scaleX: 0,
scaleY: 0,
orientation: 0
orientation: 0,
stationary: false
};

//Whether the map has finished loading.
Expand Down Expand Up @@ -5616,7 +5604,7 @@ platypus.Entity = (function () {
if (this.owner.container) {
this.parentContainer = this.owner.container;
} else if (this.owner.stage) {
this.canvas = this.canvas || springroll.Application.instance.display.canvas; //TODO: Probably need to find a better way to handle resizing - DDD 10/4/2015
this.canvas = this.canvas || Application.instance.display.canvas; //TODO: Probably need to find a better way to handle resizing - DDD 10/4/2015
this.parentContainer = this.owner.stage;
this.owner.width = this.canvas.width;
this.owner.height = this.canvas.height;
Expand Down Expand Up @@ -5676,6 +5664,21 @@ platypus.Entity = (function () {
}
},

/**
* Triggers "camera-update" on newly changed entities.
*
* @method 'child-entity-updated'
* @param entity {platypus.Entity} Expects an entity as the message object to determine whether to trigger `camera-update` on it.
* @since 0.6.8
**/
"child-entity-updated": function (entity) {
this.viewportUpdate = true;

if (this.worldIsLoaded) {
entity.triggerEvent('camera-update', this.message);
}
},

/**
* On receiving this message, the camera updates its world location and size as necessary. An example of this message is triggered by the [TiledLoader](platypus.components.TiledLoader.html) component.
*
Expand Down Expand Up @@ -5735,6 +5738,7 @@ platypus.Entity = (function () {
if (this.viewportUpdate) {
this.viewportUpdate = false;
this.stationary = false;
msg.stationary = false;

viewport.set(this.worldCamera.viewport);

Expand Down Expand Up @@ -5775,31 +5779,36 @@ platypus.Entity = (function () {
*
* @event 'camera-update'
* @param message {Object}
* @param message.orientation {number} Number describing the orientation of the camera.
* @param message.scaleX {number} Number of window pixels that comprise a single world coordinate on the x-axis.
* @param message.scaleY {number} Number of window pixels that comprise a single world coordinate on the y-axis.
* @param message.orientation {Number} Number describing the orientation of the camera.
* @param message.scaleX {Number} Number of window pixels that comprise a single world coordinate on the x-axis.
* @param message.scaleY {Number} Number of window pixels that comprise a single world coordinate on the y-axis.
* @param message.viewport {platypus.AABB} An AABB describing the world viewport area.
* @param message.stationary {Boolean} Whether the camera is moving.
**/
this.owner.trigger('camera-update', msg);

if (this.owner.triggerEventOnChildren) {
this.owner.triggerEventOnChildren('camera-update', msg);
}

} else if (!this.stationary) {
this.stationary = true;
msg.stationary = true;

this.owner.trigger('camera-update', msg);
if (this.owner.triggerEventOnChildren) {
this.owner.triggerEventOnChildren('camera-update', msg);
}

/**
* This component triggers "camera-stationary" on the entity when the camera stops moving.
*
* @event 'camera-stationary'
* @deprecated since 0.6.8 - Listen for "camera-update" instead, with a `stationary` property of `true`.
**/
this.owner.trigger('camera-stationary', msg);
this.stationary = true;

}

if (this.lastFollow.begin) {
if (this.lastFollow.begin < new Date().getTime()) {
if (this.lastFollow.begin < Date.now()) {
this.follow(this.lastFollow);
}
}
Expand Down Expand Up @@ -5923,7 +5932,7 @@ platypus.Entity = (function () {
this.lastFollow.offsetX = this.offsetX;
this.lastFollow.offsetY = this.offsetY;
}
this.lastFollow.begin = new Date().getTime() + def.time;
this.lastFollow.begin = Date.now() + def.time;
} else {
if (this.lastFollow.begin) {
this.lastFollow.begin = 0;
Expand Down
4 changes: 2 additions & 2 deletions lib/platypus.min.js

Large diffs are not rendered by default.

3 changes: 1 addition & 2 deletions src/Scene.js
Original file line number Diff line number Diff line change
Expand Up @@ -109,8 +109,7 @@ platypus.Scene = (function () {
* @param {*} event This is a message object or other value to pass along to component functions.
**/
proto.trigger = function (eventId, event) {
var i = 0,
time = 0;
var i = 0;

if (this.storedMessages) {
this.storedMessages.push({
Expand Down
38 changes: 30 additions & 8 deletions src/components/Camera.js
Original file line number Diff line number Diff line change
Expand Up @@ -159,7 +159,8 @@
viewport: new platypus.AABB(),
scaleX: 0,
scaleY: 0,
orientation: 0
orientation: 0,
stationary: false
};

//Whether the map has finished loading.
Expand Down Expand Up @@ -277,6 +278,21 @@
}
},

/**
* Triggers "camera-update" on newly changed entities.
*
* @method 'child-entity-updated'
* @param entity {platypus.Entity} Expects an entity as the message object to determine whether to trigger `camera-update` on it.
* @since 0.6.8
**/
"child-entity-updated": function (entity) {
this.viewportUpdate = true;

if (this.worldIsLoaded) {
entity.triggerEvent('camera-update', this.message);
}
},

/**
* On receiving this message, the camera updates its world location and size as necessary. An example of this message is triggered by the [TiledLoader](platypus.components.TiledLoader.html) component.
*
Expand Down Expand Up @@ -336,6 +352,7 @@
if (this.viewportUpdate) {
this.viewportUpdate = false;
this.stationary = false;
msg.stationary = false;

viewport.set(this.worldCamera.viewport);

Expand Down Expand Up @@ -376,27 +393,32 @@
*
* @event 'camera-update'
* @param message {Object}
* @param message.orientation {number} Number describing the orientation of the camera.
* @param message.scaleX {number} Number of window pixels that comprise a single world coordinate on the x-axis.
* @param message.scaleY {number} Number of window pixels that comprise a single world coordinate on the y-axis.
* @param message.orientation {Number} Number describing the orientation of the camera.
* @param message.scaleX {Number} Number of window pixels that comprise a single world coordinate on the x-axis.
* @param message.scaleY {Number} Number of window pixels that comprise a single world coordinate on the y-axis.
* @param message.viewport {platypus.AABB} An AABB describing the world viewport area.
* @param message.stationary {Boolean} Whether the camera is moving.
**/
this.owner.trigger('camera-update', msg);

if (this.owner.triggerEventOnChildren) {
this.owner.triggerEventOnChildren('camera-update', msg);
}

} else if (!this.stationary) {
this.stationary = true;
msg.stationary = true;

this.owner.trigger('camera-update', msg);
if (this.owner.triggerEventOnChildren) {
this.owner.triggerEventOnChildren('camera-update', msg);
}

/**
* This component triggers "camera-stationary" on the entity when the camera stops moving.
*
* @event 'camera-stationary'
* @deprecated since 0.6.8 - Listen for "camera-update" instead, with a `stationary` property of `true`.
**/
this.owner.trigger('camera-stationary', msg);
this.stationary = true;

}

if (this.lastFollow.begin) {
Expand Down

0 comments on commit 8829fda

Please sign in to comment.