Commit df10e635 authored by 邱旭's avatar 邱旭

10.FlppyBird-创建障碍

parent 38d1a0d6
...@@ -184,3 +184,27 @@ function loadImgAsync(src) { ...@@ -184,3 +184,27 @@ function loadImgAsync(src) {
img.src = src; img.src = src;
}); });
} }
/**
* 一个简单的通用对象池
*/
class ObjectPool {
static objs = {};
static put(name, obj) {
const pool = ObjectPool.objs[name] || (ObjectPool.objs[name] = []);
pool.push(obj);
}
static get(name) {
const pool = ObjectPool.objs[name] || (ObjectPool.objs[name] = []);
if (pool.length <= 0) {
return null;
}
return pool.shift();
}
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment