Skip to content

Commit 4d80d6c

Browse files
committed
Merge remote-tracking branch 'photonstorm_phaser/dev' into dev
2 parents 04ebae7 + 83cacb9 commit 4d80d6c

17 files changed

Lines changed: 572 additions & 29 deletions

File tree

README.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,8 @@ Change Log
4141

4242
Version 1.1.3 - in build
4343

44+
* New: The object returned by Math.sinCosGenerator now contains a length property.
45+
* New: Phaser.BitmapData object. Can be used as a texture for a Sprite or Tiling Sprite. See the new examples and docs for details.
4446
* New: RenderTexture.render now takes a Phaser.Group. Also added renderXY for when you don't want to make a new Point object.
4547
* New: Implementing PluginManager.remove, added PluginManager.removeAll (thanks crazysam)
4648
* New: Added scrollFactorX/scrollFactorY to TilemapLayers (thanks jcd-as)
@@ -69,6 +71,8 @@ Version 1.1.3 - in build
6971
* Updated: If running in Canvas mode and you have a render function it will save the context and reset the transform before running your render function
7072
* Updated: Sprite will now check the exists property of the Group it is in, if the Group.exists = false the Sprite won't update.
7173
* Updated: Lots of small documentation tweaks across various files such as Pointer.
74+
* Updated: If you specify 'null' as a Group parent it will now revert to using the World as the parent (before only 'undefined' worked)
75+
7276

7377

7478

build/config.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,6 @@
5959

6060
<script src="../src/pixi/textures/BaseTexture.js"></script>
6161
<script src="../src/pixi/textures/Texture.js"></script>
62-
<script src="../src/pixi/textures/RenderTexture.js"></script>
6362

6463
<script src="../src/pixi/utils/EventTarget.js"></script>
6564
<script src="../src/pixi/utils/Polyk.js"></script>
@@ -88,6 +87,7 @@
8887

8988
<script src="../src/gameobjects/Events.js"></script>
9089
<script src="../src/gameobjects/GameObjectFactory.js"></script>
90+
<script src="../src/gameobjects/BitmapData.js"></script>
9191
<script src="../src/gameobjects/Sprite.js"></script>
9292
<script src="../src/gameobjects/TileSprite.js"></script>
9393
<script src="../src/gameobjects/Text.js"></script>

examples/_site/view_full.html

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,7 @@
9595
<script src="../src/input/InputHandler.js"></script>
9696
<script src="../src/gameobjects/Events.js"></script>
9797
<script src="../src/gameobjects/GameObjectFactory.js"></script>
98+
<script src="../src/gameobjects/BitmapData.js"></script>
9899
<script src="../src/gameobjects/Sprite.js"></script>
99100
<script src="../src/gameobjects/TileSprite.js"></script>
100101
<script src="../src/gameobjects/Text.js"></script>

examples/_site/view_lite.html

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,7 @@
9494
<script src="../src/input/InputHandler.js"></script>
9595
<script src="../src/gameobjects/Events.js"></script>
9696
<script src="../src/gameobjects/GameObjectFactory.js"></script>
97+
<script src="../src/gameobjects/BitmapData.js"></script>
9798
<script src="../src/gameobjects/Sprite.js"></script>
9899
<script src="../src/gameobjects/TileSprite.js"></script>
99100
<script src="../src/gameobjects/Text.js"></script>
Lines changed: 77 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,77 @@
1+
2+
var game = new Phaser.Game(800, 600, Phaser.AUTO, 'phaser-example', { preload: preload, create: create, update: update });
3+
4+
function preload() {
5+
6+
game.load.image('ball', 'assets/sprites/shinyball.png');
7+
8+
}
9+
10+
var bmd;
11+
12+
var waveSize = 8;
13+
var wavePixelChunk = 2;
14+
var waveData;
15+
var waveDataCounter;
16+
17+
function create() {
18+
19+
// Create our BitmapData object at a size of 32x64
20+
bmd = game.add.bitmapData('ball', 32, 64);
21+
22+
// And apply it to 100 randomly positioned sprites
23+
for (var i = 0; i < 100; i++)
24+
{
25+
game.add.sprite(game.world.randomX, game.world.randomY, bmd);
26+
}
27+
28+
// Populate the wave with some data
29+
waveData = game.math.sinCosGenerator(32, 8, 8, 2);
30+
31+
}
32+
33+
function update() {
34+
35+
// Clear the BitmapData
36+
bmd.clear();
37+
38+
updateWobblyBall();
39+
40+
}
41+
42+
// This creates a simple sine-wave effect running through our BitmapData.
43+
// This is then duplicated across all 100 sprites using it, meaning we only have to calculate it and upload it to the GPU once.
44+
45+
function updateWobblyBall()
46+
{
47+
var s = 0;
48+
var copyRect = { x: 0, y: 0, w: wavePixelChunk, h: 32 };
49+
var copyPoint = { x: 0, y: 0 };
50+
51+
for (var x = 0; x < 32; x += wavePixelChunk)
52+
{
53+
copyPoint.x = x;
54+
copyPoint.y = waveSize + (waveSize / 2) + waveData.sin[s];
55+
56+
bmd.context.drawImage(game.cache.getImage('ball'), copyRect.x, copyRect.y, copyRect.w, copyRect.h, copyPoint.x, copyPoint.y, copyRect.w, copyRect.h);
57+
58+
copyRect.x += wavePixelChunk;
59+
60+
s++;
61+
}
62+
63+
// Now all the pixel data has been redrawn we render it to the BitmapData object.
64+
// In CANVAS mode this doesn't do anything, but on WebGL it pushes the new texture to the GPU.
65+
// If your game is exclusively running under Canvas you ca safely ignore this step.
66+
bmd.render();
67+
68+
// Cycle through the wave data - this is what causes the image to "undulate"
69+
game.math.shift(waveData.sin);
70+
71+
waveDataCounter++;
72+
73+
if (waveDataCounter == waveData.length)
74+
{
75+
waveDataCounter = 0;
76+
}
77+
}

examples/tilemaps/sci fly.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,7 @@ function create() {
5252

5353
sprite = game.add.sprite(450, 80, 'phaser');
5454
sprite.anchor.setTo(0.5, 0.5);
55+
sprite.angle = 45;
5556

5657
game.camera.follow(sprite);
5758
// game.camera.deadzone = new Phaser.Rectangle(160, 160, layer.renderWidth-320, layer.renderHeight-320);
@@ -111,7 +112,7 @@ function update() {
111112

112113
function render() {
113114

114-
// game.debug.renderSpriteCorners(sprite);
115+
game.debug.renderSpriteBounds(sprite);
115116
// game.debug.renderSpriteInfo(sprite, 32, 32);
116117
// game.debug.renderSpriteCoords(sprite, 32, 32);
117118

examples/wip/bmd.js

Lines changed: 82 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,82 @@
1+
2+
var game = new Phaser.Game(800, 600, Phaser.AUTO, 'phaser-example', { preload: preload, create: create, update: update, render: render });
3+
4+
function preload() {
5+
6+
game.load.image('atari1', 'assets/sprites/atari130xe.png');
7+
game.load.image('coke', 'assets/sprites/cokecan.png');
8+
game.load.image('mushroom', 'assets/sprites/mushroom2.png');
9+
game.load.image('ball', 'assets/sprites/shinyball.png');
10+
11+
}
12+
13+
var bmd;
14+
15+
function create() {
16+
17+
bmd = game.add.bitmapData('ball', 32, 64);
18+
19+
console.log(bmd);
20+
21+
// And apply it to 100 randomly positioned sprites
22+
for (var i = 0; i < 100; i++)
23+
{
24+
game.add.sprite(game.world.randomX - 32, game.world.randomY - 64, bmd);
25+
}
26+
27+
// Populate the wave with some data
28+
waveData = game.math.sinCosGenerator(32, 8, 8, 2);
29+
30+
}
31+
32+
function update() {
33+
34+
bmd.clear();
35+
36+
updateWobblyBall();
37+
38+
}
39+
40+
// This creates a simple sine-wave effect running through our DynamicTexture.
41+
// This is then duplicated across all sprites using it, meaning we only have to calculate it once.
42+
43+
var waveSize = 8;
44+
var wavePixelChunk = 2;
45+
var waveData;
46+
var waveDataCounter;
47+
48+
function updateWobblyBall()
49+
{
50+
var s = 0;
51+
var copyRect = { x: 0, y: 0, w: wavePixelChunk, h: 32 };
52+
var copyPoint = { x: 0, y: 0 };
53+
54+
for (var x = 0; x < 32; x += wavePixelChunk)
55+
{
56+
copyPoint.x = x;
57+
copyPoint.y = waveSize + (waveSize / 2) + waveData.sin[s];
58+
59+
bmd.context.drawImage(game.cache.getImage('ball'), copyRect.x, copyRect.y, copyRect.w, copyRect.h, copyPoint.x, copyPoint.y, copyRect.w, copyRect.h);
60+
61+
copyRect.x += wavePixelChunk;
62+
63+
s++;
64+
}
65+
66+
// Cycle through the wave data - this is what causes the image to "undulate"
67+
game.math.shift(waveData.sin);
68+
69+
waveDataCounter++;
70+
71+
if (waveDataCounter == waveData.length)
72+
{
73+
waveDataCounter = 0;
74+
}
75+
}
76+
77+
78+
function render() {
79+
80+
bmd.render();
81+
82+
}

examples/wip/bmd2.js

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
2+
var game = new Phaser.Game(800, 600, Phaser.AUTO, 'phaser-example', { preload: preload, create: create, update: update, render: render });
3+
4+
function preload() {
5+
6+
game.load.image('atari1', 'assets/sprites/atari130xe.png');
7+
game.load.image('coke', 'assets/sprites/cokecan.png');
8+
game.load.image('mushroom', 'assets/sprites/mushroom2.png');
9+
game.load.image('ball', 'assets/sprites/shinyball.png');
10+
11+
}
12+
13+
var bmd;
14+
15+
function create() {
16+
17+
//game.stage.backgroundColor = '#450034';
18+
19+
bmd = game.add.bitmapData('bob', 800, 600);
20+
21+
// And apply it to 100 randomly positioned sprites
22+
for (var i = 0; i < 100; i++)
23+
{
24+
bmd.setPixel(game.world.randomX, game.world.randomY, Math.random() * 255, Math.random() * 255, 255);
25+
}
26+
27+
bmd.context.fillStyle = '#ffffff';
28+
bmd.context.fillRect(20,20,16,16);
29+
30+
var d = game.add.sprite(0, 0, bmd);
31+
32+
}
33+
34+
function update() {
35+
36+
// bmd.clear();
37+
38+
// updateWobblyBall();
39+
40+
}
41+
42+
43+
function render() {
44+
45+
// bmd.render();
46+
47+
}

examples/wip/index.php

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,6 @@ function printJSLinks($dir, $files) {
7777
<meta charset="UTF-8" />
7878
<title>phaser</title>
7979
<base href="../"></base>
80-
<script src="http://cdnjs.cloudflare.com/ajax/libs/gsap/1.10.3/TweenMax.min.js"></script>
8180
<?php
8281
require('../../build/config.php');
8382

src/Phaser.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ var Phaser = Phaser || {
2929
TILEMAPLAYER: 10,
3030
EMITTER: 11,
3131
POLYGON: 12,
32+
BITMAPDATA: 13,
3233

3334
NONE: 0,
3435
LEFT: 1,

0 commit comments

Comments
 (0)