F
Foss
Guest
Hey! I'd like to have cloud shadows that move across the screen, destroying themselves once they move off screen, and then re-spawning.
I have obj_cloud where I define the properties:
The code is obviously erroneous. That line, 'number_of_clouds -=1' seems to be what's breaking it. In my head, this should subtract 1 from the 'number_of_clouds' variable so that the spawn code can create another cloud.
Without that line, the clouds spawn and destroy themselves correctly. Just need to get the process repeating!
I have obj_cloud where I define the properties:
image_speed = 0;
image_index = irandom(3);
image_alpha = 0.1 * random(0.3);
image_xscale = 1 + random(0.2);
image_yscale = 1 + random(0.2);
speed = 0.1 + random(10);
direction = 360;
Then I have a separate obj_game with the Create event:image_index = irandom(3);
image_alpha = 0.1 * random(0.3);
image_xscale = 1 + random(0.2);
image_yscale = 1 + random(0.2);
speed = 0.1 + random(10);
direction = 360;
number_of_clouds = 0
maximum_clouds = 10
… and the Step event:maximum_clouds = 10
//Spawn a cloud in a random position off-screen
if number_of_clouds < maximum_clouds {
instance_create_layer(-500, 0 + random(1000), "layer_cloud", obj_cloud);
number_of_clouds += 1;
}
//Destroy a cloud if it moves off screen
with (obj_cloud) {
if x>room_width+600 {
instance_destroy();
number_of_clouds -= 1;
}
}
if number_of_clouds < maximum_clouds {
instance_create_layer(-500, 0 + random(1000), "layer_cloud", obj_cloud);
number_of_clouds += 1;
}
//Destroy a cloud if it moves off screen
with (obj_cloud) {
if x>room_width+600 {
instance_destroy();
number_of_clouds -= 1;
}
}
The code is obviously erroneous. That line, 'number_of_clouds -=1' seems to be what's breaking it. In my head, this should subtract 1 from the 'number_of_clouds' variable so that the spawn code can create another cloud.
Without that line, the clouds spawn and destroy themselves correctly. Just need to get the process repeating!