Skip to content

Commit 6bf7bab

Browse files
committed
Fixed some errors in Rectangle and more Pixi hooks added, now creating the Stage properly and rendering sprites.
1 parent 19483ba commit 6bf7bab

8 files changed

Lines changed: 137 additions & 47 deletions

File tree

examples/js.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@
4545
<script src="../src/core/StateManager.js"></script>
4646
<script src="../src/core/State.js"></script>
4747
<script src="../src/system/RequestAnimationFrame.js"></script>
48+
<script src="../src/system/Canvas.js"></script>
4849
<script src="../src/system/Device.js"></script>
4950
<script src="../src/core/SignalBinding.js"></script>
5051
<script src="../src/core/Signal.js"></script>
@@ -54,6 +55,7 @@
5455
<script src="../src/math/Math.js"></script>
5556
<script src="../src/geom/Point.js"></script>
5657
<script src="../src/geom/Circle.js"></script>
58+
<script src="../src/geom/Rectangle.js"></script>
5759
<script src="../src/net/Net.js"></script>
5860
<script src="../src/tween/TweenManager.js"></script>
5961
<script src="../src/tween/Tween.js"></script>

examples/rect1.php

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
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+
var game = new Phaser.Game();
14+
15+
var r = new Phaser.Rectangle(0,0,100,100);
16+
17+
console.log(r);
18+
19+
</script>
20+
21+
</body>
22+
</html>

examples/stage 1.php

Lines changed: 32 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -12,21 +12,48 @@
1212

1313
(function () {
1414

15-
// In this approach we're simply using functions in the current scope to do what we need
16-
var game = new Phaser.Game(800, 600, Phaser.RENDERER_AUTO, '', { preload: preload, create: create });
15+
// var game = new Phaser.Game(800, 600, Phaser.AUTO, '', { preload: preload, create: create, update: update });
16+
var game = new Phaser.Game(800, 600, Phaser.CANVAS, '', { preload: preload, create: create, update: update });
17+
18+
var bunny;
1719

1820
function preload() {
1921

20-
console.log('*** preload called');
22+
console.log('***> preload called');
2123
game.load.image('cockpit', 'assets/pics/cockpit.png');
2224
game.load.image('overdose', 'assets/pics/lance-overdose-loader_eye.png');
2325

2426
}
2527

2628
function create() {
2729

28-
console.log('*** create called');
29-
document.body.appendChild(game.cache.getImage('cockpit'));
30+
console.log('***> create called');
31+
32+
// Create a basetexture
33+
var base = new PIXI.BaseTexture(game.cache.getImage('overdose'));
34+
var texture = new PIXI.Texture(base);
35+
bunny = new PIXI.Sprite(texture);
36+
37+
// center the sprites anchor point
38+
bunny.anchor.x = 0.5;
39+
bunny.anchor.y = 0.5;
40+
41+
// move the sprite t the center of the screen
42+
bunny.position.x = 200;
43+
bunny.position.y = 150;
44+
45+
game.stage._s.addChild(bunny);
46+
47+
}
48+
49+
function update() {
50+
51+
if (game.paused == false)
52+
{
53+
bunny.rotation += 0.1;
54+
bunny.scale.x += 0.01;
55+
bunny.scale.y += 0.01;
56+
}
3057

3158
}
3259

src/Game.js

Lines changed: 9 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ Phaser.Game = function (width, height, renderer, parent, state, transparent, ant
2828

2929
if (typeof width === "undefined") { width = 800; }
3030
if (typeof height === "undefined") { height = 600; }
31-
if (typeof renderer === "undefined") { renderer = Phaser.RENDERER_AUTO; }
31+
if (typeof renderer === "undefined") { renderer = Phaser.AUTO; }
3232
if (typeof parent === "undefined") { parent = ''; }
3333
if (typeof state === "undefined") { state = null; }
3434
if (typeof transparent === "undefined") { transparent = false; }
@@ -43,9 +43,6 @@ Phaser.Game = function (width, height, renderer, parent, state, transparent, ant
4343
this.transparent = transparent;
4444
this.antialias = antialias;
4545
this.renderType = renderer;
46-
// this.renderer = renderer;
47-
48-
console.log('Phaser.Game', width, height, renderer, parent, transparent, antialias);
4946

5047
this.state = new Phaser.StateManager(this, state);
5148

@@ -246,8 +243,6 @@ Phaser.Game.prototype = {
246243
return;
247244
}
248245

249-
console.log('Phaser.Game boot');
250-
251246
if (!document.body) {
252247
window.setTimeout(this._onBoot, 20);
253248
}
@@ -287,13 +282,13 @@ Phaser.Game.prototype = {
287282
this.stage.boot();
288283
// this.input.boot();
289284

290-
if (this.renderType == Phaser.RENDERER_CANVAS)
285+
if (this.renderType == Phaser.CANVAS)
291286
{
292-
console.log('Phaser', Phaser.VERSION, 'initialized. Rendering to Canvas');
287+
console.log('%cPhaser ' + Phaser.VERSION + ' initialized. Rendering to Canvas', 'color: #ffff33; background: #000000');
293288
}
294289
else
295290
{
296-
console.log('Phaser', Phaser.VERSION, 'initialized. Rendering to WebGL');
291+
console.log('%cPhaser ' + Phaser.VERSION + ' initialized. Rendering to WebGL', 'color: #ffff33; background: #000000');
297292
}
298293

299294
this.isRunning = true;
@@ -308,11 +303,11 @@ Phaser.Game.prototype = {
308303

309304
setUpRenderer: function () {
310305

311-
if (this.renderType == Phaser.RENDERER_CANVAS || (this.renderer == Phaser.RENDERER_AUTO && this.device.webGL == false))
306+
if (this.renderType == Phaser.CANVAS || (this.renderer == Phaser.AUTO && this.device.webGL == false))
312307
{
313308
if (this.device.canvas)
314309
{
315-
this.renderType = Phaser.RENDERER_CANVAS;
310+
this.renderType = Phaser.CANVAS;
316311
this.renderer = new PIXI.CanvasRenderer(this.width, this.height, null, this.transparent);
317312
Phaser.Canvas.setSmoothingEnabled(this.renderer.view, this.antialias);
318313
}
@@ -373,7 +368,8 @@ Phaser.Game.prototype = {
373368

374369
this.state.preRender();
375370

376-
// this.renderer.render();
371+
this.renderer.render(this.stage._s);
372+
377373
this.plugins.render();
378374

379375
this.state.render();
@@ -389,7 +385,7 @@ Phaser.Game.prototype = {
389385
this.plugins.postUpdate();
390386

391387
this.plugins.preRender();
392-
// this.renderer.render();
388+
this.renderer.render(this.stage._s);
393389
this.plugins.render();
394390
this.state.loadRender();
395391
this.plugins.postRender();

src/Phaser.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -27,8 +27,8 @@ var Phaser = Phaser || {
2727

2828
VERSION: '1.0.0',
2929
GAMES: [],
30-
RENDERER_AUTO: 0,
31-
RENDERER_CANVAS: 1,
32-
RENDERER_WEBGL: 2
30+
AUTO: 0,
31+
CANVAS: 1,
32+
WEBGL: 2
3333

3434
};

src/Stage.js

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,6 @@ Phaser.Stage = function (game) {
1313

1414
this.game = game;
1515

16-
this.bounds = new Phaser.Rectangle;
17-
this.offset = new Phaser.Point;
18-
1916
};
2017

2118
Phaser.Stage.prototype = {
@@ -29,8 +26,9 @@ Phaser.Stage.prototype = {
2926
boot: function () {
3027

3128
// Get the offset values (for input and other things)
29+
this.offset = new Phaser.Point;
3230
Phaser.Canvas.getOffset(this.game.renderer.view, this.offset);
33-
this.bounds.setTo(this.offset.x, this.offset.y, this.game.width, this.game.height);
31+
this.bounds = new Phaser.Rectangle(this.offset.x, this.offset.y, this.game.width, this.game.height);
3432

3533
this._s = new PIXI.Stage(0x000000);
3634

@@ -62,12 +60,12 @@ Phaser.Stage.prototype = {
6260

6361
if (event.type == 'pagehide' || event.type == 'blur' || document['hidden'] == true || document['webkitHidden'] == true)
6462
{
65-
console.log('visibilityChange - hidden', event);
63+
// console.log('visibilityChange - hidden', event);
6664
this.game.paused = true;
6765
}
6866
else
6967
{
70-
console.log('visibilityChange - shown', event);
68+
// console.log('visibilityChange - shown', event);
7169
this.game.paused = false;
7270
}
7371

src/core/StateManager.js

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@ Phaser.StateManager = function (game, pendingState) {
66

77
if (pendingState !== null)
88
{
9-
console.log('StartManager constructor', pendingState);
109
this._pendingState = pendingState;
1110
}
1211

@@ -99,7 +98,7 @@ Phaser.StateManager.prototype = {
9998

10099
boot: function () {
101100

102-
console.log('Phaser.StateManager.boot');
101+
// console.log('Phaser.StateManager.boot');
103102

104103
if (this._pendingState !== null)
105104
{

0 commit comments

Comments
 (0)