摘要:自定義自定義完整代碼更多游戲教學為游戲開發深感自豪
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)); }
更多游戲教學:www.iFIERO.com -- 為游戲開發深感自豪
文章版權歸作者所有,未經允許請勿轉載,若此文章存在違規行為,您可以聯系管理員刪除。
轉載請注明本文地址:http://specialneedsforspecialkids.com/yun/53389.html
摘要:自定義自定義完整代碼更多游戲教學為游戲開發深感自豪 showImg(https://segmentfault.com/img/remote/1460000017262663); EC6 自定義class class Brain extends Phaser.GameObjects.Sprite { constructor (scene, x, y) { ...
摘要:一首先當然得有至少有二個場景二從場景傳值到場景二種方法通過事件從通過時傳值到時有個需要特別注的事項就是,得把的設為否則因為還未激活,是監聽不到事件的通過場景啟動具體詳見代碼在整個工程中只會執行一次每次調用場景會執行一次從事件傳 showImg(https://segmentfault.com/img/remote/1460000016953682); 一、首先當然得有至少有二個場景sc...
摘要:一首先當然得有至少有二個場景二從場景傳值到場景二種方法通過事件從通過時傳值到時有個需要特別注的事項就是,得把的設為否則因為還未激活,是監聽不到事件的通過場景啟動具體詳見代碼在整個工程中只會執行一次每次調用場景會執行一次從事件傳 showImg(https://segmentfault.com/img/remote/1460000016953682); 一、首先當然得有至少有二個場景sc...
閱讀 2348·2021-11-15 11:37
閱讀 2625·2021-09-23 11:21
閱讀 2952·2021-09-07 10:11
閱讀 3164·2019-08-30 15:53
閱讀 2826·2019-08-29 15:13
閱讀 1606·2019-08-26 13:57
閱讀 1098·2019-08-26 12:23
閱讀 2438·2019-08-26 11:51