WombatTurkey Posted January 12, 2016 Share Posted January 12, 2016 Hey guys, so If you are creating a very large game or mmo and have hundreds of skills and don't want to load all those game assets at once, but only if a player has used that skill, this guide is for you! 1. Create a global array Loaded_Skills = [] 2. Create a function that activate's a player's skill dynamically UseSkill = function(Skill_ID) { if (Loaded_Skills.indexOf(Skill_ID) == -1) { // This skill sprite sheet is not loaded var temp_sprite = game.load.spritesheet('Warcry', '../img/skills/warcry.png', 32, 18, 5); temp_sprite.start(); temp_sprite.onFileComplete.add(LoadSkillComplete, temp_sprite); } else { //Skill sheet is already loaded LoadSkillComplete(100); // note the 100 is still being passed } function LoadSkillComplete(progress) { if (progress == 100) { // File is now 100% dynamically loaded and ready to be inserted into game var temp_monster = game.add.sprite(0, 0, 'Warcry'); Loaded_Skills.push(Skill_ID); // Add the skill id to the loaded sklll array so we know it's loaded } } } 3. Now use the UseSkill function and pass in the appropriate skill id. Some things to consider: -- You might want to grab your skill name (Animations, etc) and other skill information from an object for example: Skill_Data = Skills[Skill_ID] Hope this helps and saves you some bandwidth! shohan4556 and hoskope 2 Link to comment Share on other sites More sharing options...
shohan4556 Posted January 12, 2016 Share Posted January 12, 2016 Very useful tutorial, thanks for sharing. WombatTurkey 1 Link to comment Share on other sites More sharing options...
Recommended Posts