摘要:自定义自定义完整代码更多游戏教学为游戏开发深感自豪
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 -- 为游戏开发深感自豪
文章版权归作者所有,未经允许请勿转载,若此文章存在违规行为,您可以联系管理员删除。
转载请注明本文地址:https://www.ucloud.cn/yun/99749.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...
阅读 3290·2021-11-19 09:40
阅读 3720·2021-11-16 11:52
阅读 3054·2021-11-11 16:55
阅读 3265·2019-08-30 15:55
阅读 1264·2019-08-30 13:08
阅读 1738·2019-08-29 17:03
阅读 3104·2019-08-29 16:19
阅读 2662·2019-08-29 13:43