MODULE: Magnifier v1.0 - What is that thing? Oh I see!

Started by monkey0506, Tue 21/04/2009 19:49:53

Previous topic - Next topic

mitlark

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: ags
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:
Spoiler
[close]
SPIN SPIN! SPIN SPIN!

Romeo


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

Loslem

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: ags


void Update(this MagnifierType*) {
  if ((this.AGSGUI == null) || (this.Sprite <= 0)) {
    this.Enabled = false;
    return;
  }
  if (this.prevenabled != this.Enabled) { // toggle on/off
    if ((this.HideMouseCursor) || (this.prevhidemouse)) {
      if (this.Enabled) this.HideCursor();
      else this.ShowCursor();
    }
  }
  else if ((this.prevhidemouse != this.HideMouseCursor) && (this.Enabled)) {
    if (this.HideMouseCursor) this.HideCursor();
    else this.ShowCursor();
  }
  this.prevhidemouse = this.HideMouseCursor;
  if (this.ScaleFactor <= 0.0) this.ScaleFactor = 0.1;
  this.prevenabled = this.Enabled;
  this.AGSGUI.Visible = false;
  if (!this.Enabled) return;
  this.AGSGUI.BackgroundGraphic = 0;
  this.X = mouse.x;
  this.Y = mouse.y;
  if ((this.X + this.XOffset) < 0) this.AGSGUI.X = 0;
  else if ((this.X + this.XOffset) >= System.ViewportWidth) this.AGSGUI.X = (System.ViewportWidth - 1);
  else this.AGSGUI.X = (this.X + this.XOffset);
  if ((this.Y + this.YOffset) < 0) this.AGSGUI.Y = 0;
  else if ((this.Y + this.YOffset) >= System.ViewportHeight) this.AGSGUI.Y = (System.ViewportHeight - 1);
  else this.AGSGUI.Y = (this.Y + this.YOffset);
  DynamicSprite *sprite = DynamicSprite.CreateFromExistingSprite(this.Sprite, false);
  int x = (FloatToInt(IntToFloat(this.X) * this.ScaleFactor) + this.XOffset);
  int y = (FloatToInt(IntToFloat(this.Y) * this.ScaleFactor) + this.YOffset);
  sprite.ChangeCanvasSize(FloatToInt(IntToFloat(System.ViewportWidth) * this.ScaleFactor), FloatToInt(IntToFloat(System.ViewportHeight) * this.ScaleFactor), x, y);
  this.BackgroundSprite = DynamicSprite.CreateFromBackground();
  DrawingSurface *surface = this.BackgroundSprite.GetDrawingSurface();
  int i = 0;
  while ((i < Game.CharacterCount) || (i < Room.ObjectCount)) {
    if (i < Game.CharacterCount) {
      if (character[i].Room == player.Room) {
        ViewFrame *frame = Game.GetViewFrame(player.View, player.Loop, player.Frame);
        int w = ((Game.SpriteWidth[frame.Graphic] * character[i].Scaling) / 100);
        int h = ((Game.SpriteHeight[frame.Graphic] * character[i].Scaling) / 100);
        surface.DrawImage(character[i].x - (w / 2), character[i].y - h, frame.Graphic, 0, w, h);
      }
    }
    if (i < Room.ObjectCount) {
      if (object[i].Visible) {
        int graphic = object[i].Graphic;
        if (object[i].View) {
          ViewFrame *frame = Game.GetViewFrame(object[i].View, object[i].Loop, object[i].Frame);
          graphic = frame.Graphic;
        }
        int w = Game.SpriteWidth[graphic];
        int h = Game.SpriteHeight[graphic];
        if (!object[i].IgnoreScaling) {
          int scale = GetScalingAt(object[i].X, object[i].Y);
          w = ((w * scale) / 100);
          h = ((h * scale) / 100);
        }
        surface.DrawImage(object[i].X, object[i].Y - Game.SpriteHeight[graphic], graphic);
      }
    }
    i++;
  }
  surface.Release();
  this.BackgroundSprite.Resize(FloatToInt(IntToFloat(this.BackgroundSprite.Width) * this.ScaleFactor), FloatToInt(IntToFloat(this.BackgroundSprite.Height) * this.ScaleFactor));
  sprite.ChangeCanvasSize(this.BackgroundSprite.Width, this.BackgroundSprite.Height, 0, 0);
  this.BackgroundSprite.CopyTransparencyMask(sprite.Graphic);
  int w = Game.SpriteWidth[this.Sprite];
  int h = Game.SpriteHeight[this.Sprite];
  int ww = this.BackgroundSprite.Width;
  int hh = this.BackgroundSprite.Height;
  if ((ww > w) && (hh > h)) this.BackgroundSprite.Crop(x, y, w, h);
  else if (ww > w) {
    this.BackgroundSprite.Crop(x, 0, w, hh);
    if (hh < h) this.BackgroundSprite.ChangeCanvasSize(w, h, 0, (h - hh) / 2);
  }
  else if (hh > h) {
    this.BackgroundSprite.Crop(0, y, ww, h);
    if (ww < w) this.BackgroundSprite.ChangeCanvasSize(w, h, (w - ww) / 2, 0);
  }
  else this.BackgroundSprite.ChangeCanvasSize(w, h, (w - ww) / 2, (h - hh) / 2);
  if ((ww <= w) || (hh <= h)) {
    sprite = this.BackgroundSprite;
    this.BackgroundSprite = DynamicSprite.Create(w, h, false);
    surface = this.BackgroundSprite.GetDrawingSurface();
    surface.Clear(0);
    surface.DrawImage(0, 0, sprite.Graphic);
    surface.Release();
  }
  surface = this.BackgroundSprite.GetDrawingSurface();
  if (this.ScaleFactor < 1.0) {
    surface.DrawingColor = 0;
    int xm = FloatToInt(IntToFloat(System.ViewportWidth) * this.ScaleFactor);
    int xx = (x + w);
    if (x < 0) surface.DrawRectangle(0, 0, -x, surface.Height);
    if (xx >= xm) surface.DrawRectangle(xm - x, 0, xx - x, surface.Height);
    int ym = FloatToInt(IntToFloat(System.ViewportHeight) * this.ScaleFactor);
    int yy = (y + h);
    if (y < 0) surface.DrawRectangle(0, 0, surface.Width, -y);
    if (yy >= ym) surface.DrawRectangle(0, ym - y, surface.Width, yy - y);
    if ((x < 0) || (y < 0) || (xx >= xm) || (yy >= ym)) {
      surface.Release();
      sprite = DynamicSprite.CreateFromExistingSprite(this.Sprite, false);
      this.BackgroundSprite.CopyTransparencyMask(sprite.Graphic);
      surface = this.BackgroundSprite.GetDrawingSurface();
    }
  }
  surface.DrawImage(0, 0, this.Sprite);
  surface.Release();
  x = (this.X + this.XOffset);
  y = (this.Y + this.YOffset);
  int xx = (x + w);
  int yy = (y + h);
  if ((xx <= 0) || (yy <= 0) || (x >= System.ViewportWidth) || (y >= System.ViewportHeight)) {
    this.BackgroundSprite = null;
    this.AGSGUI.BackgroundGraphic = 0;
    this.AGSGUI.Width = 1;
    this.AGSGUI.Height = 1;
  }
  else {
    if ((x < 0) && (y < 0)) this.BackgroundSprite.Crop(-x, -y, this.BackgroundSprite.Width + x, this.BackgroundSprite.Height + y);
    else if (x < 0) this.BackgroundSprite.Crop(-x, 0, this.BackgroundSprite.Width + x, this.BackgroundSprite.Height);
    else if (y < 0) this.BackgroundSprite.Crop(0, -y, this.BackgroundSprite.Width, this.BackgroundSprite.Height + y);
    this.AGSGUI.BackgroundGraphic = this.BackgroundSprite.Graphic;
    this.AGSGUI.Width = this.BackgroundSprite.Width;
    this.AGSGUI.Height = this.BackgroundSprite.Height;
  }
  this.AGSGUI.Visible = true;
}
 


SMF spam blocked by CleanTalk