From c30a95cb015b417c45b2a8b551c0e483c0beaf64 Mon Sep 17 00:00:00 2001 From: Felipe Alfonso Date: Tue, 28 Feb 2017 11:49:39 -0300 Subject: [PATCH] Graphics Game Object base --- v3/src/gameobjects/graphics/Graphics.js | 27 +++++++++++++++++++ .../graphics/GraphicsCanvasRenderer.js | 9 +++++++ .../gameobjects/graphics/GraphicsFactory.js | 22 +++++++++++++++ v3/src/gameobjects/graphics/GraphicsRender.js | 6 +++++ .../graphics/GraphicsWebGLRenderer.js | 9 +++++++ v3/src/gameobjects/index.js | 4 ++- v3/src/gameobjects/text/BitmapText.js | 4 +-- ...mapTextRenderer.js => BitmapTextRender.js} | 0 8 files changed, 78 insertions(+), 3 deletions(-) create mode 100644 v3/src/gameobjects/graphics/Graphics.js create mode 100644 v3/src/gameobjects/graphics/GraphicsCanvasRenderer.js create mode 100644 v3/src/gameobjects/graphics/GraphicsFactory.js create mode 100644 v3/src/gameobjects/graphics/GraphicsRender.js create mode 100644 v3/src/gameobjects/graphics/GraphicsWebGLRenderer.js rename v3/src/gameobjects/text/{BitmapTextRenderer.js => BitmapTextRender.js} (100%) diff --git a/v3/src/gameobjects/graphics/Graphics.js b/v3/src/gameobjects/graphics/Graphics.js new file mode 100644 index 000000000..852876ffa --- /dev/null +++ b/v3/src/gameobjects/graphics/Graphics.js @@ -0,0 +1,27 @@ +var Class = require('../../utils/Class'); +var GameObject = require('../GameObject'); +var Components = require('../../components'); +var Render = require('./GraphicsRender'); + +var Graphics = new Class({ + + Mixins: [ + Components.Alpha, + Components.BlendMode, + Components.Transform, + Components.Visible, + Render + ], + + initialize: + + function Graphics (state, x, y) + { + GameObject.call(this, state); + + this.setPosition(x, y); + } + +}); + +module.exports = Graphics; diff --git a/v3/src/gameobjects/graphics/GraphicsCanvasRenderer.js b/v3/src/gameobjects/graphics/GraphicsCanvasRenderer.js new file mode 100644 index 000000000..9c89e2b5a --- /dev/null +++ b/v3/src/gameobjects/graphics/GraphicsCanvasRenderer.js @@ -0,0 +1,9 @@ +var GraphicsCanvasRenderer = function (renderer, src, interpolationPercentage, camera) +{ + if (this.renderMask !== this.renderFlags) + { + return; + } +} + +module.exports = GraphicsCanvasRenderer; diff --git a/v3/src/gameobjects/graphics/GraphicsFactory.js b/v3/src/gameobjects/graphics/GraphicsFactory.js new file mode 100644 index 000000000..3ad482af6 --- /dev/null +++ b/v3/src/gameobjects/graphics/GraphicsFactory.js @@ -0,0 +1,22 @@ +var Graphics = require('./Graphics'); +var FactoryContainer = require('../../gameobjects/FactoryContainer'); + +var GraphicsFactory = { + + KEY: 'graphics', + + add: function (x, y, group) + { + if (group === undefined) { group = this.state; } + + return group.children.add(new Graphics(this.state, x, y)); + }, + + make: function (x, y) + { + return new Graphics(this.state, x, y); + } + +}; + +module.exports = FactoryContainer.register(GraphicsFactory); diff --git a/v3/src/gameobjects/graphics/GraphicsRender.js b/v3/src/gameobjects/graphics/GraphicsRender.js new file mode 100644 index 000000000..62c141748 --- /dev/null +++ b/v3/src/gameobjects/graphics/GraphicsRender.js @@ -0,0 +1,6 @@ +module.exports = { + + renderCanvas: require('./GraphicsCanvasRenderer'), + renderWebGL: require('./GraphicsWebGLRenderer') + +}; diff --git a/v3/src/gameobjects/graphics/GraphicsWebGLRenderer.js b/v3/src/gameobjects/graphics/GraphicsWebGLRenderer.js new file mode 100644 index 000000000..767d61cde --- /dev/null +++ b/v3/src/gameobjects/graphics/GraphicsWebGLRenderer.js @@ -0,0 +1,9 @@ +var GraphicsWebGLRenderer = function (renderer, src, interpolationPercentage, camera) +{ + if (this.renderMask !== this.renderFlags) + { + return; + } +} + +module.exports = GraphicsWebGLRenderer; diff --git a/v3/src/gameobjects/index.js b/v3/src/gameobjects/index.js index cd61717b5..2d1c99365 100644 --- a/v3/src/gameobjects/index.js +++ b/v3/src/gameobjects/index.js @@ -6,6 +6,7 @@ require('./container/ContainerFactory'); require('./image/ImageFactory'); require('./sprite/SpriteFactory'); require('./text/BitmapTextFactory'); +require('./graphics/GraphicsFactory'); // Phaser.GameObjects @@ -17,6 +18,7 @@ module.exports = { Blitter: require('./blitter/Blitter'), Container: require('./container/Container'), Image: require('./image/Image'), - Sprite: require('./sprite/Sprite') + Sprite: require('./sprite/Sprite'), + Graphics: require('./graphics/Graphics.js') }; diff --git a/v3/src/gameobjects/text/BitmapText.js b/v3/src/gameobjects/text/BitmapText.js index 8e8d093c9..5ba1fe431 100644 --- a/v3/src/gameobjects/text/BitmapText.js +++ b/v3/src/gameobjects/text/BitmapText.js @@ -1,7 +1,7 @@ var Class = require('../../utils/Class'); var GameObject = require('../GameObject'); var Components = require('../../components'); -var Renderer = require('./BitmapTextRenderer'); +var Render = require('./BitmapTextRender'); var ParseXMLBitmapFont = function (xml, xSpacing, ySpacing, frame) { @@ -58,7 +58,7 @@ var BitmapText = new Class({ Components.Alpha, Components.BlendMode, Components.Visible, - Renderer + Render ], initialize: diff --git a/v3/src/gameobjects/text/BitmapTextRenderer.js b/v3/src/gameobjects/text/BitmapTextRender.js similarity index 100% rename from v3/src/gameobjects/text/BitmapTextRenderer.js rename to v3/src/gameobjects/text/BitmapTextRender.js