You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 

35 lines
508 B

  1. define([
  2. ], function (
  3. ) {
  4. return {
  5. pool: {},
  6. clean: function () {
  7. this.pool = {};
  8. },
  9. getSprite: function (type) {
  10. let list = this.pool[type];
  11. if (!list)
  12. return null;
  13. else if (list.length == 0)
  14. return null;
  15. return list.pop();
  16. },
  17. store: function (sprite) {
  18. let pool = this.pool;
  19. let type = sprite.type;
  20. if (sprite.scale.x < 0)
  21. type = 'flip' + type;
  22. let list = pool[type];
  23. if (!list)
  24. list = pool[type] = [];
  25. list.push(sprite);
  26. }
  27. };
  28. });