Anchoring support on SpriteBatch

This commit is contained in:
Felipe Alfonso 2017-01-23 16:35:14 -03:00
parent 5e1e495240
commit bf9022bbe0
4 changed files with 10 additions and 11 deletions

View file

@ -21,7 +21,7 @@ var ImageWebGLRenderer = function (renderer, src, interpolationPercentage)
renderer.spriteBatch.add(
frame,
transform._pivotX, transform._pivotY,
transform._anchorX, transform._anchorY,
transform.world.tx, transform.world.ty,
transform._worldScaleX, transform._worldScaleY,
transform._worldRotation,

View file

@ -133,7 +133,7 @@ SpriteBatch.prototype = {
return (this.vertexDataBuffer.getByteLength() >= this.vertexDataBuffer.getByteCapacity());
},
add: function (frame, pivotX, pivotY, translateX, translateY, scaleX, scaleY, rotation, vertexColor)
add: function (frame, anchorX, anchorY, translateX, translateY, scaleX, scaleY, rotation, vertexColor)
{
this.manager.setBatch(this, frame.texture.source[0].glTexture);
@ -144,10 +144,10 @@ SpriteBatch.prototype = {
var vertexBufferU32 = vertexDataBuffer.uintView;
var vertexOffset = vertexDataBuffer.allocate(CONST.SPRITE_VERTEX_COMPONENT_COUNT * CONST.SPRITE_VERTEX_COUNT);
var uvs = frame.uvs;
var x = -pivotX;
var y = -pivotY;
var width = frame.width;
var height = frame.height;
var x = width * -anchorX;
var y = height * -anchorY;
vertexBufferF32[vertexOffset++] = x;
vertexBufferF32[vertexOffset++] = y;

View file

@ -137,7 +137,7 @@ SpriteBatch32.prototype = {
return (this.vertexDataBuffer.getByteLength() >= this.vertexDataBuffer.getByteCapacity());
},
add: function (frame, pivotX, pivotY, translateX, translateY, scaleX, scaleY, rotation, vertexColor)
add: function (frame, anchorX, anchorY, translateX, translateY, scaleX, scaleY, rotation, vertexColor)
{
this.manager.setBatch(this, frame.texture.source[0].glTexture);
@ -148,10 +148,10 @@ SpriteBatch32.prototype = {
var vertexBufferU32 = vertexDataBuffer.uintView;
var vertexOffset = vertexDataBuffer.allocate(CONST.SPRITE_VERTEX_COMPONENT_COUNT * CONST.SPRITE_VERTEX_COUNT);
var uvs = frame.uvs;
var x = -pivotX;
var y = -pivotY;
var width = frame.width;
var height = frame.height;
var x = width * -anchorX;
var y = height * -anchorY;
vertexBufferF32[vertexOffset++] = x;
vertexBufferF32[vertexOffset++] = y;

View file

@ -11,10 +11,9 @@ module.exports = [
'void main () {',
' float t_cos = cos(a_rotation);',
' float t_sin = sin(a_rotation);',
' vec2 t_position = a_position * a_scale;',
' vec2 t_position = (a_position );',
' t_position = vec2(t_position.x * t_cos - t_position.y * t_sin, t_position.x * t_sin + t_position.y * t_cos);',
' t_position += a_translate;',
' gl_Position = u_view_matrix * vec4(t_position, 1.0, 1.0);',
' gl_Position = u_view_matrix * vec4((t_position * a_scale) + a_translate, 1.0, 1.0);',
' v_tex_coord = a_tex_coord;',
' v_color = a_color;',
'}'