phaser/v3/src/gameobjects/graphics/Graphics.js

135 lines
2.6 KiB
JavaScript
Raw Normal View History

2017-02-28 14:49:39 +00:00
var Class = require('../../utils/Class');
var GameObject = require('../GameObject');
var Components = require('../../components');
var Render = require('./GraphicsRender');
2017-02-28 21:12:14 +00:00
var Commands = require('./Commands');
var PI2 = 2 * Math.PI;
2017-02-28 14:49:39 +00:00
var Graphics = new Class({
Mixins: [
Components.Alpha,
Components.BlendMode,
Components.Transform,
Components.Visible,
Render
],
initialize:
function Graphics (state, x, y)
{
GameObject.call(this, state);
2017-02-28 21:12:14 +00:00
this.commandBuffer = [];
2017-02-28 14:49:39 +00:00
this.setPosition(x, y);
2017-02-28 16:52:09 +00:00
},
2017-02-28 21:12:14 +00:00
arc: function (x, y, radius, startAngle, endAngle, anticlockwise)
{
this.commandBuffer.push(
Commands.ARC,
x, y, radius, startAngle, endAngle, anticlockwise
);
2017-02-28 16:52:09 +00:00
},
lineStyle: function (lineWidth, color, alpha)
2017-02-28 21:12:14 +00:00
{
this.commandBuffer.push(
Commands.LINE_STYLE,
lineWidth, color, alpha
2017-02-28 21:12:14 +00:00
);
2017-02-28 16:52:09 +00:00
},
fillStyle: function (color, alpha)
2017-02-28 21:12:14 +00:00
{
alpha = (alpha !== undefined ? alpha : 1);
2017-02-28 21:12:14 +00:00
this.commandBuffer.push(
Commands.FILL_STYLE,
color, alpha
2017-02-28 21:12:14 +00:00
);
2017-02-28 16:52:09 +00:00
},
beginPath: function ()
{
this.commandBuffer.push(
Commands.BEGIN_PATH
);
},
closePath: function ()
{
this.commandBuffer.push(
Commands.CLOSE_PATH
);
},
fillPath: function ()
{
this.commandBuffer.push(
Commands.FILL_PATH
);
},
strokePath: function ()
{
this.commandBuffer.push(
Commands.STROKE_PATH
);
},
fillCircle: function (x, y, radius)
{
this.beginPath();
this.arc(x, y, radius, 0, PI2);
this.fillPath();
this.closePath();
},
fillRect: function (x, y, width, height)
{
this.commandBuffer.push(
Commands.FILL_RECT,
x, y, width, height
);
},
strokeCircle: function (x, y, radius)
2017-02-28 21:12:14 +00:00
{
this.beginPath();
this.arc(x, y, radius, 0, PI2);
this.strokePath();
this.closePath();
2017-02-28 16:52:09 +00:00
},
2017-02-28 14:49:39 +00:00
strokeRect: function (x, y, width, height)
2017-02-28 21:12:14 +00:00
{
this.commandBuffer.push(
Commands.STROKE_RECT,
2017-02-28 21:12:14 +00:00
x, y, width, height
);
},
2017-02-28 16:52:09 +00:00
2017-02-28 21:12:14 +00:00
lineTo: function (x, y)
{
this.commandBuffer.push(
Commands.LINE_TO,
x, y
);
},
2017-02-28 16:52:09 +00:00
2017-02-28 21:12:14 +00:00
moveTo: function (x, y)
{
this.commandBuffer.push(
Commands.MOVE_TO,
x, y
);
2017-02-28 16:52:09 +00:00
},
2017-02-28 21:12:14 +00:00
clear: function ()
{
commandBuffer.length = 0;
2017-02-28 16:52:09 +00:00
}
2017-02-28 14:49:39 +00:00
});
module.exports = Graphics;