Skip to content

Commit 1469663

Browse files
committed
Button fixes and Input coordinate fixes.
1 parent 1f28d32 commit 1469663

4 files changed

Lines changed: 43 additions & 70 deletions

File tree

examples/buttons/button scale.js

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -57,13 +57,17 @@ function create() {
5757
// Scaled and Rotated button
5858
button6 = game.add.button(600, 200, 'button', changeSky, this, 2, 1, 0);
5959
button6.name = 'sky6';
60-
button6.angle = 24;
61-
button6.scale.setTo(0.5, 2);
62-
// button6.anchor.setTo(0.5, 0.5);
60+
button6.angle = 32;
61+
button6.scale.setTo(2, 2);
62+
button6.anchor.setTo(0.5, 0.5);
63+
// scale + anchor works fine
64+
// angle + anchor works fine
65+
// scale + angle + anchor falls over
66+
6367

6468
// game.world.setBounds(0, 0, 2000, 2000);
6569
// works regardless of world angle, parent angle or camera position
66-
// game.world.angle = 5;
70+
// game.world.angle = 10;
6771
// game.camera.x = 300;
6872

6973
}

src/gameobjects/Sprite.js

Lines changed: 23 additions & 52 deletions
Original file line numberDiff line numberDiff line change
@@ -213,7 +213,8 @@ Phaser.Sprite = function (game, x, y, key, frame) {
213213
calcWidth: -1, calcHeight: -1,
214214

215215
// The current frame details
216-
frameID: this.currentFrame.uuid, frameWidth: this.currentFrame.width, frameHeight: this.currentFrame.height,
216+
// frameID: this.currentFrame.uuid, frameWidth: this.currentFrame.width, frameHeight: this.currentFrame.height,
217+
frameID: -1, frameWidth: this.currentFrame.width, frameHeight: this.currentFrame.height,
217218

218219
boundsX: 0, boundsY: 0,
219220

@@ -389,44 +390,6 @@ Phaser.Sprite.prototype.updateCache = function() {
389390
// |b d ty|
390391
// |0 0 1|
391392

392-
393-
// this._cache.width = Math.floor(this.currentFrame.sourceSizeW);
394-
// this._cache.height = Math.floor(this.currentFrame.sourceSizeH);
395-
// this._cache.halfWidth = Math.floor(this._cache.width / 2);
396-
// this._cache.halfHeight = Math.floor(this._cache.height / 2);
397-
398-
399-
// this._cache.scaleX = this.scale.x;
400-
// this._cache.scaleY = this.scale.y;
401-
402-
/*
403-
if (this.scale.x !== this._cache.realScaleX || this.scale.y !== this._cache.realScaleY)
404-
{
405-
console.log('rescale', this.name);
406-
this._cache.width = this.width;
407-
this._cache.height = this.height;
408-
this._cache.halfWidth = Math.floor(this._cache.width / 2);
409-
this._cache.halfHeight = Math.floor(this._cache.height / 2);
410-
this._cache.realScaleX = this.scale.x;
411-
this._cache.realScaleY = this.scale.y;
412-
this.updateFrame = true;
413-
this._cache.dirty = true;
414-
}
415-
*/
416-
417-
if (this._cache.calcWidth !== this.width || this._cache.calcHeight !== this.height)
418-
{
419-
console.log('calc', this.name);
420-
this._cache.width = Math.floor(this.currentFrame.sourceSizeW);
421-
this._cache.height = Math.floor(this.currentFrame.sourceSizeH);
422-
this._cache.halfWidth = Math.floor(this._cache.width / 2);
423-
this._cache.halfHeight = Math.floor(this._cache.height / 2);
424-
this._cache.frameWidth = this.texture.frame.width;
425-
this._cache.frameHeight = this.texture.frame.height;
426-
this._cache.frameID = this.currentFrame.uuid;
427-
this._cache.dirty = true;
428-
}
429-
430393
if (this.worldTransform[1] != this._cache.i01 || this.worldTransform[3] != this._cache.i10)
431394
{
432395
this._cache.a00 = this.worldTransform[0]; // scaleX a
@@ -459,10 +422,10 @@ Phaser.Sprite.prototype.updateAnimation = function() {
459422

460423
if (this.currentFrame && this.currentFrame.uuid != this._cache.frameID)
461424
{
462-
// console.log('ua frame 1 change', this.name);
463-
// this._cache.frameWidth = this.texture.frame.width;
464-
// this._cache.frameHeight = this.texture.frame.height;
465-
// this._cache.frameID = this.currentFrame.uuid;
425+
console.log('ua frame 1 change', this.name);
426+
this._cache.frameWidth = this.texture.frame.width;
427+
this._cache.frameHeight = this.texture.frame.height;
428+
this._cache.frameID = this.currentFrame.uuid;
466429
this._cache.dirty = true;
467430
}
468431

@@ -471,12 +434,12 @@ Phaser.Sprite.prototype.updateAnimation = function() {
471434
console.log('ua frame 2 change', this.name);
472435
// this._cache.width = Math.floor(this.currentFrame.sourceSizeW * this._cache.scaleX);
473436
// this._cache.height = Math.floor(this.currentFrame.sourceSizeH * this._cache.scaleY);
474-
// this._cache.width = this.currentFrame.width;
475-
// // this._cache.height = this.currentFrame.height;
437+
this._cache.width = this.currentFrame.width;
438+
this._cache.height = this.currentFrame.height;
476439
// this._cache.width = Math.floor(this.currentFrame.sourceSizeW);
477440
// this._cache.height = Math.floor(this.currentFrame.sourceSizeH);
478-
// this._cache.halfWidth = Math.floor(this._cache.width / 2);
479-
// this._cache.halfHeight = Math.floor(this._cache.height / 2);
441+
this._cache.halfWidth = Math.floor(this._cache.width / 2);
442+
this._cache.halfHeight = Math.floor(this._cache.height / 2);
480443

481444
this._cache.id = 1 / (this._cache.a00 * this._cache.a11 + this._cache.a01 * -this._cache.a10);
482445
this._cache.idi = 1 / (this._cache.a00 * this._cache.a11 + this._cache.i01 * -this._cache.i10);
@@ -492,10 +455,16 @@ Phaser.Sprite.prototype.updateAnimation = function() {
492455
Phaser.Sprite.prototype.updateBounds = function() {
493456

494457
// Update the edge points
495-
console.log('updateBounds', this.name);
496458

497459
this.offset.setTo(this._cache.a02 - (this.anchor.x * this._cache.width), this._cache.a12 - (this.anchor.y * this._cache.height));
498460

461+
// this.offset.setTo(this._cache.a02 - (this.anchor.x * this.currentFrame.width), this._cache.a12 - (this.anchor.y * this.currentFrame.height));
462+
// this.offset.setTo(this._cache.a02 - (this.anchor.x * this.width), this._cache.a12 - (this.anchor.y * this.height));
463+
464+
// this.offset.setTo(this._cache.a02 - (this.anchor.x * this._cache.width), this._cache.a12 - (this.anchor.y * this._cache.height));
465+
466+
console.log('updateBounds', this.name, this.offset.x, this.offset.y);
467+
499468
this.getLocalPosition(this.center, this.offset.x + this._cache.halfWidth, this.offset.y + this._cache.halfHeight);
500469
this.getLocalPosition(this.topLeft, this.offset.x, this.offset.y);
501470
this.getLocalPosition(this.topRight, this.offset.x + this._cache.width, this.offset.y);
@@ -513,8 +482,8 @@ Phaser.Sprite.prototype.updateBounds = function() {
513482
this._cache.boundsX = this._cache.x;
514483
this._cache.boundsY = this._cache.y;
515484

516-
this._cache.calcWidth = this.width;
517-
this._cache.calcHeight = this.height;
485+
// this._cache.calcWidth = this.width;
486+
// this._cache.calcHeight = this.height;
518487

519488
this.updateFrame = true;
520489

@@ -872,9 +841,10 @@ Phaser.Sprite.prototype.reset = function(x, y, health) {
872841
*/
873842
Phaser.Sprite.prototype.getLocalPosition = function(p, x, y) {
874843

875-
// p.x = ((this._cache.a11 * this._cache.id * x + -this._cache.a01 * this._cache.id * y + (this._cache.a12 * this._cache.a01 - this._cache.a02 * this._cache.a11) * this._cache.id) * this.scale.x) + this._cache.a02;
876-
// p.y = ((this._cache.a00 * this._cache.id * y + -this._cache.a10 * this._cache.id * x + (-this._cache.a12 * this._cache.a00 + this._cache.a02 * this._cache.a10) * this._cache.id) * this.scale.y) + this._cache.a12;
844+
p.x = ((this._cache.a11 * this._cache.id * x + -this._cache.a01 * this._cache.id * y + (this._cache.a12 * this._cache.a01 - this._cache.a02 * this._cache.a11) * this._cache.id) * this.scale.x) + this._cache.a02;
845+
p.y = ((this._cache.a00 * this._cache.id * y + -this._cache.a10 * this._cache.id * x + (-this._cache.a12 * this._cache.a00 + this._cache.a02 * this._cache.a10) * this._cache.id) * this.scale.y) + this._cache.a12;
877846

847+
/*
878848
if (this.worldTransform[0] == 1)
879849
{
880850
p.x = ((this._cache.a11 * this._cache.id * x + -this._cache.a01 * this._cache.id * y + (this._cache.a12 * this._cache.a01 - this._cache.a02 * this._cache.a11) * this._cache.id) * 1) + this._cache.a02;
@@ -892,6 +862,7 @@ Phaser.Sprite.prototype.getLocalPosition = function(p, x, y) {
892862
{
893863
p.y = ((this._cache.a00 * this._cache.id * y + -this._cache.a10 * this._cache.id * x + (-this._cache.a12 * this._cache.a00 + this._cache.a02 * this._cache.a10) * this._cache.id) * this.scale.y) + this._cache.a12;
894864
}
865+
*/
895866

896867
return p;
897868

src/input/InputHandler.js

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -495,19 +495,17 @@ Phaser.InputHandler.prototype = {
495495
if (this.sprite.worldTransform[3] == 0 && this.sprite.worldTransform[1] == 0)
496496
{
497497
// Un-rotated (but potentially scaled)
498-
// if (this._tempPoint.x >= 0 && this._tempPoint.x <= this.sprite.width && this._tempPoint.y >= 0 && this._tempPoint.y <= this.sprite.height)
499498
if (this._tempPoint.x >= x && this._tempPoint.x <= this.sprite.width && this._tempPoint.y >= y && this._tempPoint.y <= this.sprite.height)
500499
{
501-
return true;
500+
return true;
502501
}
503502
}
504503
else
505504
{
506505
// Rotated (and could be scaled too)
507-
// if (this._tempPoint.x >= 0 && this._tempPoint.x <= this.sprite.currentFrame.width && this._tempPoint.y >= 0 && this._tempPoint.y <= this.sprite.currentFrame.height)
508506
if (this._tempPoint.x >= x && this._tempPoint.x <= this.sprite.currentFrame.width && this._tempPoint.y >= y && this._tempPoint.y <= this.sprite.currentFrame.height)
509507
{
510-
return true;
508+
return true;
511509
}
512510
}
513511
}

src/utils/Debug.js

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -200,25 +200,25 @@ Phaser.Utils.Debug.prototype = {
200200

201201
showText = showText || false;
202202
showBounds = showBounds || false;
203-
color = color || 'rgb(255,0,255)';
203+
color = color || 'rgb(255,255,255)';
204204

205205
this.start(0, 0, color);
206206

207207
if (showBounds)
208208
{
209-
this.context.strokeStyle = 'rgba(0,255,0,0.8)';
209+
this.context.strokeStyle = 'rgba(255,0,0,1)';
210210
this.context.strokeRect(sprite.bounds.x, sprite.bounds.y, sprite.bounds.width, sprite.bounds.height);
211211
this.context.stroke();
212212
}
213213

214-
this.context.beginPath();
215-
this.context.moveTo(sprite.topLeft.x, sprite.topLeft.y);
216-
this.context.lineTo(sprite.topRight.x, sprite.topRight.y);
217-
this.context.lineTo(sprite.bottomRight.x, sprite.bottomRight.y);
218-
this.context.lineTo(sprite.bottomLeft.x, sprite.bottomLeft.y);
219-
this.context.closePath();
220-
this.context.strokeStyle = 'rgba(0,0,255,0.8)';
221-
this.context.stroke();
214+
// this.context.beginPath();
215+
// this.context.moveTo(sprite.topLeft.x, sprite.topLeft.y);
216+
// this.context.lineTo(sprite.topRight.x, sprite.topRight.y);
217+
// this.context.lineTo(sprite.bottomRight.x, sprite.bottomRight.y);
218+
// this.context.lineTo(sprite.bottomLeft.x, sprite.bottomLeft.y);
219+
// this.context.closePath();
220+
// this.context.strokeStyle = 'rgba(255,0,0,1)';
221+
// this.context.stroke();
222222

223223
this.renderPoint(sprite.center);
224224
this.renderPoint(sprite.topLeft);

0 commit comments

Comments
 (0)