Commit 3fe4e31 1 parent f7d39ba commit 3fe4e31 Copy full SHA for 3fe4e31
File tree 5 files changed +35
-1
lines changed
5 files changed +35
-1
lines changed Original file line number Diff line number Diff line change
1
+ // const _ = require('lodash');
2
+
1
3
cc . Class ( {
2
4
extends : cc . Component ,
3
5
@@ -8,6 +10,7 @@ cc.Class({
8
10
// use this for initialization
9
11
onLoad : function ( ) {
10
12
D . common = this ;
13
+ D . commonState . poolObj = { } ;
11
14
} ,
12
15
// 批处理对象池
13
16
batchInitNodePool : function ( that , objArray ) {
@@ -21,6 +24,8 @@ cc.Class({
21
24
let name = objInfo . name ;
22
25
let poolName = name + 'Pool' ;
23
26
that [ poolName ] = new cc . NodePool ( ) ;
27
+ // 在commonState中备份,方便clear
28
+ D . commonState . poolObj [ poolName ] = that [ poolName ] ;
24
29
// 创建对象,并放入池中
25
30
for ( let i = 0 ; i < objInfo . poolAmount ; i ++ ) {
26
31
let newNode = cc . instantiate ( objInfo . prefab ) ;
@@ -44,6 +49,13 @@ cc.Class({
44
49
putBackPool : function ( that , node ) {
45
50
let poolName = node . name + "Pool" ;
46
51
that [ poolName ] . put ( node ) ;
52
+ } ,
53
+
54
+ // 清空缓冲池
55
+ clearAllPool : function ( ) {
56
+ _ . forEach ( D . commonState . poolObj , function ( pool ) {
57
+ pool . clear ( ) ;
58
+ } )
47
59
}
48
60
49
61
// called every frame, uncomment this function to activate update callback
Original file line number Diff line number Diff line change @@ -3,4 +3,6 @@ window.D = {
3
3
// singletons
4
4
common : null , //公共方法
5
5
commonState : { } , //定义的一些常量
6
- } ;
6
+ } ;
7
+
8
+ window . _ = require ( 'lodash' ) ;
Original file line number Diff line number Diff line change @@ -106,6 +106,7 @@ cc.Class({
106
106
} ,
107
107
// 游戏结束
108
108
gameOver : function ( ) {
109
+ D . common . clearAllPool ( ) ;
109
110
cc . audioEngine . play ( this . gameOverSound ) ;
110
111
cc . director . loadScene ( 'End' ) ;
111
112
} ,
Original file line number Diff line number Diff line change
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
+ }
Original file line number Diff line number Diff line change
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"
You can’t perform that action at this time.
0 commit comments