摘要:自定義自定義完整代碼更多游戲教學(xué)為游戲開(kāi)發(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 -- 為游戲開(kāi)發(fā)深感自豪
文章版權(quán)歸作者所有,未經(jīng)允許請(qǐng)勿轉(zhuǎn)載,若此文章存在違規(guī)行為,您可以聯(lián)系管理員刪除。
轉(zhuǎn)載請(qǐng)注明本文地址:http://systransis.cn/yun/53389.html
摘要:自定義自定義完整代碼更多游戲教學(xué)為游戲開(kāi)發(fā)深感自豪 showImg(https://segmentfault.com/img/remote/1460000017262663); EC6 自定義class class Brain extends Phaser.GameObjects.Sprite { constructor (scene, x, y) { ...
摘要:一首先當(dāng)然得有至少有二個(gè)場(chǎng)景二從場(chǎng)景傳值到場(chǎng)景二種方法通過(guò)事件從通過(guò)時(shí)傳值到時(shí)有個(gè)需要特別注的事項(xiàng)就是,得把的設(shè)為否則因?yàn)檫€未激活,是監(jiān)聽(tīng)不到事件的通過(guò)場(chǎng)景啟動(dòng)具體詳見(jiàn)代碼在整個(gè)工程中只會(huì)執(zhí)行一次每次調(diào)用場(chǎng)景會(huì)執(zhí)行一次從事件傳 showImg(https://segmentfault.com/img/remote/1460000016953682); 一、首先當(dāng)然得有至少有二個(gè)場(chǎng)景sc...
摘要:一首先當(dāng)然得有至少有二個(gè)場(chǎng)景二從場(chǎng)景傳值到場(chǎng)景二種方法通過(guò)事件從通過(guò)時(shí)傳值到時(shí)有個(gè)需要特別注的事項(xiàng)就是,得把的設(shè)為否則因?yàn)檫€未激活,是監(jiān)聽(tīng)不到事件的通過(guò)場(chǎng)景啟動(dòng)具體詳見(jiàn)代碼在整個(gè)工程中只會(huì)執(zhí)行一次每次調(diào)用場(chǎng)景會(huì)執(zhí)行一次從事件傳 showImg(https://segmentfault.com/img/remote/1460000016953682); 一、首先當(dāng)然得有至少有二個(gè)場(chǎng)景sc...
閱讀 2386·2021-11-15 11:37
閱讀 2638·2021-09-23 11:21
閱讀 2967·2021-09-07 10:11
閱讀 3175·2019-08-30 15:53
閱讀 2835·2019-08-29 15:13
閱讀 1618·2019-08-26 13:57
閱讀 1112·2019-08-26 12:23
閱讀 2451·2019-08-26 11:51