Skip to content

Commit 0c97e8e

Browse files
committed
Starting work on Group.
1 parent b2fa345 commit 0c97e8e

9 files changed

Lines changed: 532 additions & 487 deletions

File tree

Phaser.sublime-workspace

Lines changed: 159 additions & 428 deletions
Large diffs are not rendered by default.

examples/assets/bd/back.png

248 Bytes
Loading

examples/assets/bd/back2.png

399 Bytes
Loading

examples/assets/bd/scroller.png

1.34 KB
Loading

examples/consoleBanner.php

Lines changed: 31 additions & 52 deletions
Original file line numberDiff line numberDiff line change
@@ -14,84 +14,63 @@
1414

1515
(function () {
1616

17-
var game = new Phaser.Game(800, 600, Phaser.CANVAS, '', { preload: preload, create: create, update: update, render: render });
17+
var game = new Phaser.Game(50, 50, Phaser.CANVAS, '', { preload: preload, create: create, update: update, render: render });
1818

1919
function preload() {
20-
// game.load.image('piccie', 'assets/sprites/phaser_tiny.png');
20+
game.load.image('piccie', 'assets/sprites/phaser_tiny.png');
2121
// game.load.image('piccie', 'assets/sprites/carrot.png');
2222
// game.load.image('piccie', 'assets/sprites/phaser-dude.png');
23-
game.load.image('piccie', 'assets/pics/atari_fujilogo.png');
23+
// game.load.image('piccie', 'assets/pics/atari_fujilogo.png');
2424
}
2525

2626
var canvas;
2727
var context;
28+
var logo;
2829

2930
function create() {
3031

31-
var img = game.add.sprite(0, 0, 'piccie');
32+
logo = game.add.sprite(0, 0, 'piccie');
3233

33-
canvas = document.createElement('canvas');
34-
canvas.width = img.width;
35-
canvas.height = img.height;
36-
context = canvas.getContext('2d');
34+
logo.body.velocity = 10;
3735

38-
context.drawImage(game.cache.getImage('piccie'), 0, 0);
36+
}
37+
38+
function colorToHex(color) {
39+
return "0123456789ABCDEF".charAt((color - (color % 16)) / 16) + "0123456789ABCDEF".charAt(color % 16);
40+
}
41+
42+
function canvasToConsole() {
3943

40-
var result = '';
44+
console.clear();
4145

42-
for (var y = 0; y < img.height; y++)
46+
for (var y = 0; y < game.height; y++)
4347
{
44-
var line = '';
45-
var css = '';
48+
// var line = '';
49+
var c = [];
4650
var previousColor = '';
4751

48-
for (var x = 0; x < img.width; x++)
52+
for (var x = 0; x < game.width; x++)
4953
{
50-
var c = context.getImageData(x, y, 1, 1);
51-
var s = "#" + colorToHex(c.data[0]) + colorToHex(c.data[1]) + colorToHex(c.data[2]);
52-
53-
if (s == previousColor)
54-
{
55-
line = line + ' ';
56-
}
57-
else
58-
{
59-
line = line + '%c ';
60-
css = css + "'background: " + s + "', ";
61-
previousColor = s;
62-
}
54+
var rgb = game.renderer.context.getImageData(x, y, 1, 1);
55+
var s = "#" + colorToHex(rgb.data[0]) + colorToHex(rgb.data[1]) + colorToHex(rgb.data[2]);
56+
c.push("'background: " + s + "'");
6357
}
6458

65-
css = css.substr(0, css.length - 2);
66-
67-
result = result + "console.log('" + line + "', " + css + ");\n";
59+
console.log('%c %c %c %c %c %c %c %c %c %c %c %c %c %c %c %c %c %c %c %c %c %c %c %c %c %c %c %c %c %c %c %c %c %c %c %c %c %c %c %c %c %c %c %c %c %c %c %c %c %c ',
60+
c[0], c[1], c[2], c[3], c[4], c[5], c[6], c[7], c[8], c[9],
61+
c[10], c[11], c[12], c[13], c[14], c[15], c[16], c[17], c[18], c[19],
62+
c[20], c[21], c[22], c[23], c[24], c[25], c[26], c[27], c[28], c[29],
63+
c[30], c[31], c[32], c[33], c[34], c[35], c[36], c[37], c[38], c[39],
64+
c[40], c[41], c[42], c[43], c[44], c[45], c[46], c[47], c[48], c[49],
65+
c[50]);
6866
}
6967

70-
document.getElementById('output').innerHTML = result;
71-
72-
}
73-
74-
/**
75-
* Return a string containing a hex representation of the given color
76-
*
77-
* @method colorToHexstring
78-
* @param {Number} color The color channel to get the hex value for, must be a value between 0 and 255)
79-
* @return {String} A string of length 2 characters, i.e. 255 = FF, 0 = 00
80-
*/
81-
function colorToHex(color) {
82-
83-
var digits = "0123456789ABCDEF";
84-
85-
var lsd = color % 16;
86-
var msd = (color - lsd) / 16;
87-
88-
var hexified = digits.charAt(msd) + digits.charAt(lsd);
89-
90-
return hexified;
91-
9268
}
9369

9470
function update() {
71+
72+
canvasToConsole();
73+
9574
}
9675

9776
function render() {

examples/consoleBanner2.php

Lines changed: 86 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,86 @@
1+
<!DOCTYPE HTML>
2+
<html>
3+
<head>
4+
<title>phaser.js - a new beginning</title>
5+
<?php
6+
require('js.php');
7+
?>
8+
</head>
9+
<body>
10+
11+
<script type="text/javascript">
12+
13+
(function () {
14+
15+
var game = new Phaser.Game(50, 30, Phaser.CANVAS, '', { preload: preload, create: create, update: update });
16+
17+
function preload() {
18+
game.load.image('background', 'assets/bd/back2.png');
19+
// game.load.image('piccie', 'assets/sprites/phaser_tiny.png');
20+
game.load.image('scroller', 'assets/bd/scroller.png');
21+
}
22+
23+
var back;
24+
var logo;
25+
var scroller;
26+
var t = 0;
27+
28+
function create() {
29+
30+
back = game.add.sprite(0, 0, 'background');
31+
scroller = game.add.sprite(50, 10, 'scroller');
32+
// logo = game.add.sprite(0, 0, 'piccie');
33+
34+
back.body.moves = false;
35+
36+
// logo.body.velocity.setTo(1,1);
37+
// logo.body.bounce.setTo(1, 1);
38+
// logo.body.collideWorldBounds = true;
39+
40+
game.add.tween(back).to( { y: -60 }, 20000, Phaser.Easing.Linear.None, true, 0, 1000, true);
41+
game.add.tween(scroller).to( { x: -700 }, 700*250, Phaser.Easing.Linear.None, true, 0, 1000);
42+
43+
}
44+
45+
function update() {
46+
47+
if (game.time.now > t)
48+
{
49+
canvasToConsole();
50+
t = game.time.now + 1000;
51+
}
52+
53+
back.y -= 1;
54+
55+
}
56+
57+
function canvasToConsole() {
58+
59+
console.clear();
60+
61+
for (var y = 0; y < game.height; y++)
62+
{
63+
var c = [];
64+
65+
for (var x = 0; x < game.width; x++)
66+
{
67+
var rgb = game.renderer.context.getImageData(x, y, 1, 1);
68+
var s = "#" + colorToHex(rgb.data[0]) + colorToHex(rgb.data[1]) + colorToHex(rgb.data[2]);
69+
c.push("background: " + s + "");
70+
}
71+
72+
console.log('%c %c %c %c %c %c %c %c %c %c %c %c %c %c %c %c %c %c %c %c %c %c %c %c %c %c %c %c %c %c %c %c %c %c %c %c %c %c %c %c %c %c %c %c %c %c %c %c %c %c ', c[0], c[1], c[2], c[3], c[4], c[5], c[6], c[7], c[8], c[9], c[10], c[11], c[12], c[13], c[14], c[15], c[16], c[17], c[18], c[19], c[20], c[21], c[22], c[23], c[24], c[25], c[26], c[27], c[28], c[29], c[30], c[31], c[32], c[33], c[34], c[35], c[36], c[37], c[38], c[39], c[40], c[41], c[42], c[43], c[44], c[45], c[46], c[47], c[48], c[49]);
73+
}
74+
75+
}
76+
77+
function colorToHex(color) {
78+
return "0123456789ABCDEF".charAt((color - (color % 16)) / 16) + "0123456789ABCDEF".charAt(color % 16);
79+
}
80+
81+
})();
82+
83+
</script>
84+
85+
</body>
86+
</html>

0 commit comments

Comments
 (0)