摘要:自定義自定義完整代碼更多游戲教學(xué)為游戲開發(fā)深感自豪
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 (){ //http://www.ifiero.com/uploads/ifiero-logo_512x512.png // this.load.image("bunny", "http://www.ifiero.com/images/ifiero-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"); } function create (){ this.add.image(0, 0, "bg").setOrigin(0).setScale(0.8); this.add.existing(new Bunny(this, 150, 150,100)); this.add.existing(new Bunny(this, 250, 250,200)); this.add.existing(new Bunny(this, 350, 350,300)); }
更多游戲教學(xué):www.iFIERO.com -- 為游戲開發(fā)深感自豪
文章版權(quán)歸作者所有,未經(jīng)允許請勿轉(zhuǎn)載,若此文章存在違規(guī)行為,您可以聯(lián)系管理員刪除。
轉(zhuǎn)載請注明本文地址:http://systransis.cn/yun/99749.html
摘要:自定義自定義完整代碼更多游戲教學(xué)為游戲開發(fā)深感自豪 showImg(https://segmentfault.com/img/remote/1460000017262663); EC6 自定義class class Brain extends Phaser.GameObjects.Sprite { constructor (scene, x, y) { ...
摘要:一首先當(dāng)然得有至少有二個場景二從場景傳值到場景二種方法通過事件從通過時傳值到時有個需要特別注的事項就是,得把的設(shè)為否則因為還未激活,是監(jiān)聽不到事件的通過場景啟動具體詳見代碼在整個工程中只會執(zhí)行一次每次調(diào)用場景會執(zhí)行一次從事件傳 showImg(https://segmentfault.com/img/remote/1460000016953682); 一、首先當(dāng)然得有至少有二個場景sc...
摘要:一首先當(dāng)然得有至少有二個場景二從場景傳值到場景二種方法通過事件從通過時傳值到時有個需要特別注的事項就是,得把的設(shè)為否則因為還未激活,是監(jiān)聽不到事件的通過場景啟動具體詳見代碼在整個工程中只會執(zhí)行一次每次調(diào)用場景會執(zhí)行一次從事件傳 showImg(https://segmentfault.com/img/remote/1460000016953682); 一、首先當(dāng)然得有至少有二個場景sc...
閱讀 3171·2021-11-19 09:40
閱讀 3663·2021-11-16 11:52
閱讀 2988·2021-11-11 16:55
閱讀 3186·2019-08-30 15:55
閱讀 1191·2019-08-30 13:08
閱讀 1663·2019-08-29 17:03
閱讀 3020·2019-08-29 16:19
閱讀 2587·2019-08-29 13:43