Jump to content

Sprite transformation matrix?


spinnerbox
 Share

Recommended Posts

I have this utility function:

var geoObjContainsPt = function (geoObj, x, y) {
     return geoObj.getBounds().contains(x, y);
}

When I use it with sprite type of object it does not work in all cases. Maybe the bug is elsewhere but as I checked the docs,

Phaser.Sprite.getBounds() wants Sprite's transformation matrix. I guess that is coordinate transformation matrix. Not sure.

But how can I get it?

Some connection with worldTransform. What is that?

Or should I use getLocalBounds()?

Note: On the contrary Phaser.Graphics.getBounds() does not need a parameter.

http://phaser.io/docs/2.6.2/Phaser.Sprite.html#getBounds

http://phaser.io/docs/2.6.2/Phaser.Graphics.html#getBounds

Only certain sprites get tinted with green. Some sort of a pattern haha :D

SlotMatrix.png

Link to comment
Share on other sites

Tried this sort of thing. Its the same result:

var spriteContainsPt = function (geoObj, x, y, frameX, frameY) {
    var matrix = new Phaser.Matrix(1, 0, 0, 1, frameX, frameY);

    return geoObj.getBounds(matrix.translate(x, y)).contains(x, y);
};

But ok, I add the sprites inside a Phaser.Graphics object so when i get them with

tileContainerGraphics.children

It returns array of DisplayObject objects. Does this changes something?

EDIT: DisplayObject does not have getBounds() function

Link to comment
Share on other sites

Lost whole day just to find out that my indexes were not calculated correctly.

I am translating two dimensional array indexes to a one dimensional array index. Both arrays have the same amount of elements.

I created my own utility function. Something like:

var convertTwoDimIndexesToOneDimIndex = function (cols, currentRow, currentCol) {
    return currentCol + cols * currentRow;
};

 

Link to comment
Share on other sites

 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...