mirror of
https://github.com/photonstorm/phaser
synced 2024-11-23 21:24:09 +00:00
transform checks for setter functions also removed old bitmap text
This commit is contained in:
parent
9353b049aa
commit
7eeb8d5d30
7 changed files with 6 additions and 407 deletions
|
@ -96,15 +96,15 @@ var Transform = {
|
|||
{
|
||||
if (y === undefined) { y = x; }
|
||||
|
||||
this.x = x;
|
||||
this.y = y;
|
||||
this.x = (x ? x : 0.0);
|
||||
this.y = (y ? y : 0.0);
|
||||
|
||||
return this;
|
||||
},
|
||||
|
||||
setRotation: function (radians)
|
||||
{
|
||||
this.rotation = radians;
|
||||
this.rotation = (radians ? radians : 0.0);
|
||||
|
||||
return this;
|
||||
},
|
||||
|
@ -114,8 +114,8 @@ var Transform = {
|
|||
if (x === undefined) { x = 1; }
|
||||
if (y === undefined) { y = x; }
|
||||
|
||||
this.scaleX = x;
|
||||
this.scaleY = y;
|
||||
this.scaleX = (x ? x : 0.0);
|
||||
this.scaleY = (y ? y : 0.0);
|
||||
|
||||
return this;
|
||||
}
|
||||
|
|
|
@ -1,88 +0,0 @@
|
|||
var Class = require('../../utils/Class');
|
||||
var GameObject = require('../GameObject');
|
||||
var Components = require('../../components');
|
||||
var Render = require('./BitmapTextRender');
|
||||
var GetBitmapTextSize = require('./GetBitmapTextSize');
|
||||
|
||||
var BitmapText = new Class({
|
||||
|
||||
Mixins: [
|
||||
Components.Alpha,
|
||||
Components.BlendMode,
|
||||
Components.Origin,
|
||||
Components.Size,
|
||||
Components.Texture,
|
||||
Components.Transform,
|
||||
Components.Visible,
|
||||
Render
|
||||
],
|
||||
|
||||
initialize:
|
||||
|
||||
function BitmapText (state, x, y, font, text, size, align)
|
||||
{
|
||||
if (text === undefined) { text = ''; }
|
||||
if (size === undefined) { size = 32; }
|
||||
if (align === undefined) { align = 'left'; }
|
||||
|
||||
GameObject.call(this, state);
|
||||
|
||||
this.fontData = this.state.sys.cache.bitmapFont.get(font);
|
||||
|
||||
this.text = text;
|
||||
|
||||
this.fontSize = size;
|
||||
|
||||
this.displayCallback;
|
||||
|
||||
this.setTexture(font);
|
||||
this.setPosition(x, y);
|
||||
},
|
||||
|
||||
setDisplayCallback: function (callback)
|
||||
{
|
||||
this.displayCallback = callback;
|
||||
|
||||
return this;
|
||||
},
|
||||
|
||||
setFontSize: function (size)
|
||||
{
|
||||
this.fontSize = size;
|
||||
|
||||
return this;
|
||||
},
|
||||
|
||||
setText: function (text)
|
||||
{
|
||||
this.text = text;
|
||||
|
||||
return this;
|
||||
},
|
||||
|
||||
// {
|
||||
// local: {
|
||||
// x,
|
||||
// y,
|
||||
// width,
|
||||
// height
|
||||
// },
|
||||
// global: {
|
||||
// x,
|
||||
// y,
|
||||
// width,
|
||||
// height
|
||||
// }
|
||||
// }
|
||||
|
||||
getTextBounds: function ()
|
||||
{
|
||||
// local = the BitmapText based on fontSize and 0x0 coords
|
||||
// global = the BitmapText, taking into account scale and world position
|
||||
|
||||
return GetBitmapTextSize(this);
|
||||
}
|
||||
|
||||
});
|
||||
|
||||
module.exports = BitmapText;
|
|
@ -1,149 +0,0 @@
|
|||
var BitmapTextCanvasRenderer = function (renderer, src, interpolationPercentage, camera)
|
||||
{
|
||||
var text = src.text;
|
||||
var textLength = text.length;
|
||||
|
||||
if (this.renderMask !== this.renderFlags || textLength === 0)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
var textureFrame = src.frame;
|
||||
|
||||
var displayCallback = src.displayCallback;
|
||||
|
||||
var cameraScrollX = camera.scrollX;
|
||||
var cameraScrollY = camera.scrollY;
|
||||
|
||||
var chars = src.fontData.chars;
|
||||
var lineHeight = src.fontData.lineHeight;
|
||||
|
||||
var xAdvance = 0;
|
||||
var yAdvance = 0;
|
||||
|
||||
var indexCount = 0;
|
||||
var charCode = 0;
|
||||
|
||||
var glyph = null;
|
||||
var glyphX = 0;
|
||||
var glyphY = 0;
|
||||
var glyphW = 0;
|
||||
var glyphH = 0;
|
||||
|
||||
var x = 0;
|
||||
var y = 0;
|
||||
|
||||
var lastGlyph = null;
|
||||
var lastCharCode = 0;
|
||||
|
||||
var ctx = renderer.currentContext;
|
||||
var image = src.frame.source.image;
|
||||
|
||||
var textureX = textureFrame.cutX;
|
||||
var textureY = textureFrame.cutY;
|
||||
|
||||
var rotation = 0;
|
||||
var scale = (src.fontSize / src.fontData.size);
|
||||
|
||||
// Blend Mode
|
||||
if (renderer.currentBlendMode !== src.blendMode)
|
||||
{
|
||||
renderer.currentBlendMode = src.blendMode;
|
||||
ctx.globalCompositeOperation = renderer.blendModes[src.blendMode];
|
||||
}
|
||||
|
||||
// Alpha
|
||||
if (renderer.currentAlpha !== src.alpha)
|
||||
{
|
||||
renderer.currentAlpha = src.alpha;
|
||||
ctx.globalAlpha = src.alpha;
|
||||
}
|
||||
|
||||
// Smoothing
|
||||
if (renderer.currentScaleMode !== src.scaleMode)
|
||||
{
|
||||
renderer.currentScaleMode = src.scaleMode;
|
||||
}
|
||||
|
||||
ctx.save();
|
||||
ctx.translate(src.x, src.y);
|
||||
ctx.rotate(src.rotation);
|
||||
ctx.scale(src.scaleX, src.scaleY);
|
||||
|
||||
for (var index = 0; index < textLength; ++index)
|
||||
{
|
||||
// Reset the scale (in case the callback changed it)
|
||||
scale = (src.fontSize / src.fontData.size);
|
||||
rotation = 0;
|
||||
|
||||
charCode = text.charCodeAt(index);
|
||||
|
||||
if (charCode === 10)
|
||||
{
|
||||
xAdvance = 0;
|
||||
indexCount = 0;
|
||||
yAdvance += lineHeight;
|
||||
lastGlyph = null;
|
||||
continue;
|
||||
}
|
||||
|
||||
glyph = chars[charCode];
|
||||
|
||||
if (!glyph)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
glyphX = textureX + glyph.x;
|
||||
glyphY = textureY + glyph.y;
|
||||
|
||||
glyphW = glyph.width;
|
||||
glyphH = glyph.height;
|
||||
|
||||
x = indexCount + glyph.xOffset + xAdvance;
|
||||
y = glyph.yOffset + yAdvance;
|
||||
|
||||
if (lastGlyph !== null)
|
||||
{
|
||||
var kerningOffset = glyph.kerning[lastCharCode];
|
||||
x += (kerningOffset !== undefined) ? kerningOffset : 0;
|
||||
}
|
||||
|
||||
if (displayCallback)
|
||||
{
|
||||
var output = displayCallback({ index: index, charCode: charCode, x: x, y: y, scale: scale, rotation: 0 });
|
||||
|
||||
x = output.x;
|
||||
y = output.y;
|
||||
scale = output.scale;
|
||||
rotation = output.rotation;
|
||||
}
|
||||
|
||||
x *= scale;
|
||||
y *= scale;
|
||||
|
||||
x -= cameraScrollX;
|
||||
y -= cameraScrollY;
|
||||
|
||||
ctx.save();
|
||||
ctx.translate(x, y);
|
||||
ctx.rotate(rotation);
|
||||
ctx.scale(scale, scale);
|
||||
|
||||
// ctx.fillStyle = 'rgba(0,255,0,0.2)';
|
||||
// ctx.fillRect(0, 0, glyphW, glyphH);
|
||||
|
||||
ctx.drawImage(image, glyphX, glyphY, glyphW, glyphH, 0, 0, glyphW, glyphH);
|
||||
|
||||
ctx.restore();
|
||||
|
||||
xAdvance += glyph.xAdvance;
|
||||
indexCount += 1;
|
||||
lastGlyph = glyph;
|
||||
lastCharCode = charCode;
|
||||
}
|
||||
|
||||
ctx.restore();
|
||||
};
|
||||
|
||||
module.exports = BitmapTextCanvasRenderer;
|
|
@ -1,20 +0,0 @@
|
|||
var BitmapText = require('./BitmapText');
|
||||
var FactoryContainer = require('../../FactoryContainer');
|
||||
|
||||
var BitmapTextFactory = {
|
||||
|
||||
KEY: 'bitmapText',
|
||||
|
||||
add: function (x, y, font, text, size, align)
|
||||
{
|
||||
return this.state.children.add(new BitmapText(this.state, x, y, font, text, size, align));
|
||||
},
|
||||
|
||||
make: function (x, y, font, text, size, align)
|
||||
{
|
||||
return new BitmapText(this.state, x, y, font, text, size, align);
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
module.exports = FactoryContainer.register(BitmapTextFactory);
|
|
@ -1,6 +0,0 @@
|
|||
module.exports = {
|
||||
|
||||
renderCanvas: require('./BitmapTextCanvasRenderer'),
|
||||
renderWebGL: require('./BitmapTextWebGLRenderer')
|
||||
|
||||
};
|
|
@ -1,138 +0,0 @@
|
|||
var BitmapTextWebGLRenderer = function (renderer, src, interpolationPercentage, camera)
|
||||
{
|
||||
if (this.renderMask !== this.renderFlags)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
var textureFrame = src.frame;
|
||||
var cameraMatrix = camera.matrix.matrix;
|
||||
var a = cameraMatrix[0];
|
||||
var b = cameraMatrix[1];
|
||||
var c = cameraMatrix[2];
|
||||
var d = cameraMatrix[3];
|
||||
var e = cameraMatrix[4];
|
||||
var f = cameraMatrix[5];
|
||||
var cameraScrollX = camera.scrollX;
|
||||
var cameraScrollY = camera.scrollY;
|
||||
var text = src.text;
|
||||
var textLength = text.length;
|
||||
var chars = src.fontData.chars;
|
||||
var lineHeight = src.fontData.lineHeight;
|
||||
var blitterBatch = renderer.blitterBatch;
|
||||
var alpha = src.alpha;
|
||||
var vertexDataBuffer = blitterBatch.vertexDataBuffer;
|
||||
var vertexBuffer = vertexDataBuffer.floatView;
|
||||
var vertexOffset = 0;
|
||||
var srcX = src.x;
|
||||
var srcY = src.y;
|
||||
var textureData = src.texture.source[textureFrame.sourceIndex];
|
||||
var textureX = textureFrame.cutX;
|
||||
var textureY = textureFrame.cutY;
|
||||
var textureWidth = textureData.width;
|
||||
var textureHeight = textureData.height;
|
||||
var texture = textureData.glTexture;
|
||||
var xAdvance = 0;
|
||||
var yAdvance = 0;
|
||||
var indexCount = 0;
|
||||
var charCode = 0;
|
||||
var glyph = null;
|
||||
var glyphX = 0;
|
||||
var glyphY = 0;
|
||||
var glyphW = 0;
|
||||
var glyphH = 0;
|
||||
var x = 0;
|
||||
var y = 0;
|
||||
var xw = 0;
|
||||
var yh = 0;
|
||||
var tx = 0;
|
||||
var ty = 0;
|
||||
var txw = 0;
|
||||
var tyh = 0;
|
||||
var umin = 0;
|
||||
var umax = 0;
|
||||
var vmin = 0;
|
||||
var vmax = 0;
|
||||
var lastGlyph = null;
|
||||
var lastCharCode = 0;
|
||||
|
||||
for (var index = 0; index < textLength; ++index)
|
||||
{
|
||||
charCode = text.charCodeAt(index);
|
||||
if (charCode === 10)
|
||||
{
|
||||
xAdvance = 0;
|
||||
indexCount = 0;
|
||||
yAdvance += lineHeight;
|
||||
lastGlyph = null;
|
||||
continue;
|
||||
}
|
||||
|
||||
glyph = chars[charCode];
|
||||
if (!glyph)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
glyphX = textureX + glyph.x;
|
||||
glyphY = textureY + glyph.y;
|
||||
glyphW = glyph.width;
|
||||
glyphH = glyph.height;
|
||||
x = (srcX + indexCount + glyph.xOffset + xAdvance) - cameraScrollX;
|
||||
y = (srcY + glyph.yOffset + yAdvance) - cameraScrollY;
|
||||
|
||||
if (lastGlyph !== null)
|
||||
{
|
||||
var kerningOffset = glyph.kerning[lastCharCode];
|
||||
x += (kerningOffset !== undefined) ? kerningOffset : 0;
|
||||
}
|
||||
|
||||
xw = x + glyphW;
|
||||
yh = y + glyphH;
|
||||
tx = x * a + y * c + e;
|
||||
ty = x * b + y * d + f;
|
||||
txw = xw * a + yh * c + e;
|
||||
tyh = xw * b + yh * d + f;
|
||||
umin = glyphX / textureWidth;
|
||||
umax = (glyphX + glyphW) / textureWidth;
|
||||
vmin = glyphY / textureHeight;
|
||||
vmax = (glyphY + glyphH) / textureHeight;
|
||||
|
||||
if (blitterBatch.elementCount >= blitterBatch.maxParticles)
|
||||
{
|
||||
blitterBatch.flush();
|
||||
}
|
||||
|
||||
renderer.setBatch(blitterBatch, texture);
|
||||
vertexOffset = vertexDataBuffer.allocate(20);
|
||||
blitterBatch.elementCount += 6;
|
||||
|
||||
vertexBuffer[vertexOffset++] = tx;
|
||||
vertexBuffer[vertexOffset++] = ty;
|
||||
vertexBuffer[vertexOffset++] = umin;
|
||||
vertexBuffer[vertexOffset++] = vmin;
|
||||
vertexBuffer[vertexOffset++] = alpha;
|
||||
vertexBuffer[vertexOffset++] = tx;
|
||||
vertexBuffer[vertexOffset++] = tyh;
|
||||
vertexBuffer[vertexOffset++] = umin;
|
||||
vertexBuffer[vertexOffset++] = vmax;
|
||||
vertexBuffer[vertexOffset++] = alpha;
|
||||
vertexBuffer[vertexOffset++] = txw;
|
||||
vertexBuffer[vertexOffset++] = tyh;
|
||||
vertexBuffer[vertexOffset++] = umax;
|
||||
vertexBuffer[vertexOffset++] = vmax;
|
||||
vertexBuffer[vertexOffset++] = alpha;
|
||||
vertexBuffer[vertexOffset++] = txw;
|
||||
vertexBuffer[vertexOffset++] = ty;
|
||||
vertexBuffer[vertexOffset++] = umax;
|
||||
vertexBuffer[vertexOffset++] = vmin;
|
||||
vertexBuffer[vertexOffset++] = alpha;
|
||||
|
||||
xAdvance += glyph.xAdvance;
|
||||
indexCount += 1;
|
||||
lastGlyph = glyph;
|
||||
lastCharCode = charCode;
|
||||
}
|
||||
};
|
||||
|
||||
module.exports = BitmapTextWebGLRenderer;
|
|
@ -108,8 +108,8 @@ var Graphics = new Class({
|
|||
{
|
||||
this.beginPath();
|
||||
this.arc(x, y, radius, 0, MATH_CONST.PI2);
|
||||
this.strokePath();
|
||||
this.closePath();
|
||||
this.strokePath();
|
||||
},
|
||||
|
||||
strokeRect: function (x, y, width, height)
|
||||
|
|
Loading…
Reference in a new issue