Skip to content

Commit 66e86e7

Browse files
committed
Tiling Sprite added
1 parent c18de53 commit 66e86e7

10 files changed

Lines changed: 524 additions & 15 deletions

File tree

Binary file not shown.
5.47 MB
Binary file not shown.

examples/assets/sprites/p2.jpeg

15.4 KB
Loading

examples/js.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,7 @@
6363
<script src="../src/system/Canvas.js"></script>
6464
<script src="../src/gameobjects/GameObjectFactory.js"></script>
6565
<script src="../src/gameobjects/Sprite.js"></script>
66+
<script src="../src/gameobjects/TileSprite.js"></script>
6667

6768
<script src="../src/system/Canvas.js"></script>
6869
<script src="../src/system/Device.js"></script>

examples/tilesprite1.php

Lines changed: 76 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,76 @@
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(800, 600, Phaser.CANVAS, '', { preload: preload, create: create, update: update, render: render });
16+
17+
function preload() {
18+
game.load.image('disk', 'assets/sprites/p2.jpeg');
19+
}
20+
21+
var s;
22+
var count = 0;
23+
24+
function create() {
25+
26+
game.world._stage.backgroundColorString = '#182d3b';
27+
28+
s = game.add.tileSprite(0, 0, 512, 512, 'disk');
29+
// s.rotation = 0.1;
30+
31+
}
32+
33+
function update() {
34+
35+
count += 0.005
36+
37+
// s.rotation += 0.01;
38+
39+
s.tileScale.x = 2 + Math.sin(count);
40+
s.tileScale.y = 2 + Math.cos(count);
41+
42+
s.tilePosition.x += 1;
43+
s.tilePosition.y += 1;
44+
45+
if (game.input.keyboard.isDown(Phaser.Keyboard.LEFT))
46+
{
47+
s.x -= 4;
48+
}
49+
else if (game.input.keyboard.isDown(Phaser.Keyboard.RIGHT))
50+
{
51+
s.x += 4;
52+
}
53+
54+
if (game.input.keyboard.isDown(Phaser.Keyboard.UP))
55+
{
56+
s.y -= 4;
57+
}
58+
else if (game.input.keyboard.isDown(Phaser.Keyboard.DOWN))
59+
{
60+
s.y += 4;
61+
}
62+
63+
}
64+
65+
function render() {
66+
67+
// game.debug.renderSpriteCorners(s, true, true);
68+
69+
}
70+
71+
})();
72+
73+
</script>
74+
75+
</body>
76+
</html>

examples/tilesprite2.php

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
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(800, 600, Phaser.AUTO, '', { preload: preload, create: create, update: update });
16+
17+
var s;
18+
19+
function preload() {
20+
game.load.image('disk', 'assets/misc/starfield.jpg');
21+
}
22+
23+
function create() {
24+
s = game.add.tileSprite(0, 0, 800, 600, 'disk');
25+
}
26+
27+
function update() {
28+
29+
if (game.input.keyboard.isDown(Phaser.Keyboard.LEFT))
30+
{
31+
s.tilePosition.x += 8;
32+
}
33+
else if (game.input.keyboard.isDown(Phaser.Keyboard.RIGHT))
34+
{
35+
s.tilePosition.x -= 8;
36+
}
37+
38+
if (game.input.keyboard.isDown(Phaser.Keyboard.UP))
39+
{
40+
s.tilePosition.y += 8;
41+
}
42+
else if (game.input.keyboard.isDown(Phaser.Keyboard.DOWN))
43+
{
44+
s.tilePosition.y -= 8;
45+
}
46+
47+
}
48+
49+
})();
50+
51+
</script>
52+
53+
</body>
54+
</html>

src/gameobjects/GameObjectFactory.js

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -21,9 +21,6 @@ Phaser.GameObjectFactory.prototype = {
2121
*/
2222
sprite: function (x, y, key, frame) {
2323

24-
if (typeof key === "undefined") { key = ''; }
25-
if (typeof frame === "undefined") { frame = null; }
26-
2724
return this.world.add(new Phaser.Sprite(this.game, x, y, key, frame));
2825

2926
},
@@ -37,20 +34,22 @@ Phaser.GameObjectFactory.prototype = {
3734
*/
3835
tween: function (obj, localReference) {
3936

40-
if (typeof localReference === "undefined") { localReference = false; }
41-
4237
return this.game.tweens.create(obj, localReference);
4338

4439
},
4540

4641
audio: function (key, volume, loop) {
4742

48-
volume = volume || 1;
49-
loop = loop || false;
50-
5143
return this.game.sound.add(key, volume, loop);
5244

53-
}
45+
},
46+
47+
tileSprite: function (x, y, width, height, key, frame) {
48+
49+
return this.world.add(new Phaser.TileSprite(this.game, x, y, width, height, key, frame));
50+
51+
},
52+
5453

5554

5655
};

src/gameobjects/Sprite.js

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -70,13 +70,13 @@ Phaser.Sprite = function (game, x, y, key, frame) {
7070
* @property blendMode
7171
* @type Number
7272
*/
73-
this.blendMode = PIXI.blendModes.NORMAL;
73+
// this.blendMode = PIXI.blendModes.NORMAL;
7474

7575
this.x = x;
7676
this.y = y;
7777

78-
this.updateFrame = true;
79-
this.renderable = true;
78+
// this.updateFrame = true;
79+
// this.renderable = true;
8080

8181
this.position.x = x;
8282
this.position.y = y;
@@ -355,5 +355,4 @@ Object.defineProperty(Phaser.Sprite.prototype, "inCamera", {
355355
return this._cache.cameraVisible;
356356
}
357357

358-
359358
});

0 commit comments

Comments
 (0)