Skip to content

Commit 410bc38

Browse files
committed
Tidying up ready to move the plugins to their own repo.
1 parent f0a6a7f commit 410bc38

4 files changed

Lines changed: 109 additions & 107 deletions

File tree

README.md

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ Version 2.0.5 - "Tanchico" - in development
5959

6060
### Updates
6161

62-
* TypeScript definitions fixes and updates (thanks @luispedrofonseca @clark-stevenson)
62+
* TypeScript definitions fixes and updates (thanks @luispedrofonseca @clark-stevenson @Anahkiasen @adamholdenyall)
6363
* Input.getPointerFromIdentifier docs update to reflect where the identifier comes from. Pointer properties now set to give it fixed defaults (thanks @JirkaDellOro, #793)
6464
* Pointer.pointerId added which is set by the DOM event (if present in the browser). Note that browsers can and do recycle pointer IDs.
6565
* Pointer.type and Pointer.exists properties added.
@@ -77,6 +77,8 @@ Version 2.0.5 - "Tanchico" - in development
7777
* ArcadePhysics.getObjectsUnderPointer will return all children from a Group that overlap with the given Pointer.
7878
* InputManager.minPriorityID lets you set the minimum priority level an object needs to be to be checked by a Pointer. Useful for UI layer stacking.
7979
* New consts: Phaser.Tilemap.NORTH, SOUTH, EAST and WEST to use with the TileMapWalker Plugin.
80+
* BitmapData.processPixelRGB added undefined check (thanks @muclemente, fix #808)
81+
8082

8183
### New Plugins
8284

plugins/TilemapWalker.js

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -21,17 +21,17 @@ Phaser.Plugin.TilemapWalker = function (game, map, layer, x, y) {
2121
/**
2222
* @property {Phaser.Game} game - A reference to the currently running Game.
2323
*/
24-
this.game = game;
24+
this.game = game;
2525

2626
/**
2727
* @property {Phaser.Tilemap} map - A reference to the Tilemap this TilemapWalker belongs to.
2828
*/
29-
this.map = map;
29+
this.map = map;
3030

3131
/**
3232
* @property {number} locationLayer - The current layer of the location marker.
3333
*/
34-
this.locationLayer = map.getLayer(layer);
34+
this.locationLayer = map.getLayer(layer);
3535

3636
/**
3737
* @property {Phaser.Point} location - The current marker location. You can move the marker with the movement methods.
@@ -55,7 +55,7 @@ Phaser.Plugin.TilemapWalker = function (game, map, layer, x, y) {
5555
*/
5656
this.history = [];
5757

58-
// TODO: History limit, History scan, record how many times walker has been on a tile before
58+
// TODO: History limit, History scan, record how many times walker has been on a tile before
5959

6060
if (typeof x !== 'undefined' && typeof y !== 'undefined')
6161
{
@@ -104,17 +104,17 @@ Phaser.Plugin.TilemapWalker.prototype = {
104104

105105
if (this.map.hasTile(x, y, this.locationLayer))
106106
{
107-
if (this.collides)
108-
{
109-
var tile = this.map.getTile(x, y, this.locationLayer);
107+
if (this.collides)
108+
{
109+
var tile = this.map.getTile(x, y, this.locationLayer);
110110

111-
if (tile && tile.collides)
112-
{
113-
return false;
114-
}
115-
}
111+
if (tile && tile.collides)
112+
{
113+
return false;
114+
}
115+
}
116116

117-
return true;
117+
return true;
118118
}
119119

120120
return false;
@@ -255,7 +255,7 @@ Phaser.Plugin.TilemapWalker.prototype = {
255255

256256
getTile: function () {
257257

258-
return this.map.getTile(this.location.x, this.location.y, this.locationLayer, true);
258+
return this.map.getTile(this.location.x, this.location.y, this.locationLayer, true);
259259

260260
},
261261

@@ -547,7 +547,7 @@ Phaser.Plugin.TilemapWalker.prototype = {
547547
return this.getTileFromLocation(0, -distance);
548548
}
549549

550-
},
550+
}
551551

552552
};
553553

plugins/VirtualJoystick.js

Lines changed: 89 additions & 90 deletions
Original file line numberDiff line numberDiff line change
@@ -3,136 +3,135 @@
33
*/
44
Phaser.Plugin.VirtualJoystick = function (game, parent) {
55

6-
Phaser.Plugin.call(this, game, parent);
6+
Phaser.Plugin.call(this, game, parent);
77

8-
this.x = 0;
9-
this.y = 0;
10-
this.limit = 10;
8+
this.x = 0;
9+
this.y = 0;
10+
this.limit = 10;
1111

12-
this.baseCircle;
12+
this.baseCircle;
1313

14-
this.baseBMD;
15-
this.nubBMD;
14+
this.baseBMD;
15+
this.nubBMD;
1616

17-
this.base;
18-
this.nub;
17+
this.base;
18+
this.nub;
1919

20-
this.baseCenter;
21-
this.nubCenter;
20+
this.baseCenter;
21+
this.nubCenter;
2222

23-
this.isDragging = false;
23+
this.isDragging = false;
2424

25-
this.angle = 0;
26-
this.distance = 0;
27-
this.force = 0;
28-
this.deltaX = 0;
29-
this.deltaY = 0;
30-
this.speed = 0;
31-
25+
this.angle = 0;
26+
this.distance = 0;
27+
this.force = 0;
28+
this.deltaX = 0;
29+
this.deltaY = 0;
30+
this.speed = 0;
31+
3232
};
3333

34-
// Extends the Phaser.Plugin template, setting up values we need
3534
Phaser.Plugin.VirtualJoystick.prototype = Object.create(Phaser.Plugin.prototype);
3635
Phaser.Plugin.VirtualJoystick.prototype.constructor = Phaser.Plugin.VirtualJoystick;
3736

3837
Phaser.Plugin.VirtualJoystick.prototype.init = function (x, y, diameter, limit) {
3938

40-
if (typeof diameter === 'undefined') { diameter = 80; }
41-
if (typeof limit === 'undefined') { limit = Math.floor(diameter / 2); }
39+
if (typeof diameter === 'undefined') { diameter = 80; }
40+
if (typeof limit === 'undefined') { limit = Math.floor(diameter / 2); }
4241

43-
this.x = x;
44-
this.y = y;
42+
this.x = x;
43+
this.y = y;
4544

46-
var radius = Math.floor(diameter / 2);
47-
var nr = radius - 4;
45+
var radius = Math.floor(diameter / 2);
46+
var nr = radius - 4;
4847

49-
this.baseCircle = new Phaser.Circle(x, y, diameter);
48+
this.baseCircle = new Phaser.Circle(x, y, diameter);
5049

51-
this.baseBMD = this.game.make.bitmapData(diameter, diameter);
52-
this.nubBMD = this.game.make.bitmapData(nr * 2, nr * 2);
50+
this.baseBMD = this.game.make.bitmapData(diameter, diameter);
51+
this.nubBMD = this.game.make.bitmapData(nr * 2, nr * 2);
5352

54-
this.baseBMD.circle(radius, radius, radius, 'rgb(255, 0, 0)');
55-
this.nubBMD.circle(nr, nr, nr, 'rgb(0, 255, 0)');
53+
this.baseBMD.circle(radius, radius, radius, 'rgb(255, 0, 0)');
54+
this.nubBMD.circle(nr, nr, nr, 'rgb(0, 255, 0)');
5655

57-
// Base
58-
this.base = this.game.add.sprite(x, y, this.baseBMD);
59-
this.base.anchor.set(0.5);
56+
// Base
57+
this.base = this.game.add.sprite(x, y, this.baseBMD);
58+
this.base.anchor.set(0.5);
6059

61-
// Nub
62-
this.nub = this.game.add.sprite(x, y, this.nubBMD);
63-
this.nub.anchor.set(0.5);
60+
// Nub
61+
this.nub = this.game.add.sprite(x, y, this.nubBMD);
62+
this.nub.anchor.set(0.5);
6463

65-
this.nub.inputEnabled = true;
64+
this.nub.inputEnabled = true;
6665

67-
this.nub.events.onInputDown.add(this.startDrag, this);
68-
this.nub.events.onInputUp.add(this.stopDrag, this);
66+
this.nub.events.onInputDown.add(this.startDrag, this);
67+
this.nub.events.onInputUp.add(this.stopDrag, this);
6968

70-
// Need to find a way to not hog this callback
71-
this.game.input.setMoveCallback(this.move, this);
69+
// Need to find a way to not hog this callback
70+
this.game.input.setMoveCallback(this.move, this);
7271

73-
this.isDragging = false;
72+
this.isDragging = false;
7473

75-
this.distance = 0;
76-
this.speed = 0;
77-
this.force = 0;
78-
this.limit = limit;
79-
this.limitPoint = new Phaser.Point();
74+
this.distance = 0;
75+
this.speed = 0;
76+
this.force = 0;
77+
this.limit = limit;
78+
this.limitPoint = new Phaser.Point();
8079

81-
this.location = new Phaser.Point();
80+
this.location = new Phaser.Point();
8281

8382
}
8483

8584
Phaser.Plugin.VirtualJoystick.prototype.startDrag = function (nub, pointer) {
8685

87-
this.isDragging = true;
86+
this.isDragging = true;
8887

89-
this.location.set(pointer.x, pointer.y);
90-
this.distance = Phaser.Point.distance(this.base, this.location, true);
91-
this.angle = this.game.math.wrapAngle(this.location.angle(this.base, true) + 180);
92-
this.force = this.game.math.percent(this.distance, this.limit);
88+
this.location.set(pointer.x, pointer.y);
89+
this.distance = Phaser.Point.distance(this.base, this.location, true);
90+
this.angle = this.game.math.wrapAngle(this.location.angle(this.base, true) + 180);
91+
this.force = this.game.math.percent(this.distance, this.limit);
9392

9493
};
9594

9695
Phaser.Plugin.VirtualJoystick.prototype.stopDrag = function (nub, pointer) {
9796

98-
this.isDragging = false;
97+
this.isDragging = false;
9998

100-
this.distance = 0;
101-
this.angle = 0;
102-
this.force = 0;
99+
this.distance = 0;
100+
this.angle = 0;
101+
this.force = 0;
103102

104-
this.nub.x = this.base.x;
105-
this.nub.y = this.base.y;
106-
107-
this.limitPoint.set(this.base.x, this.base.y);
103+
this.nub.x = this.base.x;
104+
this.nub.y = this.base.y;
105+
106+
this.limitPoint.set(this.base.x, this.base.y);
108107

109108
};
110109

111110
Phaser.Plugin.VirtualJoystick.prototype.move = function (pointer, x, y) {
112111

113-
if (!this.isDragging)
114-
{
115-
return;
116-
}
112+
if (!this.isDragging)
113+
{
114+
return;
115+
}
117116

118-
this.location.set(x, y);
117+
this.location.set(x, y);
119118

120-
this.distance = Phaser.Point.distance(this.base, this.location, true);
119+
this.distance = Phaser.Point.distance(this.base, this.location, true);
121120

122-
this.angle = this.game.math.wrapAngle(this.location.angle(this.base, true) + 180);
121+
this.angle = this.game.math.wrapAngle(this.location.angle(this.base, true) + 180);
123122

124-
this.force = this.game.math.percent(this.distance, this.limit);
123+
this.force = this.game.math.percent(this.distance, this.limit);
125124

126-
if (this.distance < this.limit)
127-
{
128-
this.limitPoint.copyFrom(this.location);
129-
}
130-
else
131-
{
132-
this.baseCircle.circumferencePoint(this.angle, true, this.limitPoint);
133-
}
125+
if (this.distance < this.limit)
126+
{
127+
this.limitPoint.copyFrom(this.location);
128+
}
129+
else
130+
{
131+
this.baseCircle.circumferencePoint(this.angle, true, this.limitPoint);
132+
}
134133

135-
this.nub.position.set(this.limitPoint.x, this.limitPoint.y);
134+
this.nub.position.set(this.limitPoint.x, this.limitPoint.y);
136135

137136
};
138137

@@ -153,13 +152,13 @@ Phaser.Plugin.VirtualJoystick.prototype.setVelocity = function (sprite, minSpeed
153152

154153
if (this.force === 0 && minSpeed === 0)
155154
{
156-
sprite.body.velocity.set(0, 0);
155+
sprite.body.velocity.set(0, 0);
157156
}
158157
else
159158
{
160-
var speed = (maxSpeed - minSpeed) * this.force;
159+
var speed = (maxSpeed - minSpeed) * this.force;
161160

162-
sprite.body.velocity.set((Math.cos(this.game.math.degToRad(this.angle)) * speed), (Math.sin(this.game.math.degToRad(this.angle)) * speed));
161+
sprite.body.velocity.set((Math.cos(this.game.math.degToRad(this.angle)) * speed), (Math.sin(this.game.math.degToRad(this.angle)) * speed));
163162
}
164163

165164
return sprite;
@@ -172,15 +171,15 @@ Phaser.Plugin.VirtualJoystick.prototype.update = function () {
172171

173172
Phaser.Plugin.VirtualJoystick.prototype.render = function () {
174173

175-
this.game.debug.text('force: ' + this.force, 32, 32);
176-
// this.game.debug.text(this.distance, 32, 32);
177-
// this.game.debug.text(this.angle, 132, 32);
174+
this.game.debug.text('force: ' + this.force, 32, 32);
175+
// this.game.debug.text(this.distance, 32, 32);
176+
// this.game.debug.text(this.angle, 132, 32);
178177

179-
// this.game.debug.text('x: ' + this.location.x + ' y: ' + this.location.y, 32, 64);
180-
// this.game.debug.text('x: ' + this.limitPoint.x + ' y: ' + this.limitPoint.y, 32, 64);
181-
// this.game.debug.text('x: ' + this.prev.x + ' y: ' + this.prev.y, 32, 64);
182-
// this.game.debug.text(Phaser.Point.distance(this.base, this.prev, true), 32, 96);
178+
// this.game.debug.text('x: ' + this.location.x + ' y: ' + this.location.y, 32, 64);
179+
// this.game.debug.text('x: ' + this.limitPoint.x + ' y: ' + this.limitPoint.y, 32, 64);
180+
// this.game.debug.text('x: ' + this.prev.x + ' y: ' + this.prev.y, 32, 64);
181+
// this.game.debug.text(Phaser.Point.distance(this.base, this.prev, true), 32, 96);
183182

184-
this.game.debug.geom(this.limitPoint, 'rgb(255,255,0)');
183+
this.game.debug.geom(this.limitPoint, 'rgb(255,255,0)');
185184

186185
};

src/loader/Loader.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -193,7 +193,8 @@ Phaser.Loader.prototype = {
193193

194194
/**
195195
* Check whether asset exists with a specific key.
196-
*
196+
* Use Phaser.Cache to access loaded assets, e.g. Phaser.Cache#checkImageKey
197+
*
197198
* @method Phaser.Loader#checkKeyExists
198199
* @param {string} type - The type asset you want to check.
199200
* @param {string} key - Key of the asset you want to check.

0 commit comments

Comments
 (0)