Testing some new Camera tricks.

This commit is contained in:
Richard Davey
2013-10-03 23:20:24 +01:00
parent c8760b4341
commit 54f073e5cb
12 changed files with 171 additions and 24 deletions
+3
View File
@@ -78,6 +78,9 @@ Version 1.0.7 (in progress in the dev branch)
* Phaser.Animation.FrameData is now Phaser.FrameData
* Phaser.Animation.Parser is now Phaser.AnimationParser (also the file has renamed from Parser.js to AnimationParser.js)
* Phaser.Loader.Parser is now Phaser.LoaderParser (also the file has renamed from Parser.js to LoaderParser.js)
* Fixed Cache.addDefaultImage so the default image works in Canvas as well as WebGL. Updated to a new image (32x32 black square with green outline)
* Extended the Loader 404 error to display the url of the file that didn't load as well as the key.
Binary file not shown.

After

Width:  |  Height:  |  Size: 253 B

+1 -1
View File
@@ -1,4 +1,4 @@
<!DOCTYPE HTML>
<!doctype html>
<html>
<head>
<meta charset="UTF-8" />
+10 -2
View File
@@ -7,7 +7,7 @@
(function () {
var game = new Phaser.Game(800, 600, Phaser.AUTO, '', { preload: preload, create: create });
var game = new Phaser.Game(800, 600, Phaser.AUTO, '', { preload: preload, create: create, update: update });
function preload() {
@@ -15,9 +15,17 @@
}
var text;
function create() {
game.add.bitmapText(200, 100, 'Phaser & Pixi\nrocking!', { font: '64px Desyrel', align: 'center' });
text = game.add.bitmapText(200, 100, 'Phaser & Pixi\nrocking!', { font: '64px Desyrel', align: 'center' });
}
function update() {
text.setText('Phaser & Pixi\nrocking!\n' + Math.round(game.time.now));
}
+111
View File
@@ -0,0 +1,111 @@
<?php
$title = "Moving around the World";
require('../head.php');
?>
<script type="text/javascript">
window.onload = function () {
var game = new Phaser.Game(800, 600, Phaser.CANVAS, '', { preload: preload, create: create, update: update, render : render });
// var game = new Phaser.Game(800, 600, Phaser.AUTO, '', { preload: preload, create: create, update: update, render: render });
function preload() {
// game.world.setSize(1920, 1200);
game.load.image('backdrop', 'assets/pics/remember-me.jpg');
game.load.image('mushroom', 'assets/sprites/mushroom.png');
game.load.image('phaser', 'assets/sprites/sonic_havok_sanity.png');
}
var cursors;
var d;
function create() {
game.add.sprite(0, 0, 'backdrop');
for (var i = 0; i < 100; i++)
{
game.add.sprite(game.world.randomX, game.world.randomY, 'mushroom');
}
d = game.add.sprite(200, 200, 'phaser');
d.anchor.setTo(0.5, 0.5);
cursors = game.input.keyboard.createCursorKeys();
console.log(game.camera.displayObject.length);
// console.log(game.camera.displayObject.children[0].name);
}
function update() {
if (cursors.up.isDown)
{
if (cursors.up.shiftKey)
{
d.angle++;
}
else
{
game.camera.y -= 4;
}
}
else if (cursors.down.isDown)
{
if (cursors.down.shiftKey)
{
d.angle--;
}
else
{
game.camera.y += 4;
}
}
if (cursors.left.isDown)
{
if (cursors.left.shiftKey)
{
game.camera.displayObject.rotation -= 0.05;
}
else
{
game.camera.x -= 4;
}
}
else if (cursors.right.isDown)
{
if (cursors.right.shiftKey)
{
game.camera.displayObject.rotation += 0.05;
}
else
{
game.camera.x += 4;
}
}
}
function render() {
game.debug.renderCameraInfo(game.camera, 32, 32);
game.debug.renderWorldTransformInfo(d, 32, 200);
game.debug.renderLocalTransformInfo(d, 32, 400);
game.debug.renderSpriteCorners(d, false, true);
}
};
</script>
<?php
require('../foot.php');
?>
+2 -1
View File
@@ -29,7 +29,8 @@ PIXI.CanvasRenderer.prototype.renderDisplayObject = function(displayObject)
continue;
}
if(!displayObject.renderable || displayObject.alpha == 0)
// if(!displayObject.renderable || displayObject.alpha == 0)
if(!displayObject.renderable)
{
displayObject = displayObject._iNext;
continue;
+8
View File
@@ -78,6 +78,8 @@ Phaser.Camera = function (game, id, x, y, width, height) {
* @default
*/
this._edge = 0;
this.displayObject = null;
};
@@ -166,6 +168,8 @@ Phaser.Camera.prototype = {
*/
update: function () {
return;
// Add dirty flag
if (this.target !== null)
@@ -216,6 +220,8 @@ Phaser.Camera.prototype = {
*/
checkWorldBounds: function () {
return;
this.atLimit.x = false;
this.atLimit.y = false;
@@ -293,6 +299,7 @@ Object.defineProperty(Phaser.Camera.prototype, "x", {
set: function (value) {
this.view.x = value;
this.displayObject.x = -value;
this.checkWorldBounds();
}
@@ -311,6 +318,7 @@ Object.defineProperty(Phaser.Camera.prototype, "y", {
set: function (value) {
this.view.y = value;
this.displayObject.y = -value;
this.checkWorldBounds();
}
+4 -3
View File
@@ -54,12 +54,13 @@ Phaser.World.prototype = {
*/
boot: function () {
this.group = new Phaser.Group(this.game, null, '__world', false);
this.camera = new Phaser.Camera(this.game, 0, 0, 0, this.game.width, this.game.height);
this.camera.displayObject = this.group;
this.game.camera = this.camera;
this.group = new Phaser.Group(this.game, null, '__world', true);
},
/**
@@ -77,7 +78,7 @@ Phaser.World.prototype = {
{
var currentNode = this.game.stage._stage.first._iNext;
do
do
{
if (currentNode['preUpdate'])
{
+8 -8
View File
@@ -419,16 +419,16 @@ Phaser.Sprite.prototype.postUpdate = function() {
if (this.exists)
{
// The sprite is positioned in this call, after taking into consideration motion updates and collision
this.body.postUpdate();
// this.body.postUpdate();
this._cache.x = this.x - (this.game.world.camera.x * this.scrollFactor.x);
this._cache.y = this.y - (this.game.world.camera.y * this.scrollFactor.y);
// this._cache.x = this.x - (this.game.world.camera.x * this.scrollFactor.x);
// this._cache.y = this.y - (this.game.world.camera.y * this.scrollFactor.y);
if (this.position.x != this._cache.x || this.position.y != this._cache.y)
{
this.position.x = this._cache.x;
this.position.y = this._cache.y;
}
// if (this.position.x != this._cache.x || this.position.y != this._cache.y)
// {
// this.position.x = this._cache.x;
// this.position.y = this._cache.y;
// }
}
}
+17
View File
@@ -123,6 +123,23 @@ Phaser.Keyboard.prototype = {
},
/**
* Creates and returns an object containing 4 hotkeys for Up, Down, Left and Right.
*
* @method Phaser.Keyboard#createCursorKeys
* @return {object} An object containing properties: up, down, left and right. Which can be polled like any other Phaser.Key object.
*/
createCursorKeys: function () {
return {
up: this.addKey(Phaser.Keyboard.UP),
down: this.addKey(Phaser.Keyboard.DOWN),
left: this.addKey(Phaser.Keyboard.LEFT),
right: this.addKey(Phaser.Keyboard.RIGHT)
}
},
/**
* Starts the Keyboard event listeners running (keydown and keyup). They are attached to the document.body.
* This is called automatically by Phaser.Input and should not normally be invoked directly.
+6 -8
View File
@@ -197,16 +197,14 @@ Phaser.Cache.prototype = {
*/
addDefaultImage: function () {
this._images['__default'] = { url: null, data: null, spriteSheet: false };
var img = new Image();
img.src = "data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAACAAAAAgCAIAAAD8GO2jAAAAGXRFWHRTb2Z0d2FyZQBBZG9iZSBJbWFnZVJlYWR5ccllPAAAAJ9JREFUeNq01ssOwyAMRFG46v//Mt1ESmgh+DFmE2GPOBARKb2NVjo+17PXLD8a1+pl5+A+wSgFygymWYHBb0FtsKhJDdZlncG2IzJ4ayoMDv20wTmSMzClEgbWYNTAkQ0Z+OJ+A/eWnAaR9+oxCF4Os0H8htsMUp+pwcgBBiMNnAwF8GqIgL2hAzaGFFgZauDPKABmowZ4GL369/0rwACp2yA/ttmvsQAAAABJRU5ErkJggg==";
this._images['__default'] = { url: null, data: img, spriteSheet: false };
this._images['__default'].frame = new Phaser.Frame(0, 0, 0, 32, 32, '', '');
var base = new PIXI.BaseTexture();
base.width = 32;
base.height = 32;
base.hasLoaded = true; // avoids a hanging event listener
PIXI.BaseTextureCache['__default'] = base;
PIXI.TextureCache['__default'] = new PIXI.Texture(base);
PIXI.BaseTextureCache['__default'] = new PIXI.BaseTexture(img);
PIXI.TextureCache['__default'] = new PIXI.Texture(PIXI.BaseTextureCache['__default']);
},
+1 -1
View File
@@ -733,7 +733,7 @@ Phaser.Loader.prototype = {
this.onFileError.dispatch(key);
console.warn("Phaser.Loader error loading file: " + key);
console.warn("Phaser.Loader error loading file: " + key + ' from URL ' + this._fileList[key].url);
this.nextFile(key, false);