Mittens 2018 will be in Boston this September. There are three spaces left, so check out the thread for details!

Author Topic: MODULE: Magnifier v1.0 - What is that thing? Oh I see!  (Read 7026 times)

mitlark

  • I'm more of an RPG guy but I like AGS :V.
    • I can help with AGS tutoring
    •  
Re: MODULE: Magnifier v1.0 - What is that thing? Oh I see!
« Reply #20 on: 28 Feb 2014, 19:40 »
Does your magnifier sprite have alpha channel? If it does, then it should work. It it doesn't, by using an image editor make it have alpha, then make the center part semitransparent, AND make sure your background has alpha channel too.

If it throws an error saying something about color depth, modify your background, adding an alpha channel to it and making sure it is in 24bpp (or 32bpp if we count alpha). Then reimport the background.

Also, if it mentions something about sprites not being the same size (at least it threw me an error like that), add this line just before the one that the error remarks (possibly line 108):
Code: Adventure Game Studio
  1. sprite.ChangeCanvasSize(this.BackgroundSprite.Width, this.BackgroundSprite.Height, 0, 0);

I hope it works for you. I'm not going to use it, but this thing is pretty rad. Here a screenie:
Add spoiler tag for Hidden:
SPIN SPIN! SPIN SPIN!

Re: MODULE: Magnifier v1.0 - What is that thing? Oh I see!
« Reply #21 on: 01 Mar 2014, 09:46 »

The magnifier sprite had an alpha-channel (actually I used the sprite included by monkey in the module) but I never thought to change the backgrounds... then after your advices I saved the backgrounds as TIFF and reimported them. It was enough. Now everything works fine. Nice module!! :smiley:
Thanks for your answer

Re: MODULE: Magnifier v1.0 - What is that thing? Oh I see!
« Reply #22 on: 01 Dec 2017, 19:29 »
Okay... lets go for some necroposting (Hey I kind of asked)

Long story short: has anybody ever gotten this module to work with scrolling rooms?

If I have a scrolling room, aand I enable the magnifier - The picture behind the magnifier (which I think is the dynamic sprite from the background) will only show magnified whats in the first picture of the room, regarding my room resolution. So put simple: I walk right, the room scrolls, the magnifier acts as if the room would not scroll.
I know it's asked way to much of you to go trough all the Modules Code, if you don't have time/mood it's okay.

Here the vode basically

Code: Adventure Game Studio
  1.  
  2. void Update(this MagnifierType*) {
  3.   if ((this.AGSGUI == null) || (this.Sprite <= 0)) {
  4.     this.Enabled = false;
  5.     return;
  6.   }
  7.   if (this.prevenabled != this.Enabled) { // toggle on/off
  8.     if ((this.HideMouseCursor) || (this.prevhidemouse)) {
  9.       if (this.Enabled) this.HideCursor();
  10.       else this.ShowCursor();
  11.     }
  12.   }
  13.   else if ((this.prevhidemouse != this.HideMouseCursor) && (this.Enabled)) {
  14.     if (this.HideMouseCursor) this.HideCursor();
  15.     else this.ShowCursor();
  16.   }
  17.   this.prevhidemouse = this.HideMouseCursor;
  18.   if (this.ScaleFactor <= 0.0) this.ScaleFactor = 0.1;
  19.   this.prevenabled = this.Enabled;
  20.   this.AGSGUI.Visible = false;
  21.   if (!this.Enabled) return;
  22.   this.AGSGUI.BackgroundGraphic = 0;
  23.   this.X = mouse.x;
  24.   this.Y = mouse.y;
  25.   if ((this.X + this.XOffset) < 0) this.AGSGUI.X = 0;
  26.   else if ((this.X + this.XOffset) >= System.ViewportWidth) this.AGSGUI.X = (System.ViewportWidth - 1);
  27.   else this.AGSGUI.X = (this.X + this.XOffset);
  28.   if ((this.Y + this.YOffset) < 0) this.AGSGUI.Y = 0;
  29.   else if ((this.Y + this.YOffset) >= System.ViewportHeight) this.AGSGUI.Y = (System.ViewportHeight - 1);
  30.   else this.AGSGUI.Y = (this.Y + this.YOffset);
  31.   DynamicSprite *sprite = DynamicSprite.CreateFromExistingSprite(this.Sprite, false);
  32.   int x = (FloatToInt(IntToFloat(this.X) * this.ScaleFactor) + this.XOffset);
  33.   int y = (FloatToInt(IntToFloat(this.Y) * this.ScaleFactor) + this.YOffset);
  34.   sprite.ChangeCanvasSize(FloatToInt(IntToFloat(System.ViewportWidth) * this.ScaleFactor), FloatToInt(IntToFloat(System.ViewportHeight) * this.ScaleFactor), x, y);
  35.   this.BackgroundSprite = DynamicSprite.CreateFromBackground();
  36.   DrawingSurface *surface = this.BackgroundSprite.GetDrawingSurface();
  37.   int i = 0;
  38.   while ((i < Game.CharacterCount) || (i < Room.ObjectCount)) {
  39.     if (i < Game.CharacterCount) {
  40.       if (character[i].Room == player.Room) {
  41.         ViewFrame *frame = Game.GetViewFrame(player.View, player.Loop, player.Frame);
  42.         int w = ((Game.SpriteWidth[frame.Graphic] * character[i].Scaling) / 100);
  43.         int h = ((Game.SpriteHeight[frame.Graphic] * character[i].Scaling) / 100);
  44.         surface.DrawImage(character[i].x - (w / 2), character[i].y - h, frame.Graphic, 0, w, h);
  45.       }
  46.     }
  47.     if (i < Room.ObjectCount) {
  48.       if (object[i].Visible) {
  49.         int graphic = object[i].Graphic;
  50.         if (object[i].View) {
  51.           ViewFrame *frame = Game.GetViewFrame(object[i].View, object[i].Loop, object[i].Frame);
  52.           graphic = frame.Graphic;
  53.         }
  54.         int w = Game.SpriteWidth[graphic];
  55.         int h = Game.SpriteHeight[graphic];
  56.         if (!object[i].IgnoreScaling) {
  57.           int scale = GetScalingAt(object[i].X, object[i].Y);
  58.           w = ((w * scale) / 100);
  59.           h = ((h * scale) / 100);
  60.         }
  61.         surface.DrawImage(object[i].X, object[i].Y - Game.SpriteHeight[graphic], graphic);
  62.       }
  63.     }
  64.     i++;
  65.   }
  66.   surface.Release();
  67.   this.BackgroundSprite.Resize(FloatToInt(IntToFloat(this.BackgroundSprite.Width) * this.ScaleFactor), FloatToInt(IntToFloat(this.BackgroundSprite.Height) * this.ScaleFactor));
  68.   sprite.ChangeCanvasSize(this.BackgroundSprite.Width, this.BackgroundSprite.Height, 0, 0);
  69.   this.BackgroundSprite.CopyTransparencyMask(sprite.Graphic);
  70.   int w = Game.SpriteWidth[this.Sprite];
  71.   int h = Game.SpriteHeight[this.Sprite];
  72.   int ww = this.BackgroundSprite.Width;
  73.   int hh = this.BackgroundSprite.Height;
  74.   if ((ww > w) && (hh > h)) this.BackgroundSprite.Crop(x, y, w, h);
  75.   else if (ww > w) {
  76.     this.BackgroundSprite.Crop(x, 0, w, hh);
  77.     if (hh < h) this.BackgroundSprite.ChangeCanvasSize(w, h, 0, (h - hh) / 2);
  78.   }
  79.   else if (hh > h) {
  80.     this.BackgroundSprite.Crop(0, y, ww, h);
  81.     if (ww < w) this.BackgroundSprite.ChangeCanvasSize(w, h, (w - ww) / 2, 0);
  82.   }
  83.   else this.BackgroundSprite.ChangeCanvasSize(w, h, (w - ww) / 2, (h - hh) / 2);
  84.   if ((ww <= w) || (hh <= h)) {
  85.     sprite = this.BackgroundSprite;
  86.     this.BackgroundSprite = DynamicSprite.Create(w, h, false);
  87.     surface = this.BackgroundSprite.GetDrawingSurface();
  88.     surface.Clear(0);
  89.     surface.DrawImage(0, 0, sprite.Graphic);
  90.     surface.Release();
  91.   }
  92.   surface = this.BackgroundSprite.GetDrawingSurface();
  93.   if (this.ScaleFactor < 1.0) {
  94.     surface.DrawingColor = 0;
  95.     int xm = FloatToInt(IntToFloat(System.ViewportWidth) * this.ScaleFactor);
  96.     int xx = (x + w);
  97.     if (x < 0) surface.DrawRectangle(0, 0, -x, surface.Height);
  98.     if (xx >= xm) surface.DrawRectangle(xm - x, 0, xx - x, surface.Height);
  99.     int ym = FloatToInt(IntToFloat(System.ViewportHeight) * this.ScaleFactor);
  100.     int yy = (y + h);
  101.     if (y < 0) surface.DrawRectangle(0, 0, surface.Width, -y);
  102.     if (yy >= ym) surface.DrawRectangle(0, ym - y, surface.Width, yy - y);
  103.     if ((x < 0) || (y < 0) || (xx >= xm) || (yy >= ym)) {
  104.       surface.Release();
  105.       sprite = DynamicSprite.CreateFromExistingSprite(this.Sprite, false);
  106.       this.BackgroundSprite.CopyTransparencyMask(sprite.Graphic);
  107.       surface = this.BackgroundSprite.GetDrawingSurface();
  108.     }
  109.   }
  110.   surface.DrawImage(0, 0, this.Sprite);
  111.   surface.Release();
  112.   x = (this.X + this.XOffset);
  113.   y = (this.Y + this.YOffset);
  114.   int xx = (x + w);
  115.   int yy = (y + h);
  116.   if ((xx <= 0) || (yy <= 0) || (x >= System.ViewportWidth) || (y >= System.ViewportHeight)) {
  117.     this.BackgroundSprite = null;
  118.     this.AGSGUI.BackgroundGraphic = 0;
  119.     this.AGSGUI.Width = 1;
  120.     this.AGSGUI.Height = 1;
  121.   }
  122.   else {
  123.     if ((x < 0) && (y < 0)) this.BackgroundSprite.Crop(-x, -y, this.BackgroundSprite.Width + x, this.BackgroundSprite.Height + y);
  124.     else if (x < 0) this.BackgroundSprite.Crop(-x, 0, this.BackgroundSprite.Width + x, this.BackgroundSprite.Height);
  125.     else if (y < 0) this.BackgroundSprite.Crop(0, -y, this.BackgroundSprite.Width, this.BackgroundSprite.Height + y);
  126.     this.AGSGUI.BackgroundGraphic = this.BackgroundSprite.Graphic;
  127.     this.AGSGUI.Width = this.BackgroundSprite.Width;
  128.     this.AGSGUI.Height = this.BackgroundSprite.Height;
  129.   }
  130.   this.AGSGUI.Visible = true;
  131. }
  132.  
  133.