mirror of
https://github.com/wassname/phaser.git
synced 2026-06-27 16:10:15 +08:00
Added a Sample Plugin and tested out the Plugin Manager. Working great :)
This commit is contained in:
+123
-813
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,37 @@
|
||||
/**
|
||||
* A Sample Plugin demonstrating how to hook into the Phaser plugin system.
|
||||
*/
|
||||
Phaser.Plugin.SamplePlugin = function (game, parent) {
|
||||
|
||||
Phaser.Plugin.call(this, game, parent);
|
||||
|
||||
this.sprite = null;
|
||||
|
||||
};
|
||||
|
||||
// Extends the Phaser.Plugin template, setting up values we need
|
||||
Phaser.Plugin.SamplePlugin.prototype = Object.create(Phaser.Plugin.prototype);
|
||||
Phaser.Plugin.SamplePlugin.prototype.constructor = Phaser.Plugin.SamplePlugin;
|
||||
|
||||
/**
|
||||
* Add a Sprite reference to this Plugin.
|
||||
* All this plugin does is move the Sprite across the screen slowly.
|
||||
* @type {Phaser.Sprite}
|
||||
*/
|
||||
Phaser.Plugin.SamplePlugin.prototype.addSprite = function (sprite) {
|
||||
|
||||
this.sprite = sprite;
|
||||
|
||||
};
|
||||
|
||||
/**
|
||||
* This is run when the plugins update during the core game loop.
|
||||
*/
|
||||
Phaser.Plugin.SamplePlugin.prototype.update = function () {
|
||||
|
||||
if (this.sprite)
|
||||
{
|
||||
this.sprite.x += 0.5;
|
||||
}
|
||||
|
||||
};
|
||||
@@ -0,0 +1,44 @@
|
||||
<!DOCTYPE HTML>
|
||||
<html>
|
||||
<head>
|
||||
<title>phaser.js - a new beginning</title>
|
||||
<?php
|
||||
require('js.php');
|
||||
?>
|
||||
<script src="../plugins/SamplePlugin.js"></script>
|
||||
</head>
|
||||
<body>
|
||||
|
||||
<script type="text/javascript">
|
||||
|
||||
(function () {
|
||||
|
||||
var game = new Phaser.Game(800, 600, Phaser.AUTO, '', { preload: preload, create: create });
|
||||
|
||||
var plugin;
|
||||
|
||||
function preload() {
|
||||
|
||||
game.load.image('atari1', 'assets/sprites/atari130xe.png');
|
||||
|
||||
}
|
||||
|
||||
function create() {
|
||||
|
||||
// Create our SamplePlugin.
|
||||
// All the SamplePlugin does is move a sprite across the screen,
|
||||
// but it shows how to structure a plugin and hook it into key functions
|
||||
|
||||
plugin = game.plugins.add(Phaser.Plugin.SamplePlugin);
|
||||
|
||||
var tempSprite = game.add.sprite(0, 200, 'atari1');
|
||||
|
||||
plugin.addSprite(tempSprite);
|
||||
|
||||
}
|
||||
|
||||
})();
|
||||
</script>
|
||||
|
||||
</body>
|
||||
</html>
|
||||
@@ -394,6 +394,7 @@ Phaser.Game.prototype = {
|
||||
this.plugins.update();
|
||||
|
||||
this.renderer.render(this.stage._stage);
|
||||
this.plugins.render();
|
||||
this.state.render();
|
||||
|
||||
this.plugins.postRender();
|
||||
|
||||
+4
-20
@@ -13,8 +13,6 @@ Phaser.Plugin = function (game, parent) {
|
||||
|
||||
this.hasPreUpdate = false;
|
||||
this.hasUpdate = false;
|
||||
this.hasPostUpdate = false;
|
||||
this.hasPreRender = false;
|
||||
this.hasRender = false;
|
||||
this.hasPostRender = false;
|
||||
|
||||
@@ -23,42 +21,28 @@ Phaser.Plugin = function (game, parent) {
|
||||
Phaser.Plugin.prototype = {
|
||||
|
||||
/**
|
||||
* Pre-update is called at the start of the update cycle, before any other updates have taken place.
|
||||
* Pre-update is called at the start of the update cycle, before any other updates have taken place (including Physics).
|
||||
* It is only called if active is set to true.
|
||||
*/
|
||||
preUpdate: function () {
|
||||
},
|
||||
|
||||
/**
|
||||
* Pre-update is called at the start of the update cycle, before any other updates have taken place.
|
||||
* Update is called after all the core subsystems (Input, Tweens, Sound, etc) and the State have updated, but before the render.
|
||||
* It is only called if active is set to true.
|
||||
*/
|
||||
update: function () {
|
||||
},
|
||||
|
||||
/**
|
||||
* Post-update is called at the end of the objects update cycle, after other update logic has taken place.
|
||||
* It is only called if active is set to true.
|
||||
*/
|
||||
postUpdate: function () {
|
||||
},
|
||||
|
||||
/**
|
||||
* Pre-render is called right before the Game Renderer starts and before any custom preRender callbacks have been run.
|
||||
* It is only called if visible is set to true.
|
||||
*/
|
||||
preRender: function () {
|
||||
},
|
||||
|
||||
/**
|
||||
* Pre-render is called right before the Game Renderer starts and before any custom preRender callbacks have been run.
|
||||
* Render is called right after the Game Renderer completes, but before the State.render.
|
||||
* It is only called if visible is set to true.
|
||||
*/
|
||||
render: function () {
|
||||
},
|
||||
|
||||
/**
|
||||
* Post-render is called after every camera and game object has been rendered, also after any custom postRender callbacks have been run.
|
||||
* Post-render is called after the Game Renderer and State.render have run.
|
||||
* It is only called if visible is set to true.
|
||||
*/
|
||||
postRender: function () {
|
||||
|
||||
+28
-58
@@ -36,52 +36,45 @@ Phaser.PluginManager.prototype = {
|
||||
}
|
||||
|
||||
// Check for methods now to avoid having to do this every loop
|
||||
if (typeof plugin['preUpdate'] === 'function') {
|
||||
if (typeof plugin['preUpdate'] === 'function')
|
||||
{
|
||||
plugin.hasPreUpdate = true;
|
||||
result = true;
|
||||
}
|
||||
|
||||
if (typeof plugin['update'] === 'function') {
|
||||
if (typeof plugin['update'] === 'function')
|
||||
{
|
||||
plugin.hasUpdate = true;
|
||||
result = true;
|
||||
}
|
||||
|
||||
if (typeof plugin['postUpdate'] === 'function') {
|
||||
plugin.hasPostUpdate = true;
|
||||
result = true;
|
||||
}
|
||||
|
||||
if (typeof plugin['preRender'] === 'function') {
|
||||
plugin.hasPreRender = true;
|
||||
result = true;
|
||||
}
|
||||
|
||||
if (typeof plugin['render'] === 'function') {
|
||||
if (typeof plugin['render'] === 'function')
|
||||
{
|
||||
plugin.hasRender = true;
|
||||
result = true;
|
||||
}
|
||||
|
||||
if (typeof plugin['postRender'] === 'function') {
|
||||
if (typeof plugin['postRender'] === 'function')
|
||||
{
|
||||
plugin.hasPostRender = true;
|
||||
result = true;
|
||||
}
|
||||
|
||||
// The plugin must have at least one of the above functions to be added to the PluginManager.
|
||||
if (result) {
|
||||
|
||||
if (plugin.hasPreUpdate || plugin.hasUpdate || plugin.hasPostUpdate)
|
||||
if (result)
|
||||
{
|
||||
if (plugin.hasPreUpdate || plugin.hasUpdate)
|
||||
{
|
||||
plugin.active = true;
|
||||
}
|
||||
|
||||
if (plugin.hasPreRender || plugin.hasRender || plugin.hasPostRender)
|
||||
if (plugin.hasRender || plugin.hasPostRender)
|
||||
{
|
||||
plugin.visible = true;
|
||||
}
|
||||
|
||||
this._pluginsLength = this.plugins.push(plugin);
|
||||
return plugin;
|
||||
|
||||
}
|
||||
else
|
||||
{
|
||||
@@ -103,8 +96,10 @@ Phaser.PluginManager.prototype = {
|
||||
return;
|
||||
}
|
||||
|
||||
for (this._p = 0; this._p < this._pluginsLength; this._p++) {
|
||||
if (this.plugins[this._p].active && this.plugins[this._p].hasPreUpdate) {
|
||||
for (this._p = 0; this._p < this._pluginsLength; this._p++)
|
||||
{
|
||||
if (this.plugins[this._p].active && this.plugins[this._p].hasPreUpdate)
|
||||
{
|
||||
this.plugins[this._p].preUpdate();
|
||||
}
|
||||
}
|
||||
@@ -118,44 +113,16 @@ Phaser.PluginManager.prototype = {
|
||||
return;
|
||||
}
|
||||
|
||||
for (this._p = 0; this._p < this._pluginsLength; this._p++) {
|
||||
if (this.plugins[this._p].active && this.plugins[this._p].hasUpdate) {
|
||||
for (this._p = 0; this._p < this._pluginsLength; this._p++)
|
||||
{
|
||||
if (this.plugins[this._p].active && this.plugins[this._p].hasUpdate)
|
||||
{
|
||||
this.plugins[this._p].update();
|
||||
}
|
||||
}
|
||||
|
||||
},
|
||||
|
||||
postUpdate: function () {
|
||||
|
||||
if (this._pluginsLength == 0)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
for (this._p = 0; this._p < this._pluginsLength; this._p++) {
|
||||
if (this.plugins[this._p].active && this.plugins[this._p].hasPostUpdate) {
|
||||
this.plugins[this._p].postUpdate();
|
||||
}
|
||||
}
|
||||
|
||||
},
|
||||
|
||||
preRender: function () {
|
||||
|
||||
if (this._pluginsLength == 0)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
for (this._p = 0; this._p < this._pluginsLength; this._p++) {
|
||||
if (this.plugins[this._p].visible && this.plugins[this._p].hasPreRender) {
|
||||
this.plugins[this._p].preRender();
|
||||
}
|
||||
}
|
||||
|
||||
},
|
||||
|
||||
render: function () {
|
||||
|
||||
if (this._pluginsLength == 0)
|
||||
@@ -163,8 +130,10 @@ Phaser.PluginManager.prototype = {
|
||||
return;
|
||||
}
|
||||
|
||||
for (this._p = 0; this._p < this._pluginsLength; this._p++) {
|
||||
if (this.plugins[this._p].visible && this.plugins[this._p].hasRender) {
|
||||
for (this._p = 0; this._p < this._pluginsLength; this._p++)
|
||||
{
|
||||
if (this.plugins[this._p].visible && this.plugins[this._p].hasRender)
|
||||
{
|
||||
this.plugins[this._p].render();
|
||||
}
|
||||
}
|
||||
@@ -178,9 +147,10 @@ Phaser.PluginManager.prototype = {
|
||||
return;
|
||||
}
|
||||
|
||||
for (this._p = 0; this._p < this._pluginsLength; this._p++) {
|
||||
|
||||
if (this.plugins[this._p].visible && this.plugins[this._p].hasPostRender) {
|
||||
for (this._p = 0; this._p < this._pluginsLength; this._p++)
|
||||
{
|
||||
if (this.plugins[this._p].visible && this.plugins[this._p].hasPostRender)
|
||||
{
|
||||
this.plugins[this._p].postRender();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,364 @@
|
||||
Phaser.Bullet = function (game, x, y, key, frame) {
|
||||
|
||||
x = x || 0;
|
||||
y = y || 0;
|
||||
key = key || null;
|
||||
frame = frame || null;
|
||||
|
||||
this.game = game;
|
||||
|
||||
// If exists = false then the Sprite isn't updated by the core game loop or physics subsystem at all
|
||||
this.exists = true;
|
||||
|
||||
// This is a handy little var your game can use to determine if a sprite is alive or not, it doesn't effect rendering
|
||||
this.alive = true;
|
||||
|
||||
this.group = null;
|
||||
|
||||
this.name = '';
|
||||
|
||||
this.renderOrderID = -1;
|
||||
|
||||
// If you would like the Sprite to have a lifespan once 'born' you can set this to a positive value. Handy for particles, bullets, etc.
|
||||
// The lifespan is decremented by game.time.elapsed each update, once it reaches zero the kill() function is called.
|
||||
this.lifespan = 0;
|
||||
|
||||
this.key = key;
|
||||
|
||||
if (key instanceof Phaser.RenderTexture)
|
||||
{
|
||||
PIXI.Sprite.call(this, key);
|
||||
|
||||
this.currentFrame = this.game.cache.getTextureFrame(key.name);
|
||||
}
|
||||
else
|
||||
{
|
||||
if (key == null || this.game.cache.checkImageKey(key) == false)
|
||||
{
|
||||
key = '__default';
|
||||
}
|
||||
|
||||
PIXI.Sprite.call(this, PIXI.TextureCache[key]);
|
||||
|
||||
if (this.game.cache.isSpriteSheet(key))
|
||||
{
|
||||
if (frame !== null)
|
||||
{
|
||||
if (typeof frame === 'string')
|
||||
{
|
||||
this.currentFrame = this.game.cache.getFrameByName(key, frame);
|
||||
}
|
||||
else
|
||||
{
|
||||
this.currentFrame = this.game.cache.getFrameByIndex(key, frame);
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
this.currentFrame = this.game.cache.getFrame(key);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* The anchor sets the origin point of the texture.
|
||||
* The default is 0,0 this means the textures origin is the top left
|
||||
* Setting than anchor to 0.5,0.5 means the textures origin is centered
|
||||
* Setting the anchor to 1,1 would mean the textures origin points will be the bottom right
|
||||
*
|
||||
* @property anchor
|
||||
* @type Point
|
||||
*/
|
||||
this.anchor = new Phaser.Point();
|
||||
|
||||
this.x = x;
|
||||
this.y = y;
|
||||
|
||||
this.position.x = x;
|
||||
this.position.y = y;
|
||||
|
||||
/**
|
||||
* Should this Sprite be automatically culled if out of range of the camera?
|
||||
* A culled sprite has its visible property set to 'false'.
|
||||
* Note that this check doesn't look at this Sprites children, which may still be in camera range.
|
||||
* So you should set autoCull to false if the Sprite will have children likely to still be in camera range.
|
||||
*
|
||||
* @property autoCull
|
||||
* @type Boolean
|
||||
*/
|
||||
this.autoCull = false;
|
||||
|
||||
// Replaces the PIXI.Point with a slightly more flexible one
|
||||
this.scale = new Phaser.Point(1, 1);
|
||||
|
||||
// Influence of camera movement upon the position
|
||||
this.scrollFactor = new Phaser.Point(1, 1);
|
||||
|
||||
// A mini cache for storing all of the calculated values
|
||||
this._cache = {
|
||||
|
||||
dirty: false,
|
||||
|
||||
// Transform cache
|
||||
a00: 1, a01: 0, a02: x, a10: 0, a11: 1, a12: y, id: 1,
|
||||
|
||||
// Input specific transform cache
|
||||
i01: 0, i10: 0, idi: 1,
|
||||
|
||||
// Bounds check
|
||||
left: null, right: null, top: null, bottom: null,
|
||||
|
||||
// The previous calculated position inc. camera x/y and scrollFactor
|
||||
x: -1, y: -1,
|
||||
|
||||
// The actual scale values based on the worldTransform
|
||||
scaleX: 1, scaleY: 1,
|
||||
|
||||
// The width/height of the image, based on the un-modified frame size multiplied by the final calculated scale size
|
||||
width: this.currentFrame.sourceSizeW, height: this.currentFrame.sourceSizeH,
|
||||
|
||||
// The actual width/height of the image if from a trimmed atlas, multiplied by the final calculated scale size
|
||||
halfWidth: Math.floor(this.currentFrame.sourceSizeW / 2), halfHeight: Math.floor(this.currentFrame.sourceSizeH / 2),
|
||||
|
||||
// The current frame details
|
||||
frameID: this.currentFrame.uuid, frameWidth: this.currentFrame.width, frameHeight: this.currentFrame.height,
|
||||
|
||||
boundsX: 0, boundsY: 0,
|
||||
|
||||
// If this sprite visible to the camera (regardless of being set to visible or not)
|
||||
cameraVisible: true
|
||||
|
||||
};
|
||||
|
||||
this.bounds = new Phaser.Rectangle(x, y, this.currentFrame.sourceSizeW, this.currentFrame.sourceSizeH);
|
||||
|
||||
// Set-up the physics body
|
||||
this.body = new Phaser.Physics.Arcade.Body(this);
|
||||
|
||||
// World bounds check
|
||||
this.inWorld = Phaser.Rectangle.intersects(this.bounds, this.game.world.bounds);
|
||||
this.inWorldThreshold = 0;
|
||||
this._outOfBoundsFired = false;
|
||||
|
||||
};
|
||||
|
||||
// Needed to keep the PIXI.Sprite constructor in the prototype chain (as the core pixi renderer uses an instanceof check sadly)
|
||||
Phaser.Bullet.prototype = Object.create(PIXI.Sprite.prototype);
|
||||
Phaser.Bullet.prototype.constructor = Phaser.Bullet;
|
||||
|
||||
/**
|
||||
* Automatically called by World.update. You can create your own update in Objects that extend Phaser.Bullet.
|
||||
*/
|
||||
Phaser.Bullet.prototype.preUpdate = function() {
|
||||
|
||||
if (!this.exists)
|
||||
{
|
||||
this.renderOrderID = -1;
|
||||
return;
|
||||
}
|
||||
|
||||
if (this.lifespan > 0)
|
||||
{
|
||||
this.lifespan -= this.game.time.elapsed;
|
||||
|
||||
if (this.lifespan <= 0)
|
||||
{
|
||||
this.kill();
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
// this._cache.dirty = false;
|
||||
|
||||
this._cache.x = this.x - (this.game.world.camera.x * this.scrollFactor.x);
|
||||
this._cache.y = this.y - (this.game.world.camera.y * this.scrollFactor.y);
|
||||
|
||||
// If this sprite or the camera have moved then let's update everything
|
||||
if (this.position.x != this._cache.x || this.position.y != this._cache.y)
|
||||
{
|
||||
this.position.x = this._cache.x;
|
||||
this.position.y = this._cache.y;
|
||||
// this._cache.dirty = true;
|
||||
}
|
||||
|
||||
if (this.visible)
|
||||
{
|
||||
this.renderOrderID = this.game.world.currentRenderOrderID++;
|
||||
|
||||
/*
|
||||
|
||||
// Only update the values we need
|
||||
if (this.worldTransform[0] != this._cache.a00 || this.worldTransform[1] != this._cache.a01)
|
||||
{
|
||||
this._cache.a00 = this.worldTransform[0]; // scaleX a
|
||||
this._cache.a01 = this.worldTransform[1]; // skewY c
|
||||
this._cache.i01 = this.worldTransform[1]; // skewY c
|
||||
this._cache.scaleX = Math.sqrt((this._cache.a00 * this._cache.a00) + (this._cache.a01 * this._cache.a01)); // round this off a bit?
|
||||
this._cache.a01 *= -1;
|
||||
this._cache.dirty = true;
|
||||
}
|
||||
|
||||
// Need to test, but probably highly unlikely that a scaleX would happen without effecting the Y skew
|
||||
if (this.worldTransform[3] != this._cache.a10 || this.worldTransform[4] != this._cache.a11)
|
||||
{
|
||||
this._cache.a10 = this.worldTransform[3]; // skewX b
|
||||
this._cache.i10 = this.worldTransform[3]; // skewX b
|
||||
this._cache.a11 = this.worldTransform[4]; // scaleY d
|
||||
this._cache.scaleY = Math.sqrt((this._cache.a10 * this._cache.a10) + (this._cache.a11 * this._cache.a11)); // round this off a bit?
|
||||
this._cache.a10 *= -1;
|
||||
this._cache.dirty = true;
|
||||
}
|
||||
|
||||
if (this.worldTransform[2] != this._cache.a02 || this.worldTransform[5] != this._cache.a12)
|
||||
{
|
||||
this._cache.a02 = this.worldTransform[2]; // translateX tx
|
||||
this._cache.a12 = this.worldTransform[5]; // translateY ty
|
||||
this._cache.dirty = true;
|
||||
}
|
||||
|
||||
if (this._cache.dirty)
|
||||
{
|
||||
this._cache.width = Math.floor(this.currentFrame.sourceSizeW * this._cache.scaleX);
|
||||
this._cache.height = Math.floor(this.currentFrame.sourceSizeH * this._cache.scaleY);
|
||||
this._cache.halfWidth = Math.floor(this._cache.width / 2);
|
||||
this._cache.halfHeight = Math.floor(this._cache.height / 2);
|
||||
|
||||
this._cache.id = 1 / (this._cache.a00 * this._cache.a11 + this._cache.a01 * -this._cache.a10);
|
||||
this._cache.idi = 1 / (this._cache.a00 * this._cache.a11 + this._cache.i01 * -this._cache.i10);
|
||||
|
||||
this.updateBounds();
|
||||
}
|
||||
*/
|
||||
}
|
||||
else
|
||||
{
|
||||
// We still need to work out the bounds in case the camera has moved
|
||||
// but we can't use the local or worldTransform to do it, as Pixi resets that if a Sprite is invisible.
|
||||
// So we'll compare against the cached state + new position.
|
||||
if (this._cache.dirty && this.visible == false)
|
||||
{
|
||||
this.bounds.x -= this._cache.boundsX - this._cache.x;
|
||||
this._cache.boundsX = this._cache.x;
|
||||
|
||||
this.bounds.y -= this._cache.boundsy - this._cache.y;
|
||||
this._cache.boundsY = this._cache.y;
|
||||
}
|
||||
}
|
||||
|
||||
// Re-run the camera visibility check
|
||||
// if (this._cache.dirty)
|
||||
// {
|
||||
this._cache.cameraVisible = Phaser.Rectangle.intersects(this.game.world.camera.screenView, this.bounds, 0);
|
||||
|
||||
if (this.autoCull == true)
|
||||
{
|
||||
this.visible = this._cache.cameraVisible;
|
||||
}
|
||||
|
||||
// Update our physics bounds
|
||||
this.body.updateBounds(this.center.x, this.center.y, this._cache.scaleX, this._cache.scaleY);
|
||||
// }
|
||||
|
||||
this.body.update();
|
||||
|
||||
}
|
||||
|
||||
Phaser.Bullet.prototype.revive = function() {
|
||||
|
||||
this.alive = true;
|
||||
this.exists = true;
|
||||
this.visible = true;
|
||||
// this.events.onRevived.dispatch(this);
|
||||
|
||||
}
|
||||
|
||||
Phaser.Bullet.prototype.kill = function() {
|
||||
|
||||
this.alive = false;
|
||||
this.exists = false;
|
||||
this.visible = false;
|
||||
// this.events.onKilled.dispatch(this);
|
||||
|
||||
}
|
||||
|
||||
Phaser.Bullet.prototype.reset = function(x, y) {
|
||||
|
||||
this.x = x;
|
||||
this.y = y;
|
||||
this.position.x = x;
|
||||
this.position.y = y;
|
||||
this.alive = true;
|
||||
this.exists = true;
|
||||
this.visible = true;
|
||||
this._outOfBoundsFired = false;
|
||||
this.body.reset();
|
||||
|
||||
}
|
||||
|
||||
Phaser.Bullet.prototype.updateBounds = function() {
|
||||
|
||||
// Update the edge points
|
||||
|
||||
// this.bounds.setTo(this._cache.left, this._cache.top, this._cache.right - this._cache.left, this._cache.bottom - this._cache.top);
|
||||
|
||||
if (this.inWorld == false)
|
||||
{
|
||||
// Sprite WAS out of the screen, is it still?
|
||||
this.inWorld = Phaser.Rectangle.intersects(this.bounds, this.game.world.bounds, this.inWorldThreshold);
|
||||
|
||||
if (this.inWorld)
|
||||
{
|
||||
// It's back again, reset the OOB check
|
||||
this._outOfBoundsFired = false;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
// Sprite WAS in the screen, has it now left?
|
||||
this.inWorld = Phaser.Rectangle.intersects(this.bounds, this.game.world.bounds, this.inWorldThreshold);
|
||||
|
||||
if (this.inWorld == false)
|
||||
{
|
||||
this.events.onOutOfBounds.dispatch(this);
|
||||
this._outOfBoundsFired = true;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Phaser.Bullet.prototype.bringToTop = function() {
|
||||
|
||||
if (this.group)
|
||||
{
|
||||
this.group.bringToTop(this);
|
||||
}
|
||||
else
|
||||
{
|
||||
this.game.world.bringToTop(this);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Object.defineProperty(Phaser.Bullet.prototype, 'angle', {
|
||||
|
||||
get: function() {
|
||||
return Phaser.Math.radToDeg(this.rotation);
|
||||
},
|
||||
|
||||
set: function(value) {
|
||||
this.rotation = Phaser.Math.degToRad(value);
|
||||
}
|
||||
|
||||
});
|
||||
|
||||
Object.defineProperty(Phaser.Bullet.prototype, "inCamera", {
|
||||
|
||||
/**
|
||||
* Is this sprite visible to the camera or not?
|
||||
*/
|
||||
get: function () {
|
||||
return this._cache.cameraVisible;
|
||||
}
|
||||
|
||||
});
|
||||
|
||||
@@ -330,6 +330,36 @@ Phaser.Cache.prototype = {
|
||||
return null;
|
||||
},
|
||||
|
||||
/**
|
||||
* Get a single frame out of a frameData set by key.
|
||||
* @param key Asset key of the frame data you want.
|
||||
* @return {object} The frame data you want.
|
||||
*/
|
||||
getFrameByIndex: function (key, frame) {
|
||||
|
||||
if (this._images[key] && this._images[key].frameData)
|
||||
{
|
||||
return this._images[key].frameData.getFrame(frame);
|
||||
}
|
||||
|
||||
return null;
|
||||
},
|
||||
|
||||
/**
|
||||
* Get a single frame out of a frameData set by key.
|
||||
* @param key Asset key of the frame data you want.
|
||||
* @return {object} The frame data you want.
|
||||
*/
|
||||
getFrameByName: function (key, frame) {
|
||||
|
||||
if (this._images[key] && this._images[key].frameData)
|
||||
{
|
||||
return this._images[key].frameData.getFrameByName(frame);
|
||||
}
|
||||
|
||||
return null;
|
||||
},
|
||||
|
||||
/**
|
||||
* Get a single frame by key. You'd only do this to get the default Frame created for a non-atlas/spritesheet image.
|
||||
* @param key Asset key of the frame data you want.
|
||||
|
||||
Reference in New Issue
Block a user