PDA

View Full Version : [AS2] Spawning MC From Library Several Times


Sythius
07-03-2009, 02:17 PM
Right.
I'm making a game xD
What I have is a MC that on frame 5 or so has "_root.GUIwood = _root.GUIwood+1;"
But what I want to do is spawn it from the library once per click, but can be repeatedly done to gain several, I also don't want it on the stage.

This game is like a empire construction game. Food is one of the resources and I want to simulate the constant need to feed workers. so when a worker is made from the HQ, it gets added to the total number of workers available. (which is a var) but I want that worker to cause a constant decrease on the food resource. My problem is that I currently can only spawn one, at max.

My current code for doing so is this :
on (release) {
mc = _root.attachMovie("sym1", "sym1"+n, +n1);
mc._x = random(800);
mc._x = random(900);
mc._alpha = 50;
}
Any help? :D

bluemagica
07-03-2009, 03:13 PM
yeh, give a bit better explanation. -_-


For the "I can create only one instance part", increase the value of n each time something is created, by putting n++ on the next line, and in the same attachMovie line, you are setting depth to +n1, that will be ++n1, and you have to increase it again in the next line for next time.....cause you can't have two instances with exact same name or depth in AS2.

As for the food consumption thing, I couldn't understand what you were coding to try and do this, but it can be simply done using a setInterval (read it in the helpfile)! use setInterval to run a function every 5 seconds or so, like


function consume_food()
{
total_food -= total_worker*per_worker_consumption_rate;
total_food = total_food>0?total_food:0;
}