mirror of
https://github.com/photonstorm/phaser
synced 2024-11-10 07:04:31 +00:00
Sprite Sheets now parse and render correctly too.
This commit is contained in:
parent
1e59bc69fb
commit
a81a8effb4
11 changed files with 92 additions and 31 deletions
BIN
Docs/WIP/01_phaser-arcade.jpg
Normal file
BIN
Docs/WIP/01_phaser-arcade.jpg
Normal file
Binary file not shown.
After Width: | Height: | Size: 243 KiB |
BIN
Docs/WIP/02_phaser-newsletter.jpg
Normal file
BIN
Docs/WIP/02_phaser-newsletter.jpg
Normal file
Binary file not shown.
After Width: | Height: | Size: 210 KiB |
BIN
Docs/WIP/phaser-manual_2013-08-27.pdf
Normal file
BIN
Docs/WIP/phaser-manual_2013-08-27.pdf
Normal file
Binary file not shown.
BIN
Docs/WIP/phaser_onscreen-controls_1-arcade.png
Normal file
BIN
Docs/WIP/phaser_onscreen-controls_1-arcade.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 1,021 KiB |
BIN
Docs/WIP/phaser_onscreen-controls_2-dpad.png
Normal file
BIN
Docs/WIP/phaser_onscreen-controls_2-dpad.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 1,010 KiB |
BIN
Docs/WIP/phaser_onscreen-controls_3-generic.png
Normal file
BIN
Docs/WIP/phaser_onscreen-controls_3-generic.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 1,022 KiB |
|
@ -22,33 +22,12 @@
|
|||
|
||||
function create() {
|
||||
|
||||
//var texture = PIXI.TextureCache['skully.png'];
|
||||
|
||||
// PIXI.BaseTextureCache['monsters'] = new PIXI.BaseTexture(game.cache.getImage('monsters'));
|
||||
|
||||
// every image loaded should go into the BaseTextureCache, unique by URL (or maybe key)
|
||||
// var base = new PIXI.BaseTexture(game.cache.getImage('monsters'));
|
||||
|
||||
// Every FRAME needs a PIXI.Texture, related to the base (the source image) and the frame data
|
||||
// var texture = new PIXI.Texture(base, { x: 0, y: 0, width: 100, height: 100 });
|
||||
// var texture2 = new PIXI.Texture(base, { x: 0, y: 0, width: 100, height: 300 });
|
||||
|
||||
// PIXI.Sprite.fromFrame(key) pulls the texture from the TextureCache and returns a new Sprite made from it...
|
||||
// var texture = PIXI.TextureCache[frameId];
|
||||
|
||||
|
||||
// console.log(PIXI.TextureCache);
|
||||
|
||||
// console.log(game.cache.getFrameData('monsters'));
|
||||
|
||||
// This is created by the very act of loading a texture atlas in
|
||||
frameData = game.cache.getFrameData('monsters');
|
||||
|
||||
// bunny = new PIXI.Sprite(texture2);
|
||||
|
||||
// Both of these work - they look fugly I know, but they'll be hidden behind a Phaser Sprite anyway
|
||||
bunny = PIXI.Sprite.fromFrame(frameData.getFrame(0).uuid);
|
||||
// bunny = PIXI.Sprite.fromFrame(frameData.getFrameByName('skully.png').uuid);
|
||||
|
||||
// bunny = PIXI.Sprite.fromImage('monsters');
|
||||
|
||||
bunny.anchor.x = 0.5;
|
||||
bunny.anchor.y = 0.5;
|
||||
|
@ -74,7 +53,7 @@
|
|||
|
||||
bunny.setTexture(PIXI.TextureCache[frameData.getFrame(f).uuid]);
|
||||
|
||||
n = game.time.now + 1000;
|
||||
n = game.time.now + 500;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
68
examples/stage 3.php
Normal file
68
examples/stage 3.php
Normal file
|
@ -0,0 +1,68 @@
|
|||
<!DOCTYPE HTML>
|
||||
<html>
|
||||
<head>
|
||||
<title>phaser.js - a new beginning</title>
|
||||
<?php
|
||||
require('js.php');
|
||||
?>
|
||||
</head>
|
||||
<body>
|
||||
|
||||
<script type="text/javascript">
|
||||
|
||||
(function () {
|
||||
|
||||
var game = new Phaser.Game(800, 600, Phaser.CANVAS, '', { preload: preload, create: create, update: update }, false, false);
|
||||
|
||||
var bunny;
|
||||
|
||||
function preload() {
|
||||
game.load.spritesheet('metalslug', 'assets/sprites/metalslug_monster39x40.png', 39, 40);
|
||||
}
|
||||
|
||||
function create() {
|
||||
|
||||
// This is created by the very act of loading a sprite sheet in
|
||||
frameData = game.cache.getFrameData('metalslug');
|
||||
|
||||
// Both of these work - they look fugly I know, but they'll be hidden behind a Phaser Sprite anyway
|
||||
bunny = PIXI.Sprite.fromFrame(frameData.getFrame(0).uuid);
|
||||
|
||||
bunny.anchor.x = 0.5;
|
||||
bunny.anchor.y = 0.5;
|
||||
|
||||
bunny.scale.x = 6;
|
||||
bunny.scale.y = 6;
|
||||
|
||||
bunny.position.x = game.world.centerX;
|
||||
bunny.position.y = game.world.centerY;
|
||||
|
||||
game.world.add(bunny);
|
||||
|
||||
n = game.time.now + 20;
|
||||
|
||||
}
|
||||
|
||||
var frameData;
|
||||
var f = 0;
|
||||
var n = 0;
|
||||
|
||||
function update() {
|
||||
|
||||
if (game.time.now > n)
|
||||
{
|
||||
f = game.math.wrapValue(f, 1, frameData.total);
|
||||
|
||||
bunny.setTexture(PIXI.TextureCache[frameData.getFrame(f).uuid]);
|
||||
|
||||
n = game.time.now + 40;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
})();
|
||||
|
||||
</script>
|
||||
|
||||
</body>
|
||||
</html>
|
|
@ -48,13 +48,23 @@ Phaser.Animation.Parser = {
|
|||
var x = 0;
|
||||
var y = 0;
|
||||
|
||||
for (var i = 0; i < total; i++) {
|
||||
for (var i = 0; i < total; i++)
|
||||
{
|
||||
var uuid = game.rnd.uuid();
|
||||
|
||||
data.addFrame(new Phaser.Animation.Frame(x, y, frameWidth, frameHeight, ''));
|
||||
data.addFrame(new Phaser.Animation.Frame(x, y, frameWidth, frameHeight, '', uuid));
|
||||
|
||||
PIXI.TextureCache[uuid] = new PIXI.Texture(PIXI.BaseTextureCache[key], {
|
||||
x: x,
|
||||
y: y,
|
||||
width: frameWidth,
|
||||
height: frameHeight
|
||||
});
|
||||
|
||||
x += frameWidth;
|
||||
|
||||
if (x === width) {
|
||||
if (x === width)
|
||||
{
|
||||
x = 0;
|
||||
y += frameHeight;
|
||||
}
|
||||
|
|
|
@ -69,10 +69,11 @@ Phaser.Cache.prototype = {
|
|||
addSpriteSheet: function (key, url, data, frameWidth, frameHeight, frameMax) {
|
||||
|
||||
this._images[key] = { url: url, data: data, spriteSheet: true, frameWidth: frameWidth, frameHeight: frameHeight };
|
||||
this._images[key].frameData = Phaser.Animation.Parser.spriteSheet(this.game, key, frameWidth, frameHeight, frameMax);
|
||||
|
||||
PIXI.BaseTextureCache[key] = new PIXI.BaseTexture(data);
|
||||
|
||||
this._images[key].frameData = Phaser.Animation.Parser.spriteSheet(this.game, key, frameWidth, frameHeight, frameMax);
|
||||
|
||||
},
|
||||
|
||||
/**
|
||||
|
|
|
@ -177,7 +177,8 @@ Phaser.Loader.prototype = {
|
|||
|
||||
if (typeof overwrite === "undefined") { overwrite = false; }
|
||||
|
||||
if (overwrite || this.checkKeyExists(key) == false) {
|
||||
if (overwrite || this.checkKeyExists(key) == false)
|
||||
{
|
||||
this.addToFileList('text', key, url);
|
||||
}
|
||||
|
||||
|
@ -195,7 +196,8 @@ Phaser.Loader.prototype = {
|
|||
|
||||
if (typeof frameMax === "undefined") { frameMax = -1; }
|
||||
|
||||
if (this.checkKeyExists(key) === false) {
|
||||
if (this.checkKeyExists(key) === false)
|
||||
{
|
||||
this.addToFileList('spritesheet', key, url, { frameWidth: frameWidth, frameHeight: frameHeight, frameMax: frameMax });
|
||||
}
|
||||
|
||||
|
@ -211,7 +213,8 @@ Phaser.Loader.prototype = {
|
|||
|
||||
if (typeof autoDecode === "undefined") { autoDecode = true; }
|
||||
|
||||
if (this.checkKeyExists(key) === false) {
|
||||
if (this.checkKeyExists(key) === false)
|
||||
{
|
||||
this.addToFileList('audio', key, urls, { buffer: null, autoDecode: autoDecode });
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue