I'm trying to make rain splatters on the ground. To do this, I'm putting a DrawImage function in my repeatedly execute that will cycle at random, drawing these rain drops in the area I specify.
Here is my code:
function room_RepExec()
{
raintimer++;
if (raintimer == 1) {
surface = Room.GetDrawingSurfaceForBackground();
backup = surface.CreateCopy();
while (doover < 50) { // 20 raindrops
int y=(165+Random(35)); // 165-200 drawing area.
int x=Random(320); // whole screen.
if (Region.GetAtRoomXY(x, y) == region[1] || Region.GetAtRoomXY(x, y) == region[7]) {
surface.DrawImage(x, y, 303, (50+Random(50)));
doover++;
}
}
}
if (raintimer == 10) {
surface.DrawSurface(backup);
surface.Release();
backup.Release();
raintimer=0;
}
}
The problem is, after the rain drops appear once and are removed--as planned--they never re-appear. I'm having trouble figuring out exactly which Draw commands I need to use, as I only remember in the old version I just used RawSaveScreen and RawRestoreScreen, both of which are now obsolete.
The reason is, I think, that you didn't reset doover so it's already = 50 in the second time and nothing will work.
So:
function room_RepExec()
{
raintimer++;
if (raintimer == 1) {
surface = Room.GetDrawingSurfaceForBackground();
backup = surface.CreateCopy();
doover = 0;
while (doover < 50) { // 20 raindrops
int y=(165+Random(35)); // 165-200 drawing area.
int x=Random(320); // whole screen.
if (Region.GetAtRoomXY(x, y) == region[1] || Region.GetAtRoomXY(x, y) == region[7]) {
surface.DrawImage(x, y, 303, (50+Random(50)));
doover++;
}
}
}
if (raintimer == 10) {
surface.DrawSurface(backup);
surface.Release();
backup.Release();
raintimer=0;
}
}
Doh, thanks, that fixed it.