EC6自定义类classBrainextendsPhaser.GameObjects.Sprite{constructor(scene,x,y){super(scene,x,y);this.setTexture('大脑');this.setPosition(x,y);}preUpdate(time,delta){super.preUpdate(time,delta);this.rotation+=0.01;}}EC5自定义classvarBunny=newPhaser.Class({Extends:Phaser.GameObjects.Sprite,initialize:functionBunny(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);}});完整代码:varBunny=newPhaser.Class({Extends:Phaser.GameObjects.Sprite,initialize:functionBunny(scene,x,y,speed){Phaser.GameObjects.Sprite.call(这个,场景);this.setTexture('bunny');this.setPosition(x,y);this.setScale(0.3);this.speed=速度;},preUpdate(time,delta){this.rotation+=(0.01+this.speed*0.0001);}});varconfig={type:Phaser.AUTO,width:600,height:480,parent:'phaser-example',scene:{预加载:预加载,创建:创建}};vargame=newPhaser.Game(config);functionpreload(){//http://www.fiero.com/uploads/fiero-logo_512x512.png//this.load.image('bunny','http://www.ifero.com/images/ifero-logo_512x512.png');this.load.setBaseURL('http://labs.phaser.io');this.load.image('bg','assets/pics/purple-dots.png');this.load.image('bunny','assets/sprites/bunny.png');}functioncreate(){this.add.image(0,0,'bg').setOrigin(0).setScale(0.8);this.add.existing(newBunny(this,150,150,100));this.add.existing(newBunny(this,250,250,200));this.add.existing(newBunny(this,350,350,300));}更多游戏教学:www.iFIERO.com--为游戏开发深感自豪
