Copying a section of the background

Started by joelphilippage, Tue 31/08/2010 16:24:26

Previous topic - Next topic

joelphilippage

I'm not experienced at drawing things in-game.
Code: ags

  DynamicSprite* cutBackground = DynamicSprite.CreateFromBackground(GetBackgroundFrame(), TopX, TopY, Width, Height);
  cutBackground.SaveToFile("tmp.bmp");
  cutBackground.Delete();
  player.ChangeRoom(zoomedRoom);
  DynamicSprite* backdrop = DynamicSprite.CreateFromFile("tmp.bmp");
  DrawingSurface *zoomedBackround = Room.GetDrawingSurfaceForBackground();
  zoomedBackround.DrawImage(0, 0, backdrop.Graphic, 0, 640, 400);
  zoomedBackround.Release();
  backdrop.Delete();
  File.Delete("tmp.bmp");


This should cut out a section of the background, then go to the assigned room where it will then paste the section of backdrop in the next room scaled to full size.

Problem: After the room changes, the image is not pasted.



Ryan Timothy B

#1
When a room changes with the ChangeRoom, it still runs the script afterwards before actually changing the room.

First. You don't need to export the image as a bmp outside of AGS just to import it again and delete it. Why not just use a Global Variable. Or a variable in the globalscript if this were all running in the globalScript (or just simply do the import export method).

But the global variable is definitely the way to go. Go to the global variable pane and you'll see that you can create a DynamicSprite* type variable. Let's pretend you name it cutBackground, like you did in this script.
Also, every time the zoomed room is loaded, the altered background won't be stored anymore.


So do this in the room script, or global script, or wherever this copying action should be called while in the previous room.
Code: ags

  cutBackground = DynamicSprite.CreateFromBackground(GetBackgroundFrame(), TopX, TopY, Width, Height);
  player.ChangeRoom(zoomedRoom);


Then in the new room (in the Room_Load, so you can see it before the fade in):
Code: ags

if (cutBackground!=null)
{
  DrawingSurface *surface = Room.GetDrawingSurfaceForBackground();
  surface .DrawImage(0, 0, cutBackground.Graphic, 0, 640, 400);
  surface.Release();
}




If this were all being called in the GlobalScript you could simply just do the pasting of this image within the On_Event instead of the previous script doing it in the Room_Load, like so:
Code: ags

function on_event (EventType event, int data)
{
  if (event == eEventEnterRoomBeforeFadein && data == zoomedRoom && cutBackground!=null)
  {
    DrawingSurface *surface = Room.GetDrawingSurfaceForBackground();
    surface .DrawImage(0, 0, cutBackground.Graphic, 0, 640, 400);
    surface.Release();
  }
}




Then you just delete what is stored in the global DynamicSprite whenever you don't need it anymore.
Code: ags

  cutBackground.Delete();



Also, if this were a one time thing, I'd definitely suggest just drawing a zoomed in version of the background, since it won't look all that attractive stretched with AGS.

joelphilippage

I had to do a few tweaks, but it works. Thanks. I tried that method before but thought it was deleting the image between rooms.



SMF spam blocked by CleanTalk