Optimised sprite a tiny bit more and created a couple of fun demos :)

This commit is contained in:
Richard Davey 2013-09-01 06:21:39 +01:00
parent fef28c6a6a
commit d54a92310d
5 changed files with 220 additions and 1207 deletions

File diff suppressed because it is too large Load diff

View file

@ -44,12 +44,6 @@
s.angle += 0.5;
s2.angle += 1;
if (s.scale.x > -2)
{
// s.scale.x -= 0.01;
// s.scale.y -= 0.01;
}
}
function render() {

55
examples/camera4.php Normal file
View file

@ -0,0 +1,55 @@
<!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, render: render });
var mummy;
function preload() {
game.load.spritesheet('mummy', 'assets/sprites/metalslug_mummy37x45.png', 37, 45, 18);
}
function create() {
mummy = game.add.sprite(0, 300, 'mummy');
mummy.scale.setTo(2, 2);
mummy.animations.add('walk');
mummy.animations.play('walk', 50, true);
game.add.tween(mummy).to({ x: game.width - 100 }, 20000, Phaser.Easing.Linear.None, true);
}
function update() {
mummy.angle += 1;
}
function render() {
game.debug.renderPoint(mummy.topLeft, 'rgb(255,0,0)');
game.debug.renderPoint(mummy.topRight, 'rgb(0,255,0)');
game.debug.renderPoint(mummy.bottomLeft, 'rgb(0,0,255)');
game.debug.renderPoint(mummy.bottomRight, 'rgb(255,0,255)');
}
})();
</script>
</body>
</html>

70
examples/camera5.php Normal file
View file

@ -0,0 +1,70 @@
<!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.AUTO, '', { preload: preload, create: create, update: update, render: render });
var core;
var core2;
function preload() {
game.load.image('bling', 'assets/sprites/diamond.png');
}
function create() {
core = game.add.sprite(game.world.centerX, game.world.centerY, 'bling');
core.anchor.setTo(0.5, 0.5);
core2 = game.add.sprite(game.world.centerX, game.world.centerY, 'bling');
core2.anchor.setTo(0.5, 0.5);
for (var i = 1; i < 50; i++)
{
var d = game.add.sprite(Math.cos(i) * 300, Math.sin(i) * 100, 'bling')
d.anchor.setTo(0.5, 0.5);
d.angle = Math.random() * 300;
core.addChild(d);
var d = game.add.sprite(Math.cos(i) * 360, Math.sin(i) * 100, 'bling')
d.anchor.setTo(0.5, 0.5);
d.angle = Math.random() * 300;
core2.addChild(d);
}
}
function update() {
core.angle += 1;
core2.angle -= 1;
for (var d in core.children) {
core.children[d].angle += 4;
}
for (var d in core2.children) {
core2.children[d].angle -= 4;
}
}
function render() {
}
})();
</script>
</body>
</html>

View file

@ -107,14 +107,19 @@ Phaser.Sprite = function (game, x, y, key, frame) {
this.worldView = new Phaser.Rectangle(x, y, this.width, this.height);
// Edge points
this.topLeft = new Phaser.Point(x, y);
this.topRight = new Phaser.Point(x + this.width, y);
this.bottomRight = new Phaser.Point(x + this.width, y + this.height);
this.bottomLeft = new Phaser.Point(x, y + this.height);
this.offset = new Phaser.Point();
this.topLeft = new Phaser.Point();
this.topRight = new Phaser.Point();
this.bottomRight = new Phaser.Point();
this.bottomLeft = new Phaser.Point();
this._dirty = true;
// Do we need all 4 edge points? It might be better to just calculate the center and apply the circle for a bounds check
this.getLocalPosition(this.topLeft, this.offset.x, this.offset.y);
this.getLocalPosition(this.topRight, this.offset.x + this.width, this.offset.y);
this.getLocalPosition(this.bottomLeft, this.offset.x, this.offset.y + this.height);
this.getLocalPosition(this.bottomRight, this.offset.x + this.width, this.offset.y + this.height);
this._dirty = false;
// transform cache
this._a00 = 0;