Adventure Game Studio

AGS Support => Beginners' Technical Questions => Topic started by: TheJBurger on Sun 31/08/2008 08:24:48

Title: DrawImage Appearing and Reappearing [solved]
Post by: TheJBurger on Sun 31/08/2008 08:24:48
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.
Title: Re: DrawImage Appearing and Reappearing
Post by: Gilbert on Sun 31/08/2008 09:44:35
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;
    }
}

Title: Re: DrawImage Appearing and Reappearing
Post by: TheJBurger on Mon 01/09/2008 02:25:02
Doh, thanks, that fixed it.