Phaser3 对象池随机产生炸弹并销毁
scene.js
/// <reference path="../../libs/phaser/phaser.min.js"/>
'use strict';
var BootScene = new Phaser.Class({
Extends: Phaser.Scene,
initialize: function BootScene() {
Phaser.Scene.call(this, {
key: 'Boot',
active: true // listening resize event;
});
},
init: function () {
console.log('init bootscene');
this.particles = {};
},
preload: function () {
this.load.image('sky', 'assets/space.jpg');
this.load.spritesheet('explode','assets/explode.png',{frameWidth:128,frameHeight:128})
},
create: function () {
// this.sound.play('hitbomb');
this.background = this.add.sprite(0, 0, 'sky').setOrigin(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 = Phaser.Math.Between(10, this.sys.game.config.width);
let y = Phaser.Math.Between(10,this.sys.game.config.height);
// this.add.sprite(x,y,'explode').setScale(0.7).play('explodeAnimation');
let singleExplode = this.exploadGroup.get(x,y,'explode'); //* get to pool instead of create
singleExplode.setScale(0.7).play('explodeAnimation'); //* play animation;
singleExplode.setActive(true);
singleExplode.setVisible(true);
// explosion lifespan
this.explosionTimeEvent = this.time.addEvent({
delay: 600, // delay 5s 删除 this.bomb;
repeat: 0,
callbackScope: this,
callback:function(){
this.exploadGroup.killAndHide(singleExplode);
//* this.explosionTimeEvent.remove(false);
}
});
},
});
效果预览地址:http://www.iFIERO.com/uploads/phaserjs3/RandomBombEffect
更多游戏教学:http://www.iFIERO.com -- 为游戏开发深感自豪
Phaser3 对象池随机产生炸弹并销毁的更多相关文章
- Phaserjs3 对象池随机产生炸弹并销毁 -- Html网页游戏开发
scene.js /// <reference path="../../libs/phaser/phaser.min.js"/> 'use strict'; var B ...
- cocos对象池的使用
enemy.js cc.Class({ extends: cc.Component, properties: { enemySpeed: 0, //设置加速度 }, //初始化当前节点的y坐标 ini ...
- 对象池3(方法功能)PoolManager(控制)PoolTimeObject(时间管理)text01(调用)Destorys(销毁)
1.对象池PoolManager namespace kernal { public class PoolManager : MonoBehaviour { //“缓冲池”集合 public stat ...
- JedisCluster中应用的Apache Commons Pool对象池技术
对象池技术在服务器开发上应用广泛.在各种对象池的实现中,尤其以数据库的连接池最为明显,可以说是每个服务器必须实现的部分. apache common pool 官方文档可以参考:https://c ...
- Java小对象的解决之道——对象池(Object Pool)的设计与应用
一.概述 面向对象编程是软件开发中的一项利器,现已经成为大多数编程人员的编程思路.很多高级计算机语言也对这种编程模式提供了很好的支持,例如C++.Object Pascal.Java等.曾经有大量的软 ...
- 通用对象池ObjectPool的一种简易设计和实现方案
对象池,最简单直接的作用当然是通过池来减少创建和销毁对象次数,实现对象的缓存和复用.我们熟知的线程池.数据库连接池.TCP连接池等等都是非常典型的对象池. 一个基本的简易对象池的主要功能实现我认为应该 ...
- common-pool2对象池(连接池)的介绍及使用
我们在服务器开发的过程中,往往会有一些对象,它的创建和初始化需要的时间比较长,比如数据库连接,网络IO,大数据对象等.在大量使用这些对象时,如果不采用一些技术优化,就会造成一些不可忽略的性能影响.一种 ...
- Unity3D 基于预设(Prefab)的泛型对象池实现
背景 在研究Inventory Pro插件的时候,发现老外实现的一个泛型对象池,觉得设计的小巧实用,不敢私藏,特此共享出来. 以前也看过很多博友关于对象池的总结分享,但是世界这么大,这么复杂到底什么样 ...
- Apache Commons-pool实现对象池(包括带key对象池)
Commons-pool是一个apache开源组织下的众多项目的一个.其被广泛地整合到众多需要对象池功能的项目中. 官网:http://commons.apache.org/proper/common ...
随机推荐
- DDD(领域驱动设计)总结
基本概念: 领域驱动设计(简称 ddd)概念来源于2004年著名建模专家eric evans发表的他最具影响力的书籍:<domain-driven design –tackling comple ...
- 词法分析器Lexer
词法分析 In computer science, lexical analysis, lexing or tokenization is the process of converting a se ...
- Python scrapy 常见问题及解决 【遇到的坑】
1. 爬虫出现Forbidden by robots.txt 解决方法:setting.py ROBOTSTXT_OBEY = True 改成False 原因:scrapy抓包时的输出就能发现,在请求 ...
- jquery遍历之children()与find()的区别
hildren(selector) 方法是返回匹配元素集合中每个元素的所有子元素(仅儿子辈).参数可选,添加参数表示通过选择器进行过滤,对元素进行筛选. .find(selector)方法是返回匹配元 ...
- python之路——网络基础
你现在已经学会了写python代码,假如你写了两个python文件a.py和b.py,分别去运行,你就会发现,这两个python的文件分别运行的很好.但是如果这两个程序之间想要传递一个数据,你要怎么做 ...
- POP3、SMTP端口(SSL、TSL)
POP3服务器地址: 110 995 支持SSLSMTP服务器地址: 25 465 或者 587 支持SSL(TSL) 465端口是SSL/TLS通讯协议的 ...
- [mutt] Configure mutt to receive email via IMAP and send via SMTP
“All mail clients suck. This one [mutt] just sucks less.” Michael Elkins, ca. 1995 Actually I have t ...
- switch与java
switch结构可以更好的解决等值判断问题switch 选择结构的语法:switch (表达式){case 常量 1://代码块1:break;case 常量 2://代码块2:break;..... ...
- php读取大文件如日志文件
需求如下: 现有一个1G左右的日志文件,大约有500多万行, 用php返回最后几行的内容. 1. 直接采用file函数来操作 or file_get_content() 肯定报内存溢出注: 由于 fi ...
- C++通过Callback向C#传递数据
现在比较流行C#与C++融合:C#做GUI,开发效率高,C++做运算,运行效率高,二者兼得. 但是C++与C#必然存在数据交互,C#与C++dll的数据交互从来都是一个让人头疼的问题. 从调用方式看也 ...