This commit is contained in:
Felipe Alfonso 2016-09-19 20:58:18 -03:00
commit 2f3fc22b50
8 changed files with 93 additions and 48 deletions

View file

@ -138,6 +138,11 @@ Phaser.AnimationParser = {
frames[i].spriteSourceSize.h frames[i].spriteSourceSize.h
); );
} }
if (frames[i].rotated)
{
newFrame.rotated = true;
}
} }
return data; return data;
@ -251,6 +256,11 @@ Phaser.AnimationParser = {
); );
} }
if (frames[key].rotated)
{
newFrame.rotated = true;
}
i++; i++;
} }

View file

@ -64,7 +64,7 @@ Phaser.Frame = function (index, x, y, width, height, name) {
this.distance = Phaser.Math.distance(0, 0, width, height); this.distance = Phaser.Math.distance(0, 0, width, height);
/** /**
* @property {boolean} rotated - Rotated? (not yet implemented) * @property {boolean} rotated - Is the frame rotated in the source texture?
* @default * @default
*/ */
this.rotated = false; this.rotated = false;

View file

@ -190,6 +190,11 @@ Phaser.Component.LoadTexture.prototype = {
this.texture.trim = null; this.texture.trim = null;
} }
if (frame.rotated)
{
this.texture.rotated = true;
}
if (this.cropRect) if (this.cropRect)
{ {
this.updateCrop(); this.updateCrop();

View file

@ -448,62 +448,86 @@ PIXI.Sprite.prototype._renderCanvas = function(renderSession, matrix)
} }
// Ignore null sources // Ignore null sources
if (this.texture.valid) if (!this.texture.valid)
{ {
var resolution = this.texture.baseTexture.resolution / renderSession.resolution; // Update the children and leave
for (var i = 0; i < this.children.length; i++)
renderSession.context.globalAlpha = this.worldAlpha;
// If smoothingEnabled is supported and we need to change the smoothing property for this texture
if (renderSession.smoothProperty && renderSession.scaleMode !== this.texture.baseTexture.scaleMode)
{ {
renderSession.scaleMode = this.texture.baseTexture.scaleMode; this.children[i]._renderCanvas(renderSession);
renderSession.context[renderSession.smoothProperty] = (renderSession.scaleMode === PIXI.scaleModes.LINEAR);
} }
// If the texture is trimmed we offset by the trim x/y, otherwise we use the frame dimensions if (this._mask)
var dx = (this.texture.trim) ? this.texture.trim.x - this.anchor.x * this.texture.trim.width : this.anchor.x * -this.texture.frame.width;
var dy = (this.texture.trim) ? this.texture.trim.y - this.anchor.y * this.texture.trim.height : this.anchor.y * -this.texture.frame.height;
var tx = (wt.tx * renderSession.resolution) + renderSession.shakeX;
var ty = (wt.ty * renderSession.resolution) + renderSession.shakeY;
// Allow for pixel rounding
if (renderSession.roundPixels)
{ {
renderSession.context.setTransform(wt.a, wt.b, wt.c, wt.d, tx | 0, ty | 0); renderSession.maskManager.popMask(renderSession);
dx |= 0;
dy |= 0;
}
else
{
renderSession.context.setTransform(wt.a, wt.b, wt.c, wt.d, tx, ty);
} }
var cw = this.texture.crop.width; return;
var ch = this.texture.crop.height; }
dx /= resolution; var resolution = this.texture.baseTexture.resolution / renderSession.resolution;
dy /= resolution;
if (this.tint !== 0xFFFFFF) renderSession.context.globalAlpha = this.worldAlpha;
// If smoothingEnabled is supported and we need to change the smoothing property for this texture
if (renderSession.smoothProperty && renderSession.scaleMode !== this.texture.baseTexture.scaleMode)
{
renderSession.scaleMode = this.texture.baseTexture.scaleMode;
renderSession.context[renderSession.smoothProperty] = (renderSession.scaleMode === PIXI.scaleModes.LINEAR);
}
// If the texture is trimmed we offset by the trim x/y, otherwise we use the frame dimensions
var dx = (this.texture.trim) ? this.texture.trim.x - this.anchor.x * this.texture.trim.width : this.anchor.x * -this.texture.frame.width;
var dy = (this.texture.trim) ? this.texture.trim.y - this.anchor.y * this.texture.trim.height : this.anchor.y * -this.texture.frame.height;
var tx = (wt.tx * renderSession.resolution) + renderSession.shakeX;
var ty = (wt.ty * renderSession.resolution) + renderSession.shakeY;
// Allow for pixel rounding
if (renderSession.roundPixels)
{
renderSession.context.setTransform(wt.a, wt.b, wt.c, wt.d, tx | 0, ty | 0);
dx |= 0;
dy |= 0;
}
else
{
renderSession.context.setTransform(wt.a, wt.b, wt.c, wt.d, tx, ty);
}
var cw = this.texture.crop.width;
var ch = this.texture.crop.height;
if (this.texture.rotated)
{
// 90 degree coordinate rotation
cw = ch;
ch = this.texture.crop.width;
renderSession.context.translate(0, cw);
renderSession.context.rotate(-1.5707963267948966);
}
dx /= resolution;
dy /= resolution;
if (this.tint !== 0xFFFFFF)
{
if (this.texture.requiresReTint || this.cachedTint !== this.tint)
{ {
if (this.texture.requiresReTint || this.cachedTint !== this.tint) this.tintedTexture = PIXI.CanvasTinter.getTintedTexture(this, this.tint);
{
this.tintedTexture = PIXI.CanvasTinter.getTintedTexture(this, this.tint);
this.cachedTint = this.tint; this.cachedTint = this.tint;
this.texture.requiresReTint = false; this.texture.requiresReTint = false;
} }
renderSession.context.drawImage(this.tintedTexture, 0, 0, cw, ch, dx, dy, cw / resolution, ch / resolution); renderSession.context.drawImage(this.tintedTexture, 0, 0, cw, ch, dx, dy, cw / resolution, ch / resolution);
} }
else else
{ {
var cx = this.texture.crop.x; var cx = this.texture.crop.x;
var cy = this.texture.crop.y; var cy = this.texture.crop.y;
renderSession.context.drawImage(this.texture.baseTexture.source, cx, cy, cw, ch, dx, dy, cw / resolution, ch / resolution);
} renderSession.context.drawImage(this.texture.baseTexture.source, cx, cy, cw, ch, dx, dy, cw / resolution, ch / resolution);
} }
for (var i = 0; i < this.children.length; i++) for (var i = 0; i < this.children.length; i++)

View file

@ -328,13 +328,13 @@ PIXI.WebGLRenderer.prototype.setTexturePriority = function (textureNameCollectio
if (index + 1 < maxTextures) if (index + 1 < maxTextures)
{ {
imageCache[imageName].base.textureIndex = index + 1; imageCache[imageName].base.textureIndex = index + 1;
this.currentBatchedTextures.push(imageName);
} }
else else
{ {
imageCache[imageName].base.textureIndex = maxTextures - 1; imageCache[imageName].base.textureIndex = maxTextures - 1;
} }
this.currentBatchedTextures.push(imageName);
} }
return this.currentBatchedTextures; return this.currentBatchedTextures;

View file

@ -134,6 +134,8 @@ PIXI.Texture = function(baseTexture, frame, crop, trim)
*/ */
this.crop = crop || new PIXI.Rectangle(0, 0, 1, 1); this.crop = crop || new PIXI.Rectangle(0, 0, 1, 1);
this.rotated = false;
if (baseTexture.hasLoaded) if (baseTexture.hasLoaded)
{ {
if (this.noFrame) frame = new PIXI.Rectangle(0, 0, baseTexture.width, baseTexture.height); if (this.noFrame) frame = new PIXI.Rectangle(0, 0, baseTexture.width, baseTexture.height);

View file

@ -1,7 +1,7 @@
/// <reference path="pixi.d.ts" /> /// <reference path="pixi.d.ts" />
/// <reference path="p2.d.ts" /> /// <reference path="p2.d.ts" />
// Type definitions for Phaser 3.0.0 - 7th September 2016 // Type definitions for Phaser 3.0.0
// Project: https://github.com/photonstorm/phaser // Project: https://github.com/photonstorm/phaser
declare module "phaser" { declare module "phaser" {
@ -18,6 +18,7 @@ declare class Phaser {
static CANVAS: number; static CANVAS: number;
static WEBGL: number; static WEBGL: number;
static HEADLESS: number; static HEADLESS: number;
static WEBGL_MULTI: number;
static BITMAPDATA: number; static BITMAPDATA: number;
static BITMAPTEXT: number; static BITMAPTEXT: number;
@ -1402,6 +1403,7 @@ declare module Phaser {
seed?: string; seed?: string;
state?: Phaser.State; state?: Phaser.State;
forceSetTimeOut: boolean; forceSetTimeOut: boolean;
multiTextue: boolean;
} }

View file

@ -1300,6 +1300,7 @@ declare module PIXI {
clearBeforeRender: boolean; clearBeforeRender: boolean;
width: number; width: number;
height: number; height: number;
currentBatchedTextures: string[];
view: HTMLCanvasElement; view: HTMLCanvasElement;
projection: Point; projection: Point;
offset: Point; offset: Point;
@ -1318,6 +1319,7 @@ declare module PIXI {
updateTexture(texture: Texture): void; updateTexture(texture: Texture): void;
destroy(): void; destroy(): void;
mapBlendModes(): void; mapBlendModes(): void;
setTexturePriority(textureNameCollection: string[]): string[];
} }