Skip to content

Commit 67d6845

Browse files
committed
Started work on merging Blittle object back in.
1 parent 4155265 commit 67d6845

3 files changed

Lines changed: 173 additions & 0 deletions

File tree

Lines changed: 75 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,75 @@
1+
/**
2+
* @author Richard Davey <rich@photonstorm.com>
3+
* @copyright 2016 Photon Storm Ltd.
4+
* @license {@link https://github.com/photonstorm/phaser/blob/master/license.txt|MIT License}
5+
*/
6+
7+
var CONST = require('../../const');
8+
var GameObject = require('../GameObject');
9+
10+
/**
11+
* An Image is a light-weight object you can use to display anything that doesn't need physics or animation.
12+
* It can still rotate, scale, crop and receive input events. This makes it perfect for logos, backgrounds, simple buttons and other non-Sprite graphics.
13+
*
14+
* @class Phaser.GameObject.Blitter
15+
* @extends Phaser.GameObject
16+
* @constructor
17+
* @param {Phaser.Game} game - A reference to the currently running game.
18+
* @param {number} [x=0] - The x coordinate of the Image. The coordinate is relative to any parent container this Image may be in.
19+
* @param {number} [y=0] - The y coordinate of the Image. The coordinate is relative to any parent container this Image may be in.
20+
* @param {string} [key] - The texture used by the Image during rendering. It can be a string which is a reference to the Cache entry, or an instance of a RenderTexture, BitmapData or PIXI.Texture.
21+
* @param {string|number} [frame] - If this Image is using part of a sprite sheet or texture atlas you can specify the exact frame to use by giving a string or numeric index.
22+
*/
23+
var Blitter = function (state, x, y, key, frame)
24+
{
25+
var _texture = state.game.textures.get(key);
26+
var _frame = _texture.get(frame);
27+
28+
GameObject.call(this, state, x, y, _texture, _frame);
29+
30+
this.type = CONST.BLITTER;
31+
};
32+
33+
Blitter.prototype = Object.create(GameObject.prototype);
34+
Blitter.prototype.constructor = Blitter;
35+
36+
Blitter.prototype.renderCanvas = require('./BlitterCanvasRenderer');
37+
Blitter.prototype.renderWebGL = require('./BlitterWebGLRenderer');
38+
39+
Object.defineProperties(Blitter.prototype, {
40+
41+
width: {
42+
43+
enumerable: true,
44+
45+
get: function ()
46+
{
47+
return this.transform._scaleX * this.frame.realWidth;
48+
},
49+
50+
set: function (value)
51+
{
52+
this.scaleX = value / this.frame.realWidth;
53+
}
54+
55+
},
56+
57+
height: {
58+
59+
enumerable: true,
60+
61+
get: function ()
62+
{
63+
return this.transform._scaleY * this.frame.realHeight;
64+
},
65+
66+
set: function (value)
67+
{
68+
this.scaleY = value / this.frame.realHeight;
69+
}
70+
71+
}
72+
73+
});
74+
75+
module.exports = Blitter;
Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
/**
2+
* @author Richard Davey <rich@photonstorm.com>
3+
* @copyright 2016 Photon Storm Ltd.
4+
* @license {@link https://github.com/photonstorm/phaser/blob/master/license.txt|MIT License}
5+
*/
6+
7+
var Blitter = require('./Blitter');
8+
var FactoryContainer = require('../../gameobjects/FactoryContainer');
9+
10+
var BlitterFactory = {
11+
12+
KEY: 'blitter',
13+
14+
/**
15+
* Create a new `Blitter` object.
16+
*
17+
* An Image is a light-weight object you can use to display anything that doesn't need physics or animation.
18+
*
19+
* It can still rotate, scale, crop and receive input events.
20+
* This makes it perfect for logos, backgrounds, simple buttons and other non-Sprite graphics.
21+
*
22+
* @method Phaser.GameObject.Factory#image
23+
* @param {number} [x=0] - The x coordinate of the Image. The coordinate is relative to any parent container this Image may be in.
24+
* @param {number} [y=0] - The y coordinate of the Image. The coordinate is relative to any parent container this Image may be in.
25+
* @param {string|Phaser.RenderTexture|Phaser.BitmapData|Phaser.Video|PIXI.Texture} [key] - The image used as a texture by this display object during rendering. If a string Phaser will get for an entry in the Image Cache. Or it can be an instance of a RenderTexture, BitmapData, Video or PIXI.Texture.
26+
* @param {string|number} [frame] - If a Texture Atlas or Sprite Sheet is used this allows you to specify the frame to be used. Use either an integer for a Frame ID or a string for a frame name.
27+
* @param {Phaser.Group} [group] - Optional Group to add the object to. If not specified it will be added to the World group.
28+
* @return {Phaser.Image} The newly created Image object.
29+
*/
30+
add: function (x, y, key, frame, group)
31+
{
32+
if (group === undefined) { group = this.state; }
33+
34+
// console.log('ImageFactory.add', key, x, y, frame, group);
35+
// console.log('into State', this.state);
36+
37+
return group.children.add(new Blitter(this.state, x, y, key, frame));
38+
},
39+
40+
make: function (x, y, key, frame)
41+
{
42+
// console.log('ImageFactory.make', key, x, y, frame);
43+
44+
return new Blitter(this.state, x, y, key, frame);
45+
}
46+
47+
};
48+
49+
module.exports = FactoryContainer.register(BlitterFactory);
Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
2+
var BlitterWebGLRenderer = function (renderer, src, interpolationPercentage)
3+
{
4+
// var frame = src.frame;
5+
var worldAlpha = src.color.worldAlpha * 255 << 24;
6+
7+
// Skip rendering?
8+
9+
if (src.skipRender || !src.visible || worldAlpha === 0)
10+
{
11+
return;
12+
}
13+
14+
// var verts = src.transform.getVertexData(interpolationPercentage, renderer);
15+
// var index = src.frame.source.glTextureIndex;
16+
// var tint = src.color._glTint;
17+
// var bg = src.color._glBg;
18+
// renderer.batch.add(frame.source, src.blendMode, verts, frame.uvs, index, alpha, tint, bg);
19+
// var transform = src.transform;
20+
21+
// Render children
22+
for (var i = 0; i < src.children.list.length; i++)
23+
{
24+
var bob = src.children.list[i];
25+
var frame = bob.frame;
26+
var alpha = (worldAlpha * bob.alpha) * 255 << 24;
27+
28+
if (!bob.visible || alpha === 0 || !frame.cutWidth || !frame.cutHeight)
29+
{
30+
continue;
31+
}
32+
33+
var index = frame.source.glTextureIndex;
34+
var verts = bob.transform.getVertexData(interpolationPercentage);
35+
36+
// tint and bg values come from the parent Blitter object, not the Bob
37+
renderer.batch.add(frame.source, src.blendMode, verts, frame.uvs, index, alpha, tint, bg);
38+
}
39+
40+
// renderer.spriteBatch.add(
41+
// frame,
42+
// transform._pivotX, transform._pivotY,
43+
// transform.world.tx, transform.world.ty,
44+
// transform._worldScaleX, transform._worldScaleY,
45+
// transform._worldRotation
46+
// );
47+
};
48+
49+
module.exports = BlitterWebGLRenderer;

0 commit comments

Comments
 (0)