Skip to content

Commit 6a8e6a7

Browse files
committed
Adding in Phaser.Create.
1 parent d027bf8 commit 6a8e6a7

3 files changed

Lines changed: 102 additions & 0 deletions

File tree

build/config.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -102,6 +102,7 @@
102102
<script src="$path/src/geom/RoundedRectangle.js"></script>
103103
104104
<script src="$path/src/core/Camera.js"></script>
105+
<script src="$path/src/core/Create.js"></script>
105106
<script src="$path/src/core/State.js"></script>
106107
<script src="$path/src/core/StateManager.js"></script>
107108
<script src="$path/src/core/Signal.js"></script>

src/core/Create.js

Lines changed: 95 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,95 @@
1+
/**
2+
* @author Richard Davey <rich@photonstorm.com>
3+
* @copyright 2015 Photon Storm Ltd.
4+
* @license {@link https://github.com/photonstorm/phaser/blob/master/license.txt|MIT License}
5+
*/
6+
7+
/**
8+
*
9+
* TODO: Gradient generator
10+
* TODO: Look at bsfxr for audio gen
11+
* TODO: Dither support
12+
*
13+
* @class Phaser.Create
14+
* @constructor
15+
* @param {Phaser.Game} game - Game reference to the currently running game.
16+
*/
17+
Phaser.Create = function (game) {
18+
19+
/**
20+
* @property {Phaser.Game} game - A reference to the currently running Game.
21+
*/
22+
this.game = game;
23+
24+
this.bmd = game.make.bitmapData();
25+
26+
this.canvas = this.bmd.canvas;
27+
this.ctx = this.bmd.context;
28+
29+
// http://androidarts.com/palette/16pal.htm
30+
31+
this.palettes = {
32+
'arne': { 0: '#000000', 1: '#9D9D9D', 2: '#FFFFFF', 3: '#BE2633', 4: '#E06F8B', 5: '#493C2B', 6: '#A46422', 7: '#EB8931', 8: '#F7E26B', 9: '#2F484E', A: '#44891A', B: '#A3CE27', C: '#1B2632', D: '#005784', E: '#31A2F2', F: '#B2DCEF' },
33+
'jmp': { 0: '#000000', 1: '#191028', 2: '#46af45', 3: '#a1d685', 4: '#453e78', 5: '#7664fe', 6: '#833129', 7: '#9ec2e8', 8: '#dc534b', 9: '#e18d79', A: '#d6b97b', B: '#e9d8a1', C: '#216c4b', D: '#d365c8', E: '#afaab9', F: '#f5f4eb' },
34+
'cga': { 0: '#000000', 1: '#2234d1', 2: '#0c7e45', 3: '#44aacc', 4: '#8a3622', 5: '#5c2e78', 6: '#aa5c3d', 7: '#b5b5b5', 8: '#5e606e', 9: '#4c81fb', A: '#6cd947', B: '#7be2f9', C: '#eb8a60', D: '#e23d69', E: '#ffd93f', F: '#fffff' }
35+
};
36+
37+
};
38+
39+
Phaser.Create.prototype = {
40+
41+
texture: function (key, data, pixelWidth, pixelHeight, palette) {
42+
43+
if (typeof pixelWidth === 'undefined') { pixelWidth = 8; }
44+
if (typeof pixelHeight === 'undefined') { pixelHeight = 8; }
45+
if (typeof palette === 'undefined') { palette = 'arne'; }
46+
47+
var w = data[0].length * pixelWidth;
48+
var h = data.length * pixelHeight;
49+
50+
this.bmd.resize(w, h);
51+
52+
// Draw it
53+
for (var y = 0; y < data.length; y++)
54+
{
55+
var row = data[y];
56+
57+
for (var x = 0; x < row.length; x++)
58+
{
59+
var d = row[x];
60+
61+
if (d !== '.' && d !== ' ')
62+
{
63+
this.ctx.fillStyle = this.palettes[palette][d];
64+
this.ctx.fillRect(x * pixelWidth, y * pixelHeight, pixelWidth, pixelHeight);
65+
}
66+
}
67+
}
68+
69+
return this.bmd.generateTexture(key);
70+
71+
},
72+
73+
grid: function (key, width, height, cellWidth, cellHeight, color) {
74+
75+
this.bmd.resize(width, height);
76+
77+
this.ctx.fillStyle = color;
78+
79+
for (var y = 0; y < height; y += cellHeight)
80+
{
81+
this.ctx.fillRect(0, y, width, 1);
82+
}
83+
84+
for (var x = 0; x < width; x += cellWidth)
85+
{
86+
this.ctx.fillRect(x, 0, 1, height);
87+
}
88+
89+
return this.bmd.generateTexture(key);
90+
91+
}
92+
93+
};
94+
95+
Phaser.Create.prototype.constructor = Phaser.Create;

src/core/Game.js

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -252,6 +252,11 @@ Phaser.Game = function (width, height, renderer, parent, state, transparent, ant
252252
*/
253253
this.particles = null;
254254

255+
/**
256+
* @property {Phaser.Create} create - The Asset Generator.
257+
*/
258+
this.create = null;
259+
255260
/**
256261
* If `false` Phaser will automatically render the display list every update. If `true` the render loop will be skipped.
257262
* You can toggle this value at run-time to gain exact control over when Phaser renders. This can be useful in certain types of game or application.
@@ -542,6 +547,7 @@ Phaser.Game.prototype = {
542547
this.sound = new Phaser.SoundManager(this);
543548
this.physics = new Phaser.Physics(this, this.physicsConfig);
544549
this.particles = new Phaser.Particles(this);
550+
this.create = new Phaser.Create(this);
545551
this.plugins = new Phaser.PluginManager(this);
546552
this.net = new Phaser.Net(this);
547553

0 commit comments

Comments
 (0)