Skip to content

Commit 7cc5a61

Browse files
committed
Zone now uses x/y as center for drop zone shapes.
1 parent e20d4b1 commit 7cc5a61

2 files changed

Lines changed: 43 additions & 7 deletions

File tree

v3/src/checksum.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
var CHECKSUM = {
2-
build: '980f6760-7325-11e7-a031-bfdaa3af0a4c'
2+
build: 'fe5bfd50-7332-11e7-902d-a936c8f38615'
33
};
44
module.exports = CHECKSUM;

v3/src/gameobjects/zone/Zone.js

Lines changed: 42 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,19 @@
11

2+
var BlendModes = require('../../renderer/BlendModes');
3+
var Circle = require('../../geom/circle/Circle');
4+
var CircleContains = require('../../geom/circle/Contains');
25
var Class = require('../../utils/Class');
3-
var GameObject = require('../GameObject');
46
var Components = require('../components');
5-
var BlendModes = require('../../renderer/BlendModes');
7+
var GameObject = require('../GameObject');
8+
var Rectangle = require('../../geom/rectangle/Rectangle');
9+
var RectangleContains = require('../../geom/rectangle/Contains');
10+
11+
// A Zone is a non-rendering Game Object that has a position and size.
12+
// It has no texture and never renders, but does live on the display list and
13+
// can be moved, scaled and rotated like any other Game Object.
14+
// The default origin is 0.5, the center of the Zone, the same as with Game Objects.
15+
// It's useful for linking to drop zones and input hit areas and has a couple of helper methods specifically for this.
16+
// Also useful for object overlap checks, or as a base for your own non-displaying objects.
617

718
var Zone = new Class({
819

@@ -22,23 +33,48 @@ var Zone = new Class({
2233

2334
function Zone (scene, x, y, width, height)
2435
{
36+
if (width === undefined) { width = 1; }
37+
if (height === undefined) { height = width; }
38+
2539
GameObject.call(this, scene, 'Zone');
2640

2741
this.setPosition(x, y);
2842
this.setSize(width, height);
29-
this.setOrigin(0);
3043

3144
this.blendMode = BlendModes.NORMAL;
3245
},
3346

47+
// Centered on the Zones x/y
48+
setCircleDropZone: function (radius)
49+
{
50+
return this.setDropZone(new Circle(0, 0, radius), CircleContains);
51+
},
52+
53+
// Centered on the Zones x/y position
54+
setRectangleDropZone: function (width, height)
55+
{
56+
var x = -(width / 2);
57+
var y = -(height / 2);
58+
59+
return this.setDropZone(new Rectangle(x, y, width, height), RectangleContains);
60+
},
61+
62+
// Define your own shape as the drop zone
3463
setDropZone: function (shape, callback)
3564
{
36-
if (!this.input)
65+
if (shape === undefined)
3766
{
38-
this.setInteractive(shape, callback);
67+
this.setRectangleDropZone(this.width, this.height);
3968
}
69+
else
70+
{
71+
if (!this.input)
72+
{
73+
this.setInteractive(shape, callback);
74+
}
4075

41-
this.input.dropZone = true;
76+
this.input.dropZone = true;
77+
}
4278

4379
return this;
4480
},

0 commit comments

Comments
 (0)