主页 > canvas引擎 > Phaser游戏引擎 >
来源:未知 时间:2021-06-16 22:25 作者:小飞侠 阅读:次
[导读] 场景A调用场景B方法 varSceneA=newPhaser.Class({Extends:Phaser.Scene,initialize:functionSceneA(){Phaser.Scene.call(this,{key:sceneA});},create:function(){varsceneB=this.scene.get(sceneB);//获得场景Bthis.input.on(pointerup,function...
场景A调用场景B方法 var SceneA = new Phaser.Class({ Extends: Phaser.Scene, initialize: function SceneA () { Phaser.Scene.call(this, { key: 'sceneA' }); }, create: function () { var sceneB = this.scene.get('sceneB'); // 获得场景B this.input.on('pointerup', function () { var x = Phaser.Math.Between(0, 800); var y = Phaser.Math.Between(0, 600); var frame = sceneB.getImage(); // 此处获得场景B方法 this.add.image(x, y, frame); }, this); this.add.text(10, 10, 'Click to get image', { font: '16px Courier', fill: '#00ff00' }).setDepth(1000); } }); var SceneB = new Phaser.Class({ Extends: Phaser.Scene, initialize: function SceneB () { // 注册并且自动执行 Phaser.Scene.call(this, { key: 'sceneB', active: true }); this.frames; }, preload: function () { this.load.setPath('assets/sprites/'); this.load.image('amiga-cursor'); this.load.image('aqua_ball'); this.load.image('asuna_by_vali233'); this.load.image('atari130xe'); this.load.image('atari400'); }, create: function () { this.frames = [ 'amiga-cursor', 'aqua_ball', 'asuna_by_vali233', 'atari130xe', 'atari400' ]; }, getImage: function () { return Phaser.Math.RND.pick(this.frames); } }); var config = { type: Phaser.AUTO, width: 800, height: 600, backgroundColor: '#2d2d2d', parent: 'phaser-example', scene: [ SceneA, SceneB ] }; var game = new Phaser.Game(config); |
自学PHP网专注网站建设学习,PHP程序学习,平面设计学习,以及操作系统学习
京ICP备14009008号-1@版权所有www.zixuephp.com
网站声明:本站所有视频,教程都由网友上传,站长收集和分享给大家学习使用,如由牵扯版权问题请联系站长邮箱904561283@qq.com