
















custom class
EC6 自定义class
class Brain extends Phaser.GameObjects.Sprite {
constructor (scene, x, y)
{
super(scene, x, y);
this.setTexture('brain');
this.setPosition(x, y);
}
preUpdate (time, delta)
{
super.preUpdate(time, delta);
this.rotation += 0.01;
}
}
EC5 自定义class
var Bunny = new Phaser.Class({
Extends:Phaser.GameObjects.Sprite,
initialize:function Bunny(scene,x,y,speed){
Phaser.GameObjects.Sprite.call(this,scene);
this.setTexture('bunny');
this.setPosition(x, y);
this.setScale(0.3);
this.speed = speed;
},
preUpdate(time,delta){
this.rotation += (0.01+ this.speed * 0.0001) ;
}
});
完整代码:
var Bunny = new Phaser.Class({
Extends:Phaser.GameObjects.Sprite,
initialize:function Bunny(scene,x,y,speed){
Phaser.GameObjects.Sprite.call(this,scene);
this.setTexture('bunny');
this.setPosition(x, y);
this.setScale(0.3);
this.speed = speed;
},
preUpdate(time,delta){
this.rotation += (0.01+ this.speed * 0.0001) ;
}
});
var config = {
type: Phaser.AUTO,
width: 600,
height: 480,
parent: 'phaser-example',
scene: {
preload: preload,
create: create
}
};
var game = new Phaser.Game(config);
function preload (){
更多游戏教学:www.iFIERO.com -- 为游戏开发深感自豪
此内容由惯性聚合(RSS阅读器)自动聚合整理,仅供阅读参考。 原文来自 — 版权归原作者所有。