Skip to content

Commit 3fe4e31

Browse files
committedNov 10, 2017
📦 使用yarn
1 parent f7d39ba commit 3fe4e31

File tree

5 files changed

+35
-1
lines changed

5 files changed

+35
-1
lines changed
 

‎assets/Script/Game/common.js

+12
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
// const _ = require('lodash');
2+
13
cc.Class({
24
extends: cc.Component,
35

@@ -8,6 +10,7 @@ cc.Class({
810
// use this for initialization
911
onLoad: function () {
1012
D.common = this;
13+
D.commonState.poolObj = {};
1114
},
1215
// 批处理对象池
1316
batchInitNodePool: function (that, objArray) {
@@ -21,6 +24,8 @@ cc.Class({
2124
let name = objInfo.name;
2225
let poolName = name + 'Pool';
2326
that[poolName] = new cc.NodePool();
27+
// 在commonState中备份,方便clear
28+
D.commonState.poolObj[poolName] = that[poolName];
2429
// 创建对象,并放入池中
2530
for (let i = 0; i < objInfo.poolAmount; i++) {
2631
let newNode = cc.instantiate(objInfo.prefab);
@@ -44,6 +49,13 @@ cc.Class({
4449
putBackPool: function (that, node) {
4550
let poolName = node.name + "Pool";
4651
that[poolName].put(node);
52+
},
53+
54+
// 清空缓冲池
55+
clearAllPool: function () {
56+
_.forEach(D.commonState.poolObj, function (pool) {
57+
pool.clear();
58+
})
4759
}
4860

4961
// called every frame, uncomment this function to activate update callback

‎assets/Script/Game/global.js

+3-1
Original file line numberDiff line numberDiff line change
@@ -3,4 +3,6 @@ window.D = {
33
// singletons
44
common: null, //公共方法
55
commonState: {}, //定义的一些常量
6-
};
6+
};
7+
8+
window._ = require('lodash');

‎assets/Script/Game/main.js

+1
Original file line numberDiff line numberDiff line change
@@ -106,6 +106,7 @@ cc.Class({
106106
},
107107
// 游戏结束
108108
gameOver: function () {
109+
D.common.clearAllPool();
109110
cc.audioEngine.play(this.gameOverSound);
110111
cc.director.loadScene('End');
111112
},

‎package.json

+12
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
{
2+
"name": "aircraft-war",
3+
"version": "1.0.0",
4+
"description": "cocos creator game aircraft war",
5+
"main": "index.js",
6+
"repository": "https://github.com/Here21/aircraft-war",
7+
"author": "Martin",
8+
"license": "MIT",
9+
"dependencies": {
10+
"lodash": "^4.17.4"
11+
}
12+
}

‎yarn.lock

+7
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
# THIS IS AN AUTOGENERATED FILE. DO NOT EDIT THIS FILE DIRECTLY.
2+
# yarn lockfile v1
3+
4+
5+
lodash@^4.17.4:
6+
version "4.17.4"
7+
resolved "https://registry.yarnpkg.com/lodash/-/lodash-4.17.4.tgz#78203a4d1c328ae1d86dca6460e369b57f4055ae"

0 commit comments

Comments
 (0)
Please sign in to comment.