mirror of
https://github.com/wassname/phaser.git
synced 2026-07-17 11:31:30 +08:00
Making some major changes to Camera and World.
This commit is contained in:
@@ -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');
|
||||
?>
|
||||
@@ -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);
|
||||
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user