mirror of
https://github.com/photonstorm/phaser
synced 2024-11-14 00:47:29 +00:00
Added IsoBox shape
This commit is contained in:
parent
fb5bf5d9c1
commit
d25ad0cf68
6 changed files with 263 additions and 0 deletions
|
@ -41,6 +41,7 @@ var GameObjects = {
|
|||
Shape: require('./shape/Shape'),
|
||||
Arc: require('./shape/arc/Arc'),
|
||||
Ellipse: require('./shape/ellipse/Ellipse'),
|
||||
IsoBox: require('./shape/isobox/IsoBox'),
|
||||
Polygon: require('./shape/polygon/Polygon'),
|
||||
Rectangle: require('./shape/rectangle/Rectangle'),
|
||||
Triangle: require('./shape/triangle/Triangle'),
|
||||
|
@ -66,6 +67,7 @@ var GameObjects = {
|
|||
// Shapes
|
||||
Arc: require('./shape/arc/ArcFactory'),
|
||||
Ellipse: require('./shape/ellipse/EllipseFactory'),
|
||||
IsoBox: require('./shape/isobox/IsoBoxFactory'),
|
||||
Polygon: require('./shape/polygon/PolygonFactory'),
|
||||
Rectangle: require('./shape/rectangle/RectangleFactory'),
|
||||
Triangle: require('./shape/triangle/TriangleFactory')
|
||||
|
|
60
src/gameobjects/shape/isobox/IsoBox.js
Normal file
60
src/gameobjects/shape/isobox/IsoBox.js
Normal file
|
@ -0,0 +1,60 @@
|
|||
/**
|
||||
* @author Richard Davey <rich@photonstorm.com>
|
||||
* @copyright 2018 Photon Storm Ltd.
|
||||
* @license {@link https://github.com/photonstorm/phaser/blob/master/license.txt|MIT License}
|
||||
*/
|
||||
|
||||
var IsoBoxRender = require('./IsoBoxRender');
|
||||
var Class = require('../../../utils/Class');
|
||||
var Shape = require('../Shape');
|
||||
|
||||
/**
|
||||
* @classdesc
|
||||
*
|
||||
* @class IsoBox
|
||||
* @extends Phaser.GameObjects.Shape
|
||||
* @memberOf Phaser.GameObjects
|
||||
* @constructor
|
||||
* @since 3.13.0
|
||||
*
|
||||
* @param {Phaser.Scene} scene - The Scene to which this Game Object belongs. A Game Object can only belong to one Scene at a time.
|
||||
* @param {number} x - The horizontal position of this Game Object in the world.
|
||||
* @param {number} y - The vertical position of this Game Object in the world.
|
||||
*/
|
||||
var IsoBox = new Class({
|
||||
|
||||
Extends: Shape,
|
||||
|
||||
Mixins: [
|
||||
IsoBoxRender
|
||||
],
|
||||
|
||||
initialize:
|
||||
|
||||
function IsoBox (scene, x, y, size, height, fillTop, fillLeft, fillRight)
|
||||
{
|
||||
if (x === undefined) { x = 0; }
|
||||
if (y === undefined) { y = 0; }
|
||||
if (size === undefined) { size = 48; }
|
||||
if (height === undefined) { height = 32; }
|
||||
if (fillTop === undefined) { fillTop = 0xeeeeee; }
|
||||
if (fillLeft === undefined) { fillLeft = 0x999999; }
|
||||
if (fillRight === undefined) { fillRight = 0xcccccc; }
|
||||
|
||||
Shape.call(this, scene, 'IsoBox', null);
|
||||
|
||||
this.fillTop = fillTop;
|
||||
this.fillLeft = fillLeft;
|
||||
this.fillRight = fillRight;
|
||||
|
||||
this.isFilled = true;
|
||||
|
||||
this.setPosition(x, y);
|
||||
this.setSize(size, height);
|
||||
|
||||
this.updateDisplayOrigin();
|
||||
}
|
||||
|
||||
});
|
||||
|
||||
module.exports = IsoBox;
|
26
src/gameobjects/shape/isobox/IsoBoxCanvasRenderer.js
Normal file
26
src/gameobjects/shape/isobox/IsoBoxCanvasRenderer.js
Normal file
|
@ -0,0 +1,26 @@
|
|||
/**
|
||||
* @author Richard Davey <rich@photonstorm.com>
|
||||
* @copyright 2018 Photon Storm Ltd.
|
||||
* @license {@link https://github.com/photonstorm/phaser/blob/master/license.txt|MIT License}
|
||||
*/
|
||||
|
||||
/**
|
||||
* Renders this Game Object with the Canvas Renderer to the given Camera.
|
||||
* The object will not render if any of its renderFlags are set or it is being actively filtered out by the Camera.
|
||||
* This method should not be called directly. It is a utility function of the Render module.
|
||||
*
|
||||
* @method Phaser.GameObjects.IsoBox#renderCanvas
|
||||
* @since 3.13.0
|
||||
* @private
|
||||
*
|
||||
* @param {Phaser.Renderer.Canvas.CanvasRenderer} renderer - A reference to the current active Canvas renderer.
|
||||
* @param {Phaser.GameObjects.IsoBox} src - The Game Object being rendered in this call.
|
||||
* @param {number} interpolationPercentage - Reserved for future use and custom pipelines.
|
||||
* @param {Phaser.Cameras.Scene2D.Camera} camera - The Camera that is rendering the Game Object.
|
||||
* @param {Phaser.GameObjects.Components.TransformMatrix} parentMatrix - This transform matrix is defined if the game object is nested
|
||||
*/
|
||||
var IsoBoxCanvasRenderer = function (renderer, src, interpolationPercentage, camera, parentMatrix)
|
||||
{
|
||||
};
|
||||
|
||||
module.exports = IsoBoxCanvasRenderer;
|
31
src/gameobjects/shape/isobox/IsoBoxFactory.js
Normal file
31
src/gameobjects/shape/isobox/IsoBoxFactory.js
Normal file
|
@ -0,0 +1,31 @@
|
|||
/**
|
||||
* @author Richard Davey <rich@photonstorm.com>
|
||||
* @copyright 2018 Photon Storm Ltd.
|
||||
* @license {@link https://github.com/photonstorm/phaser/blob/master/license.txt|MIT License}
|
||||
*/
|
||||
|
||||
var GameObjectFactory = require('../../GameObjectFactory');
|
||||
var IsoBox = require('./IsoBox');
|
||||
|
||||
/**
|
||||
* Creates a new IsoBox Shape Game Object and adds it to the Scene.
|
||||
*
|
||||
* Note: This method will only be available if the IsoBox Game Object has been built into Phaser.
|
||||
*
|
||||
* @method Phaser.GameObjects.GameObjectFactory#isobox
|
||||
* @since 3.13.0
|
||||
*
|
||||
* @param {number} [x=0] - The horizontal position of this Game Object in the world.
|
||||
* @param {number} [y=0] - The vertical position of this Game Object in the world.
|
||||
* @param {number} [size=48] - The width of the iso box in pixels. The left and right faces will be exactly half this value.
|
||||
* @param {number} [height=32] - The height of the iso box. The left and right faces will be this tall. The overall height of the isobox will be this value plus half the `size` value.
|
||||
* @param {number} [fillTop=0xeeeeee] - The fill color of the top face of the iso box.
|
||||
* @param {number} [fillLeft=0x999999] - The fill color of the left face of the iso box.
|
||||
* @param {number} [fillRight=0xcccccc] - The fill color of the right face of the iso box.
|
||||
*
|
||||
* @return {Phaser.GameObjects.IsoBox} The Game Object that was created.
|
||||
*/
|
||||
GameObjectFactory.register('isobox', function (x, y, size, height, fillTop, fillLeft, fillRight)
|
||||
{
|
||||
return this.displayList.add(new IsoBox(this.scene, x, y, size, height, fillTop, fillLeft, fillRight));
|
||||
});
|
25
src/gameobjects/shape/isobox/IsoBoxRender.js
Normal file
25
src/gameobjects/shape/isobox/IsoBoxRender.js
Normal file
|
@ -0,0 +1,25 @@
|
|||
/**
|
||||
* @author Richard Davey <rich@photonstorm.com>
|
||||
* @copyright 2018 Photon Storm Ltd.
|
||||
* @license {@link https://github.com/photonstorm/phaser/blob/master/license.txt|MIT License}
|
||||
*/
|
||||
|
||||
var renderWebGL = require('../../../utils/NOOP');
|
||||
var renderCanvas = require('../../../utils/NOOP');
|
||||
|
||||
if (typeof WEBGL_RENDERER)
|
||||
{
|
||||
renderWebGL = require('./IsoBoxWebGLRenderer');
|
||||
}
|
||||
|
||||
if (typeof CANVAS_RENDERER)
|
||||
{
|
||||
renderCanvas = require('./IsoBoxCanvasRenderer');
|
||||
}
|
||||
|
||||
module.exports = {
|
||||
|
||||
renderWebGL: renderWebGL,
|
||||
renderCanvas: renderCanvas
|
||||
|
||||
};
|
119
src/gameobjects/shape/isobox/IsoBoxWebGLRenderer.js
Normal file
119
src/gameobjects/shape/isobox/IsoBoxWebGLRenderer.js
Normal file
|
@ -0,0 +1,119 @@
|
|||
/**
|
||||
* @author Richard Davey <rich@photonstorm.com>
|
||||
* @copyright 2018 Photon Storm Ltd.
|
||||
* @license {@link https://github.com/photonstorm/phaser/blob/master/license.txt|MIT License}
|
||||
*/
|
||||
|
||||
var Utils = require('../../../renderer/webgl/Utils');
|
||||
|
||||
/**
|
||||
* Renders this Game Object with the WebGL Renderer to the given Camera.
|
||||
* The object will not render if any of its renderFlags are set or it is being actively filtered out by the Camera.
|
||||
* This method should not be called directly. It is a utility function of the Render module.
|
||||
*
|
||||
* @method Phaser.GameObjects.IsoBox#renderWebGL
|
||||
* @since 3.13.0
|
||||
* @private
|
||||
*
|
||||
* @param {Phaser.Renderer.WebGL.WebGLRenderer} renderer - A reference to the current active WebGL renderer.
|
||||
* @param {Phaser.GameObjects.IsoBox} src - The Game Object being rendered in this call.
|
||||
* @param {number} interpolationPercentage - Reserved for future use and custom pipelines.
|
||||
* @param {Phaser.Cameras.Scene2D.Camera} camera - The Camera that is rendering the Game Object.
|
||||
* @param {Phaser.GameObjects.Components.TransformMatrix} parentMatrix - This transform matrix is defined if the game object is nested
|
||||
*/
|
||||
var IsoBoxWebGLRenderer = function (renderer, src, interpolationPercentage, camera, parentMatrix)
|
||||
{
|
||||
var pipeline = this.pipeline;
|
||||
|
||||
var camMatrix = pipeline._tempMatrix1;
|
||||
var shapeMatrix = pipeline._tempMatrix2;
|
||||
var calcMatrix = pipeline._tempMatrix3;
|
||||
|
||||
renderer.setPipeline(pipeline);
|
||||
|
||||
shapeMatrix.applyITRS(src.x, src.y, src.rotation, src.scaleX, src.scaleY);
|
||||
|
||||
camMatrix.copyFrom(camera.matrix);
|
||||
|
||||
if (parentMatrix)
|
||||
{
|
||||
// Multiply the camera by the parent matrix
|
||||
camMatrix.multiplyWithOffset(parentMatrix, -camera.scrollX * src.scrollFactorX, -camera.scrollY * src.scrollFactorY);
|
||||
|
||||
// Undo the camera scroll
|
||||
shapeMatrix.e = src.x;
|
||||
shapeMatrix.f = src.y;
|
||||
}
|
||||
else
|
||||
{
|
||||
shapeMatrix.e -= camera.scrollX * src.scrollFactorX;
|
||||
shapeMatrix.f -= camera.scrollY * src.scrollFactorY;
|
||||
}
|
||||
|
||||
camMatrix.multiply(shapeMatrix, calcMatrix);
|
||||
|
||||
// var i;
|
||||
// var dx = src._displayOriginX;
|
||||
// var dy = src._displayOriginY;
|
||||
|
||||
var size = src.width;
|
||||
var height = src.height;
|
||||
|
||||
var alpha = camera.alpha * src.alpha;
|
||||
|
||||
// Top Face
|
||||
|
||||
var tint = Utils.getTintAppendFloatAlphaAndSwap(src.fillTop, alpha);
|
||||
|
||||
var x0 = calcMatrix.getX(-size / 2, -height);
|
||||
var y0 = calcMatrix.getY(-size / 2, -height);
|
||||
|
||||
var x1 = calcMatrix.getX(0, -size / 4 - height);
|
||||
var y1 = calcMatrix.getY(0, -size / 4 - height);
|
||||
|
||||
var x2 = calcMatrix.getX(size / 2, -height);
|
||||
var y2 = calcMatrix.getY(size / 2, -height);
|
||||
|
||||
var x3 = calcMatrix.getX(0, size / 4 - height);
|
||||
var y3 = calcMatrix.getY(0, size / 4 - height);
|
||||
|
||||
pipeline.batchQuad(x0, y0, x1, y1, x2, y2, x3, y3, 0, 0, 1, 1, tint, tint, tint, tint, 2);
|
||||
|
||||
// Left Face
|
||||
|
||||
tint = Utils.getTintAppendFloatAlphaAndSwap(src.fillLeft, alpha);
|
||||
|
||||
x0 = calcMatrix.getX(-size / 2, 0);
|
||||
y0 = calcMatrix.getY(-size / 2, 0);
|
||||
|
||||
x1 = calcMatrix.getX(0, size / 4);
|
||||
y1 = calcMatrix.getY(0, size / 4);
|
||||
|
||||
x2 = calcMatrix.getX(0, size / 4 - height);
|
||||
y2 = calcMatrix.getY(0, size / 4 - height);
|
||||
|
||||
x3 = calcMatrix.getX(-size / 2, -height);
|
||||
y3 = calcMatrix.getY(-size / 2, -height);
|
||||
|
||||
pipeline.batchQuad(x0, y0, x1, y1, x2, y2, x3, y3, 0, 0, 1, 1, tint, tint, tint, tint, 2);
|
||||
|
||||
// Right Face
|
||||
|
||||
tint = Utils.getTintAppendFloatAlphaAndSwap(src.fillRight, alpha);
|
||||
|
||||
x0 = calcMatrix.getX(size / 2, 0);
|
||||
y0 = calcMatrix.getY(size / 2, 0);
|
||||
|
||||
x1 = calcMatrix.getX(0, size / 4);
|
||||
y1 = calcMatrix.getY(0, size / 4);
|
||||
|
||||
x2 = calcMatrix.getX(0, size / 4 - height);
|
||||
y2 = calcMatrix.getY(0, size / 4 - height);
|
||||
|
||||
x3 = calcMatrix.getX(size / 2, -height);
|
||||
y3 = calcMatrix.getY(size / 2, -height);
|
||||
|
||||
pipeline.batchQuad(x0, y0, x1, y1, x2, y2, x3, y3, 0, 0, 1, 1, tint, tint, tint, tint, 2);
|
||||
};
|
||||
|
||||
module.exports = IsoBoxWebGLRenderer;
|
Loading…
Reference in a new issue