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

monkey0506

I actually stole the idea for this directly from Lego Indiana Jones. I was playing it and in Barnett College there's a map and you use a magnifying glass to indicate where you want to go next. As I was playing around with it the first thing that came to my mind was "somebody should write that module," so of course, I did.

So this module creates a magnifying glass-style effect for your game. I tested it with scale factors as high as 2.65 (265% scale) and as low as 0.1 (10% scale) and still maintained 40 FPS, though in rooms with other effects, lots of characters, etc. it may run quite slowly.

It requires a GUI to display the effect and a sprite to be used as the "magnifying glass." It does work with sprites with an alpha channel so you can for example create a light blue tint over the magnified area (as done by the included magnifier.png file). However if you have an alpha channel around the outer edge of the "frame" then it will display the magnified image behind the outer edge instead of the normal background. This is due to the way that AGS handles drawing alpha channels and should be corrected in a future version. Also the only real reason it requires a GUI is for future compatibility with that, but I could probably add an Overlay mode if requested.

Download
Mirror

placyd

That would be a very useful module for me, because in my next game there will be a puzzle where you have to use a magnifier  :P
I'm glad that I found this, but unfortunatelly it's not working for me.
My room is 640x400, 32bit colour depth, and I've used your png file as the magnifier sprite, I've created a blank GUI and set everything as in the manual, but an error comes up at this line:

this.BackgroundSprite.CopyTransparencyMask(sprite.Graphic);

The error message is:

DynamicSprite.CopyTransparencyMask: sprites are not the same colour depth.

What could be the problem?

Another question: what size should be the magnifier gui, and it should be blank or it should have a background?


monkey0506

#2
The DynamicSprite* for Magnifier.BackgroundSprite is assigned as:

Code: ags
this.BackgroundSprite = DynamicSprite.CreateFromBackground();


So a difference in the colour depth would mean that the room's background is not 32-bit...?

As far as the GUI goes the Width, Height, BackgroundGraphic, and Visible properties are all managed by the module's code so none of those are strictly relevant as far as the in-editor setup.

However what I'd suggest would be to just simply make it a transparent GUI the size of the magnifying glass sprite. That would probably be simplest. If it makes you feel better you could even assign its background graphic to that of the sprite. But any controls or other settings would not be affected, so could distort the effect...or you might be able to find a way to take advantage of these... ;)

Oh and I'm glad to hear that you'd find this useful. :)

Ryan Timothy B

It would be nice to see a picture of what one could expect from this without having to install it for themselves. :P
I only want to see what it does due to programing curiosity.
Sounds as though you're only enlarging a section of the background, so you're not seeing more, you're only seeing it enlarged.  Correct?

monkey0506

Well it depends how much you can see prior to the scaling level being applied. :P

I'll try and get a screenshot up when I get the chance.

(What this module does is it resizes a portion of the background based on a given scaling level and then overlays a sprite on top of that, i.e. doing what a magnifying glass does. It won't actually allow you to see things that aren't already there, but it could be useful...maybe)

Wonkyth

Couldn't you just have a second image that acts as the zoomed in version?
"But with a ninja on your face, you live longer!"

NsMn

I have to agree, that would make it much easier.

placyd

Ok, it's working now :P
First I've imported a bigger background image then 640x400, so it's not working with scrolling rooms...
Here are two pictures showing the magnifier effect with 2x scale:

One more thing: when the player character is hidden, the magnifier shows him ;)
It's not a problem, because I can place him out of the screen, I just mentioned it :)

Wonkyth

On my earlier thought:
The only problem with that is that things that can move would need to be updated constantly, and for large rooms/high res games it's gonna use allot of space.
"But with a ninja on your face, you live longer!"

Knox

Hey Monkey,

1st, great module...Ive got it to work on my background no probs...super nice!

I was wondering, is there away to make this also work for magnifying gui's? Right now Im trying to magnify a gui, and the effect "cuts" through the gui and shows the background room instead.
--All that is necessary for evil to triumph is for good men to do nothing.

monkey0506

Hey, I must have somehow missed a couple posts in this thread. Thanks to placyd for the bug reports and uploading those screenshots. I took a second to look over the code, and I'm pretty sure I know why it's not working with scrolling rooms. I have a couple projects I'm actively working on right now, but I'll try and keep this in mind that I need to fix this at some point. Hidden characters still showing up is pretty simple to fix also.

Regarding Wonky's suggestion of using a statically zoomed sprite, that's actually not a bad idea to allow the user to specify a separate static sprite this way (that would even allow you to show more detail, smooth scaling, etc.), and it also gave me the idea of caching the background sprite (instead of resizing a new dynamic sprite every game loop like it's doing now to get the background; characters and objects would still have to be dynamically added on top of that).

As for magnifying GUIs..I'm not sure. Because at that point I'd pretty much have to rerender the entire screen via the script, which would not be efficient at all. I'm already redrawing the background, characters, and objects..having to redraw GUIs and GUIControls (especially labels, textboxes, etc.) would make it somewhat of a nightmare.

Knox

Suppose I just wanted to use it on gui's only (no redraw for backgrounds, characters, or objects)...would it be doable?

Ive got some gui's set up as booklets, and Id use the magnifier only on the gui area, to see small print, etc...it would never be used on the background room, characters or whatever...plus the game is paused so i was thinking is there a way to capture the whole screen, set it on the background, and then Id just hide all the open gui's...when the magnifier is closed, everything is restored to how it was.

I dont know, does that sound crazy? If so, crap! Got to rethink how Im gonna do this :P
--All that is necessary for evil to triumph is for good men to do nothing.

monkey0506

I think that for your purposes the best thing to do would be to create a highly specialized route instead of a generic route. For that, let me ask you some questions..

Does your GUI move, or in any way change? Do the controls change? Is the text dynamic?

So long as the GUI stays in one place and doesn't change during magnification..it would be presumably possible to hide the mouse cursor, wait until the next game loop (for the screen to refresh), use DynamicSprite.CreateFromScreenshot to grab the image of the GUI, and then keep it as a cached copy..

Doing that would save you (or me :P) from having to redraw the GUI and its controls. This method wouldn't work well generically (or for other cases like the background, characters, and objects) because of the fact that if you use CreateFromScreenshot it will capture the mouse (even if you turn it off), so you have to wait till the next game loop.

The cached copy would be resized and cropped dynamically as needed..it could work well depending on your needs and implementation.

Knox

#13
Good news is that when I go into "magnify" mode...everything will be "frozen", as in the booklets can no longer be flipped. Nothing is dynamic at all.

Here is a screenshot to give an idea:



--All that is necessary for evil to triumph is for good men to do nothing.

monkey0506

Okay, I'm gonna take this to PM since this is going to be specialized code unrelated to the module.. ;)

Knox

--All that is necessary for evil to triumph is for good men to do nothing.

Knox

#16
Hey Monkey,

If you have a chance today (may 1st), go to Google homepage...there's a magnifier "effect" they are using whe you go over the google logo...which is pretty much like yours, no?

Kinda cool.
--All that is necessary for evil to triumph is for good men to do nothing.

Knox

MUaaaahhaahhh!!

Evil gril  ;D

...Now that you're on a roll with your modules Monkey...

<tilts head back and laughs maniacally while wringing hands>

...what says-you to p'raps make the above request work?   :-*

...MuuaAAhahaah-haha HAHA HAHAHh haha!!

<thunder claps in distance, evil glare in eyes>

Evil gril  ;D
--All that is necessary for evil to triumph is for good men to do nothing.

Knox

QuoteSo long as the GUI stays in one place and doesn't change during magnification..it would be presumably possible to hide the mouse cursor, wait until the next game loop (for the screen to refresh), use DynamicSprite.CreateFromScreenshot to grab the image of the GUI, and then keep it as a cached copy..

Ok so once I get the screen grab, I can resize it/move it to follow the magnifier? I guess with an alpha channel on my magnifier sprite, I can "cut" that piece into a circle, right?

Im going to attempt to make the magnifier work on a static/non modifiable/non-moving GUI. :)
--All that is necessary for evil to triumph is for good men to do nothing.

Romeo


Hi,

I'm working on an interactive-book about drawings and I really need a magnifying glass in order to allow the readers to magnify the drawings.
This module looks pretty good for my purpose but I couldn't use it so far... I don't know what's wrong :sad:

I followed the example written in the script's Header and I didn't get any error message, the magnifying glass sprite appeared but there's no zoom effect and actually the sprite covers the background.

Does anybody know why? I'm using the last AGS version (3.3.0). Can that be a possible reason? What should I do in this case?

Thank you

SMF spam blocked by CleanTalk