'use strict " />
效果图
对象池 object pool
scene.js
/// <reference path="../../libs/phar/phar.min.js"/> 'u strict';var bootscene = new phar.class({ extends: phar.scene, initialize: function bootscene() { phar.scene.call(this, { key: 'boot', active: true // listening resize event; }); }, init: function () { console.log('init bootscene'); this.particles = {}; }, preload: function () { this.load.image('sky', 'asts/space.jpg'); this.load.spritesheet('explode','asts/explode.png',{framewidth:128,framehe伤感短文ight:128}) }, create: function () { // this.sound.play('hitbomb'); this.background = this.add.sprite(0, 0, 'sky').torigin(0, 0); this.createexplode(); }, update:function(){ // console.log('bootscene update'); }, createexplode:function(){ //* single image; // this.add.sprite(200,200,'explode',10); this.anims.create({ key: 'explodeanimation', frames: this.anims.generateframenumbers('explode', { start: 0, end: 16, first: 0 }), framerate: 25, repeat: 0 }); //* pool group this.exploadgroup = this.add.group(); this.time.addevent({ delay: 2500, // repeat: -1, callbackscope: this, callback: this.spawnrandomexplode }); }, spawnrandomexplode:function(){ let x = phar.math.between(10, this.sys.game.config.width); let y = phar.math.between(10,this.sys.game.config.height); // this.add.sprite(x,y,'explode').tscale(0.7).play('explodeanimation'); let singleex限定语plode = this.exploadgroup.get(x,y,'explode'); //* get to pool instead of create singleexplode.tscale(0.7).play('explodeanimation'); //* play animation; singleexplode.tactive(true); singleexplode.tvisible(true); // explosion lifespan this.explosiontimeevent = this.time.addevent({ delay: 600, // delay 5s 删除 this.bo仙剑诗词mb; re免费网课平台peat: 0, callbackscope: this, callback:function(){ this.exploadgroup.killandhide(singleexplode); //* this.explosiontimeevent.remove(fal)感人爱情故事; } }); }, });
效果预览地址:http://www.ifiero.com/uploads/pharjs3/randombombeffect
更多游戏教学:http://www.ifiero.com— 为游戏开发深感自豪
本文发布于:2023-04-03 02:09:01,感谢您对本站的认可!
本文链接:https://www.wtabcd.cn/fanwen/zuowen/09c0f0874701501dab3d28d25c79160d.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文word下载地址:Phaserjs3 对象池随机产生炸弹并销毁.doc
本文 PDF 下载地址:Phaserjs3 对象池随机产生炸弹并销毁.pdf
留言与评论(共有 0 条评论) |