Zooming Animation

Started by Snake Blisken, Wed 23/11/2005 12:26:07

Previous topic - Next topic

Snake Blisken

This probably isn't the best way to do this, and I am completly open to suggestions. Anyway, I wanted to be able to slowly zoom in on a house and appear as if you were floating closer and closer and then through the window. But I needed the window to stay in the center of screen.Ã,  (Well, it would be neat to give it a more "floating" effect, and maybe one day I will implement that as well. For right now, though, it it is MUCH easier to just keep the center of the window in the center of the screen)

At first, I simply used RawDrawImageResized() in a loop to slowly increase the size of the image. I also had to change the x,y cordinates so that everything would line up right. This worked ok, but the closer you got to the window, the slower the animation got. So, I made a couple more graphics to place in between so that at certain points, it would start with a new image instead of trying to enlarge one image.

You can see the animation in action here http://projects.iannarelli.com/AGS/Ã,  Please make sure you run winsetup and check 640X480, so the graphics will look ok. (Well, you'll have to forgive the programmer graphics. But they do actually look worse in 320X240)

Here is the script. All constructive comments are very welcome.

mouse.Visible = false;

StartCutscene(eSkipAnyKeyOrMouseClick);

int counter = 0;
int x = 0;
int y = 0;
int w = 320;
int h = 240;

while(counter < 32)
{
Ã,  counter ++;
Ã,  Ã, 
   RawDrawImageResized(x, y, 2,w, h);
   
   x = x - 4;
   y = y - 3;
   w = w + 8;
   h = h + 6;
   
   Wait(2);
}

counter = 0;
x = 0;
y = 0;
w = 320;
h = 240;

while(counter < 38)
{
Ã,  counter ++;
Ã,  Ã, 
   RawDrawImageResized(x, y, 3,w, h);
   
   x = x - 4;
   y = y - 3;
   w = w + 8;
   h = h + 6;
   
   Wait(2);
}Ã,  Ã, 

counter = 0;
x = 0;
y = 0;
w = 320;
h = 240;

while(counter < 50)
{
Ã,  counter ++;
Ã,  Ã, 
   RawDrawImageResized(x, y, 6,w, h);
   
   x = x - 4;
   y = y - 3;
   w = w + 8;
   h = h + 6;
   
   Wait(2);
}Ã, 

Wait(40);
EndCutscene();

mouse.Visible = true;
player.ChangeRoom(2, 85, 195);Ã, 

Thanks
Snake Blisken
Thanks,
Snake Blisken

SSH

What you need to do to keep the speed of change is to increase the amount you change x, y, w and h by each game cycle. In fact, I'll maybe go and make a module to do this...
12

strazer


Snake Blisken

Quote from: SSH on Wed 23/11/2005 12:39:48
What you need to do to keep the speed of change is to increase the amount you change x, y, w and h by each game cycle. In fact, I'll maybe go and make a module to do this...

But wouldn't that make the end of the animation seem choppy because it would be taking larger "steps" at each loop?
Thanks,
Snake Blisken

Snake Blisken

#4
Quote from: Snake Blisken on Wed 23/11/2005 12:43:13
Quote from: SSH on Wed 23/11/2005 12:39:48
What you need to do to keep the speed of change is to increase the amount you change x, y, w and h by each game cycle. In fact, I'll maybe go and make a module to do this...

But wouldn't that make the end of the animation seem choppy because it would be taking larger "steps" at each loop?

This looks like it might work. I don't have much time right now to tweak it, but initial tests look promising. Thanks for the advice!

EDIT: I have updated the zip file. It still needs some tweaking, but this solution appears to be much better. Here is the modified script. Maybe after thanksgiving I will clean it up some and post the modified script.

mouse.Visible = false;

StartCutscene(eSkipAnyKeyOrMouseClick);

int counter = 0;
int x = 0;
int y = 0;
int w = 320;
int h = 240;

while(counter < 30)
{
Ã,  counter ++;
Ã,  Ã, 
   RawDrawImageResized(x, y, 2,w, h);
   
   x = x - 4;
   y = y - 3;
   w = w + 8;
   h = h + 6;
   
   Wait(2);
}

counter = 0;
//x = 0;
//y = 0;
//w = 320;
//h = 240;

while(counter < 30)
{
Ã,  counter ++;
Ã,  Ã, 
   RawDrawImageResized(x, y, 2,w, h);
   
   x = x - 8;
   y = y - 6;
   w = w + 16;
   h = h + 12;
   
   Wait(2);
}Ã,  Ã, 

counter = 0;
//x = 0;
//y = 0;
//w = 320;
//h = 240;

while(counter < 15)
{
Ã,  counter ++;
Ã,  Ã, 
   RawDrawImageResized(x, y, 2,w, h);
   
   x = x - 32;
   y = y - 24;
   w = w + 64;
   h = h + 48;
   
   Wait(2);
}

while(counter < 10)
{
Ã,  counter ++;
Ã,  Ã, 
   RawDrawImageResized(x, y, 2,w, h);
   
   x = x - 64;
   y = y - 48;
   w = w + 128;
   h = h + 96;
   
   Wait(2);
}Ã,  Ã, 

while(counter < 5)
{
Ã,  counter ++;
Ã,  Ã, 
   RawDrawImageResized(x, y, 2,w, h);
   
   x = x - 128;
   y = y - 96;
   w = w + 256;
   h = h + 192;
   
   Wait(2);
}Ã,  Ã, 

Wait(40);
EndCutscene();

mouse.Visible = true;
player.ChangeRoom(2, 85, 195);Ã,  Ã, 
Thanks,
Snake Blisken

SSH

Gah! I'm trying to remember my trigonometry to work out how the steps should change, but its all gone. This is what happens 14 years after leaving school...

In my star wars scroller I used a reciprocal of a loop counter to calculate the size as things scrolled away. Another way to do it is to utilise the walkable area scaling and speed scaling and make your house a character...
12

Snake Blisken

#6
Quote from: SSH on Wed 23/11/2005 13:12:06
Gah! I'm trying to remember my trigonometry to work out how the steps should change, but its all gone. This is what happens 14 years after leaving school...

In my star wars scroller I used a reciprocal of a loop counter to calculate the size as things scrolled away. Another way to do it is to utilise the walkable area scaling and speed scaling and make your house a character...

Actually, I looked at the walkable area scaling when I first started, but I wasn't sure how to work it into what I am trying to do. I will put some more thought into this possibility as well. BTW, what is speed scaling? Thanks for all the help and advice. See ya after thanksgiving!

EDIT: At least you took trig! :) If I knew then that I would fall in love with programming, I would have done a better job in math class!
Thanks,
Snake Blisken

Wretched

#7
Here's my zoom code, slightly modified and therefore probably not working any more, from the last room in Magsic II where you could zoom in on various parts of the screen.


DynamicSprite *DSP;

// Zoom in & out on point (x,y),Ã,  Ã, z depth of zoom,Ã,  InOnly flag drops out after zoom in

function Zoom(int x, int y, int z, bool InOnly)
{
Ã,  RawSaveScreen();

Ã,  DSP=DynamicSprite.CreateFromScreenShot();
Ã,  Wait(1);

Ã,  int kx;
Ã,  int ky;
Ã,  int i=0;
Ã,  int id=z/60;
Ã, 
Ã,  while(i>=0)
Ã,  {
Ã,  Ã,  kx=(-(x*(320+z*2))/320)+160;Ã, 
Ã,  Ã,  ky=(-(y*(240+z*2))/240)+120;Ã, 
Ã, 
Ã,  Ã,  RawDrawImageResized( (kx*i)/z, (ky*i)/z, DSP.Graphic, 320+i*2, 240+i*2);
Ã,  Ã, 
Ã,  Ã,  Wait(1);
Ã, 
Ã,  Ã,  i+=id;
Ã,  Ã,  if (i>z)
Ã,  Ã,  {
Ã,  Ã,  Ã,  //Use this as basis for room background after zoom in
Ã,  Ã,  Ã,  //SaveScreenShot("zoom.pcx");
Ã,  Ã,  Ã, 
Ã,  Ã,  Ã,  id=-id;
Ã,  Ã,  Ã,  i=z;
Ã,  Ã,  Ã, 
Ã,  Ã,  Ã,  if (InOnly)
Ã,  Ã,  Ã,  {
Ã,  Ã,  Ã,  Ã,  return;
Ã,  Ã,  Ã,  }
Ã,  Ã,  }
Ã,  }

Ã,  RawRestoreScreen();
}


Usage:

Zoom(88,170,300,0);




SSH

I've created a Zoom module here which you can feel free to use...
12

SMF spam blocked by CleanTalk