2017-03-27 22:10:04 +00:00
|
|
|
|
2017-07-28 01:22:41 +00:00
|
|
|
var BlendModes = require('../../renderer/BlendModes');
|
|
|
|
var Circle = require('../../geom/circle/Circle');
|
|
|
|
var CircleContains = require('../../geom/circle/Contains');
|
2017-03-27 22:10:04 +00:00
|
|
|
var Class = require('../../utils/Class');
|
2017-07-04 00:59:31 +00:00
|
|
|
var Components = require('../components');
|
2017-07-28 01:22:41 +00:00
|
|
|
var GameObject = require('../GameObject');
|
|
|
|
var Rectangle = require('../../geom/rectangle/Rectangle');
|
|
|
|
var RectangleContains = require('../../geom/rectangle/Contains');
|
|
|
|
|
2018-01-04 22:02:29 +00:00
|
|
|
// A Zone is a non-rendering rectangular Game Object that has a position and size.
|
2017-07-28 01:22:41 +00:00
|
|
|
// It has no texture and never renders, but does live on the display list and
|
|
|
|
// can be moved, scaled and rotated like any other Game Object.
|
2018-01-04 22:02:29 +00:00
|
|
|
|
2017-07-28 01:22:41 +00:00
|
|
|
// The default origin is 0.5, the center of the Zone, the same as with Game Objects.
|
|
|
|
// It's useful for linking to drop zones and input hit areas and has a couple of helper methods specifically for this.
|
|
|
|
// Also useful for object overlap checks, or as a base for your own non-displaying objects.
|
2017-03-27 22:10:04 +00:00
|
|
|
|
|
|
|
var Zone = new Class({
|
|
|
|
|
2017-04-05 01:10:48 +00:00
|
|
|
Extends: GameObject,
|
|
|
|
|
2017-03-27 22:10:04 +00:00
|
|
|
Mixins: [
|
|
|
|
Components.GetBounds,
|
|
|
|
Components.Origin,
|
|
|
|
Components.ScaleMode,
|
|
|
|
Components.Transform,
|
2017-06-22 02:19:03 +00:00
|
|
|
Components.ScrollFactor,
|
2017-03-27 22:10:04 +00:00
|
|
|
Components.Visible
|
|
|
|
],
|
|
|
|
|
|
|
|
initialize:
|
|
|
|
|
2017-07-14 13:30:20 +00:00
|
|
|
function Zone (scene, x, y, width, height)
|
2017-03-27 22:10:04 +00:00
|
|
|
{
|
2017-07-28 01:22:41 +00:00
|
|
|
if (width === undefined) { width = 1; }
|
|
|
|
if (height === undefined) { height = width; }
|
|
|
|
|
2017-07-14 13:30:20 +00:00
|
|
|
GameObject.call(this, scene, 'Zone');
|
2017-03-27 22:10:04 +00:00
|
|
|
|
|
|
|
this.setPosition(x, y);
|
2018-01-04 22:02:29 +00:00
|
|
|
|
|
|
|
this.width = width;
|
|
|
|
this.height = height;
|
2017-07-27 16:40:15 +00:00
|
|
|
|
|
|
|
this.blendMode = BlendModes.NORMAL;
|
|
|
|
},
|
|
|
|
|
2018-01-04 22:02:29 +00:00
|
|
|
displayWidth: {
|
|
|
|
|
|
|
|
get: function ()
|
|
|
|
{
|
|
|
|
return this.scaleX * this.width;
|
|
|
|
},
|
|
|
|
|
|
|
|
set: function (value)
|
|
|
|
{
|
|
|
|
this.scaleX = value / this.width;
|
|
|
|
}
|
|
|
|
|
|
|
|
},
|
|
|
|
|
|
|
|
displayHeight: {
|
|
|
|
|
|
|
|
get: function ()
|
|
|
|
{
|
|
|
|
return this.scaleY * this.height;
|
|
|
|
},
|
|
|
|
|
|
|
|
set: function (value)
|
|
|
|
{
|
|
|
|
this.scaleY = value / this.height;
|
|
|
|
}
|
|
|
|
|
|
|
|
},
|
|
|
|
|
|
|
|
setSize: function (width, height)
|
|
|
|
{
|
|
|
|
this.width = width;
|
|
|
|
this.height = height;
|
|
|
|
|
|
|
|
return this;
|
|
|
|
},
|
|
|
|
|
|
|
|
setDisplaySize: function (width, height)
|
|
|
|
{
|
|
|
|
this.displayWidth = width;
|
|
|
|
this.displayHeight = height;
|
|
|
|
|
|
|
|
return this;
|
|
|
|
},
|
|
|
|
|
2017-07-28 01:22:41 +00:00
|
|
|
// Centered on the Zones x/y
|
|
|
|
setCircleDropZone: function (radius)
|
|
|
|
{
|
|
|
|
return this.setDropZone(new Circle(0, 0, radius), CircleContains);
|
|
|
|
},
|
|
|
|
|
|
|
|
// Centered on the Zones x/y position
|
|
|
|
setRectangleDropZone: function (width, height)
|
|
|
|
{
|
|
|
|
var x = -(width / 2);
|
|
|
|
var y = -(height / 2);
|
|
|
|
|
|
|
|
return this.setDropZone(new Rectangle(x, y, width, height), RectangleContains);
|
|
|
|
},
|
|
|
|
|
|
|
|
// Define your own shape as the drop zone
|
2017-07-27 16:40:15 +00:00
|
|
|
setDropZone: function (shape, callback)
|
|
|
|
{
|
2017-07-28 01:22:41 +00:00
|
|
|
if (shape === undefined)
|
2017-07-27 16:40:15 +00:00
|
|
|
{
|
2017-07-28 01:22:41 +00:00
|
|
|
this.setRectangleDropZone(this.width, this.height);
|
2017-07-27 16:40:15 +00:00
|
|
|
}
|
2017-07-28 01:22:41 +00:00
|
|
|
else
|
|
|
|
{
|
|
|
|
if (!this.input)
|
|
|
|
{
|
|
|
|
this.setInteractive(shape, callback);
|
|
|
|
}
|
2017-07-27 16:40:15 +00:00
|
|
|
|
2017-07-28 01:22:41 +00:00
|
|
|
this.input.dropZone = true;
|
|
|
|
}
|
2017-07-27 16:40:15 +00:00
|
|
|
|
|
|
|
return this;
|
|
|
|
},
|
|
|
|
|
|
|
|
renderCanvas: function ()
|
|
|
|
{
|
|
|
|
return;
|
|
|
|
},
|
|
|
|
|
|
|
|
renderWebGL: function ()
|
|
|
|
{
|
|
|
|
return;
|
2017-03-27 22:10:04 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
module.exports = Zone;
|