Jump to content

[Mini Tutorial] - How to dynamically load game assets


WombatTurkey
 Share

Recommended Posts

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!

Link to comment
Share on other sites

 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...