mirror of
https://github.com/photonstorm/phaser
synced 2024-11-27 23:20:59 +00:00
60 lines
1.2 KiB
PHP
60 lines
1.2 KiB
PHP
|
<?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');
|
||
|
?>
|