Look through Key Hole - Display image

Started by larsselleth, Fri 21/08/2015 11:53:07

Previous topic - Next topic

larsselleth

Hi, long time reader, first time poster.

    I have the basics of making a game. I can create it, move from one room to another, pick up/look at objects blah blah blah.

What I really want to do next is my character looks through a key hole and see's what is on the other side of the door. And I will be damned im I can figure this out. I have put the image of the room in the sprites section but I cannot work out the command to display the image for x seconds before reverting back to the playable "room"

Any help would be greatly appreciated

I really hope this isnt the simplest question y'all have had.

Regards,
Lars

Khris

You can use a graphical overlay, or a GUI.

An overlay is probably the easiest way:
Code: ags
  Overlay *keyhole = Overlay.CreateGraphical(20, 20, keyholeview_spriteslot, true);
  Wait(GetGameSpeed() * 3); // 3 seconds
  keyhole.Remove();

larsselleth

Excellent.

Many thanks for your reply, I will give it a whirl tonight.

Very kind regards,
Lars

larsselleth

And here comes my lack of understanding.

My keyhole is an object called oKeyhole. It is image 39 in a sprite subfolder called objects. The image I want it to display is image 40 in a sprite subfolder called rooms (I dont think the subfolder matters but I am trying to provide as much info as possible)

I have tried to find information on the overlay command but I am not coming up with much. I dont want you all to think I am abusing your kind nature in helping me. I have written the command ;

Overlay oKeyhole = Overlay.CreateGraphical(20, 20, oKeyhole_40, true);
  Wait(GetGameSpeed() * 3); // 3 seconds
  oKeyhole.Remove();

Any help is greatly received. And apologies for being a noob.

Lars

Snarky

If what you need to display on the screen is a combination of two sprites (a room image and a black screen with a keyhole-shaped hole in it, or something like that), it gets a little more complicated. Some options:

-Pre-combine them into one sprite in an image editor, and simply display that like Khris explained
-Use rawdraw commands to draw first one, then the other to a new dynamic sprite (slightly complicated)
-Display two overlays at the same time, one on top of the other

If I'm misunderstanding you, could you post the two sprites and how you want it to appear in the game so we can see what you're talking about?

larsselleth

Hi Snarky.

Firstly, thanks for your reply.

I dont want anything as complicated as a key hole image over a background, just a command to look at the key hole, my character walks over, looks at the keyhole which then shows an image of the room behind the door :)


Snarky

#6
Oh right, I think I see your confusion.

The "keyhole object" oKeyhole is just the thing you click on to make the character look through the keyhole? In that case, it's completely irrelevant to the problem. The only thing that matters is the graphic you actually want to display, and you should make sure you don't confuse "the overlay where we display the graphic that shows the view through the keyhole into another room" (let's call it keyholeView) with "the object that represents the keyhole for purposes of interacting with it in the room" (oKeyhole).

So this line is wrong:
Overlay oKeyhole = Overlay.CreateGraphical(20, 20, oKeyhole_40, true);

What you're actually doing here is to define a new overlay (a graphic displayed on the screen) that has the same name as the object oKeyhole that already exists. You should never try to define two different things with the same name that exist at the same time: either it won't compile and run, or it will lead to bad bugs. Also, oKeyhole_40 isn't a thing, you can't use that as an argument. You need to just take the number of the sprite you want to display, in this case 40.

So what you should do instead is something like:

Code: ags
Overlay* keyholeView = Overlay.CreateGraphical(20,20, 40, true);
Wait(GetGameSpeed() * 3); // 3 seconds
keyholeView.Remove(); // Note the same name!


Notice also the * after Overlay in the first line. That's important (it means that keyholeView is a pointer: you don't have to understand what that means, just remember that you have to use it for some things). Some people, like Khris, put the space before the *. It works either way, but IMO it makes much more sense to have the * as part of the type rather than the variable name.

Now, to make this run is where oKeyhole comes in. You probably want to add it as an OnClick (or OnInteract or whatever) handler for that object. So go into the oKeyhole events (in the room editor), and select the event you want. It should generate a new function for you that is called something like oKeyhole_OnClick(). Put the code inside that function.

larsselleth

Snarky/Khris
  Thank you so much for your assistance. I have got it to work now. I used the code from you guys but had the keyhole as a hotspot instead of an object and it worked a treat.

Many thanks

:cool:

SMF spam blocked by CleanTalk