Making some major changes to Camera and World.

This commit is contained in:
Richard Davey
2013-10-04 14:41:15 +01:00
parent 54f073e5cb
commit e8bed83ac3
12 changed files with 235 additions and 536 deletions
+60
View File
@@ -0,0 +1,60 @@
<?php
$title = "Custom Sprite";
require('../head.php');
?>
<script type="text/javascript">
MonsterBunny = function (game, rotateSpeed) {
// We call the Phaser.Sprite passing in the game reference
// We're giving it a random X/Y position here, just for the sake of this demo - you could also pass the x/y in the constructor
Phaser.Sprite.call(this, game, game.world.randomX, game.world.randomY, 'bunny');
this.anchor.setTo(0.5, 0.5);
this.rotateSpeed = rotateSpeed;
var randomScale = 0.1 + Math.random();
this.scale.setTo(randomScale, randomScale)
game.add.existing(this);
};
MonsterBunny.prototype = Object.create(Phaser.Sprite.prototype);
MonsterBunny.prototype.constructor = MonsterBunny;
MonsterBunny.prototype.update = function() {
// Automatically called by World.update
this.angle += this.rotateSpeed;
};
(function () {
var game = new Phaser.Game(800, 600, Phaser.AUTO, '', { preload: preload, create: create });
function preload() {
game.load.image('bunny', 'assets/sprites/bunny.png');
}
function create() {
for (var i = 0.1; i < 2; i += 0.1)
{
new MonsterBunny(game, i);
}
}
})();
</script>
<?php
require('../foot.php');
?>
+10 -5
View File
@@ -6,13 +6,15 @@
<script type="text/javascript">
// Here is a custom game object
MonsterBunny = function (game, x, y) {
MonsterBunny = function (game, x, y, rotateSpeed) {
Phaser.Sprite.call(this, game, x, y, 'bunny');
this.rotateSpeed = rotateSpeed;
};
MonsterBunny.prototype = Phaser.Utils.extend(true, Phaser.Sprite.prototype, PIXI.Sprite.prototype);
MonsterBunny.prototype = Object.create(Phaser.Sprite.prototype);
MonsterBunny.prototype.constructor = MonsterBunny;
/**
@@ -20,7 +22,7 @@ MonsterBunny.prototype.constructor = MonsterBunny;
*/
MonsterBunny.prototype.update = function() {
this.angle++;
this.angle += this.rotateSpeed;
};
@@ -36,11 +38,14 @@ MonsterBunny.prototype.update = function() {
function create() {
var wabbit = new MonsterBunny(game, 400, 300);
wabbit.lifespan = 3000;
var wabbit = new MonsterBunny(game, 200, 300, 1);
wabbit.anchor.setTo(0.5, 0.5);
var wabbit2 = new MonsterBunny(game, 600, 300, 0.5);
wabbit2.anchor.setTo(0.5, 0.5);
game.add.existing(wabbit);
game.add.existing(wabbit2);
}