mirror of
https://github.com/photonstorm/phaser
synced 2024-11-22 12:43:26 +00:00
Generate Grid can now calculate w/h based on ortho texture
This commit is contained in:
parent
675eec8103
commit
e79ec0c96c
2 changed files with 18 additions and 5 deletions
|
@ -59,10 +59,13 @@ var GenerateGridVerts = function (config)
|
|||
var rotateY = GetFastValue(config, 'rotateY', 0);
|
||||
var rotateZ = GetFastValue(config, 'rotateZ', 0);
|
||||
var zIsUp = GetFastValue(config, 'zIsUp', true);
|
||||
var isOrtho = GetFastValue(config, 'isOrtho', mesh.dirtyCache[11]);
|
||||
var colors = GetFastValue(config, 'colors', [ 0xffffff ]);
|
||||
var alphas = GetFastValue(config, 'alphas', [ 1 ]);
|
||||
var tile = GetFastValue(config, 'tile', false);
|
||||
|
||||
var widthSet = GetFastValue(config, 'width', null);
|
||||
|
||||
var result = {
|
||||
faces: [],
|
||||
verts: []
|
||||
|
@ -72,6 +75,17 @@ var GenerateGridVerts = function (config)
|
|||
tempRotation.set(rotateX, rotateY, rotateZ);
|
||||
tempMatrix.fromRotationXYTranslation(tempRotation, tempPosition, zIsUp);
|
||||
|
||||
// If the Mesh is ortho and no width/height is given, we'll default to texture sizes (if set!)
|
||||
if (!widthSet && isOrtho && texture)
|
||||
{
|
||||
var textureFrame = texture.get(frame);
|
||||
|
||||
var renderer = mesh.scene.sys.renderer;
|
||||
|
||||
width = textureFrame.width / renderer.height;
|
||||
height = textureFrame.height / renderer.height;
|
||||
}
|
||||
|
||||
var halfWidth = width / 2;
|
||||
var halfHeight = height / 2;
|
||||
|
||||
|
@ -95,10 +109,8 @@ var GenerateGridVerts = function (config)
|
|||
var frameV0 = 0;
|
||||
var frameV1 = 1;
|
||||
|
||||
if (texture)
|
||||
if (textureFrame)
|
||||
{
|
||||
var textureFrame = texture.get(frame);
|
||||
|
||||
frameU0 = textureFrame.u0;
|
||||
frameU1 = textureFrame.u1;
|
||||
frameV0 = textureFrame.v0;
|
||||
|
|
|
@ -5,8 +5,8 @@
|
|||
* @property {(string|Phaser.Textures.Texture)} key - The key of the texture to be used for this Grid, as stored in the Texture Manager, or a Texture instance.
|
||||
* @property {(string|integer)} [frame] - The name or index of the frame within the Texture.
|
||||
* @property {Phaser.GameObjects.Mesh} [mesh] - If specified, the vertices of the generated grid will be added to this Mesh Game Object.
|
||||
* @property {number} [width=128] - The width of the grid in pixels.
|
||||
* @property {number} [height=width] - The height of the grid in pixels.
|
||||
* @property {number} [width=1] - The width of the grid in 3D units. If you wish to get a pixel accurate grid based on a texture, you can use an Ortho Mesh or the `isOrtho` parameter.
|
||||
* @property {number} [height=width] - The height of the grid in 3D units.
|
||||
* @property {number} [widthSegments=1] - The number of segments to split the grid horizontally in to.
|
||||
* @property {number} [heightSegments=widthSegments] - The number of segments to split the grid vertically in to.
|
||||
* @property {number} [x=0] - Offset the grid x position by this amount.
|
||||
|
@ -14,4 +14,5 @@
|
|||
* @property {number|number[]} [colors=0xffffff] - An array of colors, one per vertex, or a single color value applied to all vertices.
|
||||
* @property {number|number[]} [alphas=1] - An array of alpha values, one per vertex, or a single alpha value applied to all vertices.
|
||||
* @property {boolean} [tile=false] - Should the texture tile (repeat) across the grid segments, or display as a single texture?
|
||||
* @property {boolean} [isOrtho=false] - If set and using a texture with an ortho Mesh, the `width` and `height` parameters will be calculated based on the frame size for you.
|
||||
*/
|
||||
|
|
Loading…
Reference in a new issue