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.
 
 
 

72 lines
1.2 KiB

  1. define([
  2. 'js/system/events'
  3. ], function (
  4. events
  5. ) {
  6. var resources = {
  7. spriteNames: [
  8. 'charas',
  9. 'tiles',
  10. 'walls',
  11. 'mobs',
  12. 'bosses',
  13. 'animBigObjects',
  14. 'bigObjects',
  15. 'objects',
  16. 'characters',
  17. 'attacks',
  18. 'ui',
  19. 'abilityIcons',
  20. 'uiIcons',
  21. 'items',
  22. 'materials',
  23. 'questItems',
  24. 'auras',
  25. 'sprites',
  26. 'animChar',
  27. 'animMob',
  28. 'animBoss',
  29. 'white',
  30. 'ray',
  31. 'images/skins/0001.png'
  32. ],
  33. sprites: {},
  34. ready: false,
  35. init: function (list) {
  36. list.forEach(function (l) {
  37. this.spriteNames.push(l);
  38. }, this);
  39. this.spriteNames.forEach(function (s) {
  40. var sprite = {
  41. image: (new Image()),
  42. ready: false
  43. };
  44. sprite.image.src = s.indexOf('png') > -1 ? s : 'images/' + s + '.png';
  45. sprite.image.onload = this.onSprite.bind(this, sprite);
  46. this.sprites[s] = sprite;
  47. }, this);
  48. },
  49. onSprite: function (sprite) {
  50. sprite.ready = true;
  51. var readyCount = 0;
  52. for (var s in this.sprites) {
  53. if (this.sprites[s].ready)
  54. readyCount++;
  55. }
  56. if (readyCount == this.spriteNames.length)
  57. this.onReady();
  58. },
  59. onReady: function () {
  60. this.ready = true;
  61. events.emit('onResourcesLoaded');
  62. }
  63. };
  64. return resources;
  65. });