Skip to content

Commit

Permalink
📦 使用yarn
Browse files Browse the repository at this point in the history
  • Loading branch information
Here21 committed Nov 10, 2017
1 parent f7d39ba commit 3fe4e31
Show file tree
Hide file tree
Showing 5 changed files with 35 additions and 1 deletion.
12 changes: 12 additions & 0 deletions assets/Script/Game/common.js
@@ -1,3 +1,5 @@
// const _ = require('lodash');

cc.Class({
extends: cc.Component,

Expand All @@ -8,6 +10,7 @@ cc.Class({
// use this for initialization
onLoad: function () {
D.common = this;
D.commonState.poolObj = {};
},
// 批处理对象池
batchInitNodePool: function (that, objArray) {
Expand All @@ -21,6 +24,8 @@ cc.Class({
let name = objInfo.name;
let poolName = name + 'Pool';
that[poolName] = new cc.NodePool();
// 在commonState中备份,方便clear
D.commonState.poolObj[poolName] = that[poolName];
// 创建对象,并放入池中
for (let i = 0; i < objInfo.poolAmount; i++) {
let newNode = cc.instantiate(objInfo.prefab);
Expand All @@ -44,6 +49,13 @@ cc.Class({
putBackPool: function (that, node) {
let poolName = node.name + "Pool";
that[poolName].put(node);
},

// 清空缓冲池
clearAllPool: function () {
_.forEach(D.commonState.poolObj, function (pool) {
pool.clear();
})
}

// called every frame, uncomment this function to activate update callback
Expand Down
4 changes: 3 additions & 1 deletion assets/Script/Game/global.js
Expand Up @@ -3,4 +3,6 @@ window.D = {
// singletons
common: null, //公共方法
commonState: {}, //定义的一些常量
};
};

window._ = require('lodash');
1 change: 1 addition & 0 deletions assets/Script/Game/main.js
Expand Up @@ -106,6 +106,7 @@ cc.Class({
},
// 游戏结束
gameOver: function () {
D.common.clearAllPool();
cc.audioEngine.play(this.gameOverSound);
cc.director.loadScene('End');
},
Expand Down
12 changes: 12 additions & 0 deletions package.json
@@ -0,0 +1,12 @@
{
"name": "aircraft-war",
"version": "1.0.0",
"description": "cocos creator game aircraft war",
"main": "index.js",
"repository": "https://github.com/Here21/aircraft-war",
"author": "Martin",
"license": "MIT",
"dependencies": {
"lodash": "^4.17.4"
}
}
7 changes: 7 additions & 0 deletions yarn.lock
@@ -0,0 +1,7 @@
# THIS IS AN AUTOGENERATED FILE. DO NOT EDIT THIS FILE DIRECTLY.
# yarn lockfile v1


lodash@^4.17.4:
version "4.17.4"
resolved "https://registry.yarnpkg.com/lodash/-/lodash-4.17.4.tgz#78203a4d1c328ae1d86dca6460e369b57f4055ae"

0 comments on commit 3fe4e31

Please sign in to comment.