In my new project, I use an array to store 6 different images I want to randomly load onto 9 image elements. I want to set a limit so that only 1 of the images can load onto 3 of the planes (of 9 planes, only 3 can have the picture of a star, for example. If there are 3 stars each other image can only appear twice at most and no more stars can appear).
As it is I have this set up to limit how many times each images appear:
RandomImage.prototype.initialize = function()
{
var image; //Selected image to render on plane
var newImages; //Array of images if any image reaches a count of 3
//Variables to track how many times an image has been
//picked to limit the number of each image to 3
var spades = 0;
var diamonds = 0;
var shoes = 0;
var clubs = 0;
var sevens = 0;
var stars = 0;
var planes = this.app.root.findByTag("symbol"); //Image elements in scene
//Randomly select an image for each plane
for(i=0;i<planes.length;i++)
{
image = this.images[Math.floor(Math.random()*this.images.length)]; //this.images is a script attribute array of assets
if(image.name === "Diamonds.png")
{
if(diamonds < 3)
{
diamonds += 1;
console.log("Num Diamonds: " + diamonds);
}
else if(diamonds === 3)
{
//Remove this image from array and limit others to 2
}
}
else if(image.name === "Clubs.png")
{
if(clubs < 3)
{
clubs += 1;
console.log("Num Clubs: " + clubs);
}
else if(clubs === 3)
{
//Remove this image from array and limit others to 2
}
}
else if(image.name === "horseshoe.png")
{
if(shoes < 3)
{
shoes += 1;
console.log("Num Shoes: " + shoes);
}
else if(shoe === 3)
{
//Remove this image from array and limit others to 2
}
}
else if(image.name === "seven.png")
{
if(sevens < 3)
{
seven += 1;
console.log("Num Sevens: " + sevens);
}
else if(sevens === 3)
{
//Remove this image from array and limit others to 2
}
}
else if(image.name === "spades.png")
{
if(spades < 3)
{
spades += 1;
console.log("Num Spades: " + spades);
}
else if(spades === 3)
{
//Remove this image from array and limit others to 2
}
}
else if(image.name === "star.png")
{
if(stars < 3)
{
stars += 1;
console.log("Num Star: " + stars);
}
else if(stars === 3)
{
//Remove this image from array and limit others to 2
}
}
planes[i].element.texture = image.resource;
}
};
I’m looking for something like this to happen almost every time.