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

88 lines
1.7 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');
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
},
2017-02-28 21:12:14 +00:00
beginFill: function (color)
{
this.commandBuffer.push(
Commands.BEGIN_FILL,
color
);
2017-02-28 16:52:09 +00:00
},
2017-02-28 21:12:14 +00:00
endFill: function ()
{
this.commandBuffer.push(
Commands.END_FILL
);
2017-02-28 16:52:09 +00:00
},
2017-02-28 21:12:14 +00:00
drawCircle: function (x, y, radius)
{
this.commandBuffer.push(
Commands.DRAW_CIRCLE,
x, y, radius
);
2017-02-28 16:52:09 +00:00
},
2017-02-28 14:49:39 +00:00
2017-02-28 21:12:14 +00:00
drawRect: function (x, y, width, height)
{
this.commandBuffer.push(
Commands.DRAW_RECT,
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;