Adventure Game Studio

AGS Support => Advanced Technical Forum => Topic started by: Oncer on Fri 06/05/2005 21:26:39

Title: Iterate through Objects and Hotspots
Post by: Oncer on Fri 06/05/2005 21:26:39
I want to add the following feature to my game:
If the player holds F10, there is a blinking symbol at the position of every object/hotspot the player can interact with.
I've made a small script for this in the repeadedly_execute section:

while (IsKeyPressed(368)) //F10, blinking circles
    {
      RawSaveScreen();
      int i=0;
      while (i<GetGameParameter(GP_NUMOBJECTS,0,0,0))
      {
        if (IsObjectOn(i))
        {
          RawSetColorRGB(255,255,255);
          RawDrawCircle(GetObjectX(i),GetObjectY(i),3);
        }
        i++;
      }
      Wait(5);
      RawRestoreScreen();
      Wait(5);
    }


Here comes my problem. I want the circle at the exact position of the object, not at the top-left corner of the object sprite. The (horizontal and vertical) centre of the object would be perfect. And how could I do the same for the hotspots in a room? I can't even get the position of the hotspot area, and I don't want to waste my walk-to points for this   :(

Anyone here with a solution?

Oncer
Title: Re: Iterate through Objects and Hotspots
Post by: Pumaman on Sat 07/05/2005 11:39:31
For objects, you can use GetGameParameter(GP_SPRITEWIDTH) and GetGameParameter(GP_SPRITEHEIGHT)  to calculate the centre of the object.

For hotspots, there is no "centre", because hotspot shapes can be all over the place, and it wouldn't really make sense to try and work out a centre for them. You could use the walk-to points for this purpose, assuming you're not actually using them for anything else.
Title: Re: Iterate through Objects and Hotspots
Post by: Oncer on Sat 07/05/2005 17:12:09
I fully understand why hotspots haven't got coordinates. But I need the walk-to points as walk-to points  ;D.

Is there any other possibility? Using objects instead of hotspots is probably a bad idea. Making a list with coordinates for each hotspot, OTOH, is very much work  :-\.

Any idea?
Title: Re: Iterate through Objects and Hotspots
Post by: Ashen on Sat 07/05/2005 17:15:39
Use Properties? You'll still have to set them by hand for each hotspot, but it'll be a lot easier to access them in script.
Title: Re: Iterate through Objects and Hotspots
Post by: Oncer on Sat 07/05/2005 17:21:08
You mean Room Properties?

E.g.

Hs1X 239
Hs1Y 40
Hs2X 112
Hs2Y 30
Hs3X 70
Hs3Y 20


Hmm... I believe this is the best solution if I don't use the walk-to points. I'll ask my project leader if he really wants this feature  ;)
Title: Re: Iterate through Objects and Hotspots
Post by: Ashen on Sat 07/05/2005 17:30:39
I don't understand that - are you talking about using ints for each hotspot?
That would work, I suppose, but what I meant was - you can give every hotspot ( and every object, inv item, character, but that's not important right now) its own 'Custom Properties'. Look up 'Properties' and GetHotspotProperty () in the manual, for a better description.

Title: Re: Iterate through Objects and Hotspots
Post by: Oncer on Sat 07/05/2005 17:37:00
Aww... I thought way too complicated. Now it's clear to me, but I've also experienced another problem!
The blinking circle looks perfect on hotspots, but it is drawn "behind" the objects! The reference manual says 
Quote from: ManualNOTE: The Raw functions always draw onto the current background frame only.

What can I do about that?

EDIT: And how can I get the Clickable-Attribute from an Object? I only want to display the icon on objects the player can interact with!
EDIT2: Is there any way to get the number of hotspots in a room? Or should I iterate through all 30 hotspots every time. This isn't a good solution for me because the max. number of hotspots could change in future AGS releases...
Title: Re: Iterate through Objects and Hotspots
Post by: Pumaman on Sat 07/05/2005 18:50:11
You won't be able to make any raw drawn stuff appear in front of objects. You might find you need to create an overlay and place it on top of the object.

QuoteEDIT: And how can I get the Clickable-Attribute from an Object? I only want to display the icon on objects the player can interact with!

Just use  object[X].Clickable  (AGS 2.7 only, not supported in 2.62)

Quote
EDIT2: Is there any way to get the number of hotspots in a room? Or should I iterate through all 30 hotspots every time. This isn't a good solution for me because the max. number of hotspots could change in future AGS releases...

There is currently no way to get the number of hotspots, simply because AGS doesn't actually store this information itself. As far as AGS is concerned, there are always the maximum number of hotspots in each room, it's just that there's no actual hotspot area for any that are not in use.

You can use the AGS_MAX_HOTSPOTS constant to reflect the maximum number supported by AGS, if that helps.
Title: Re: Iterate through Objects and Hotspots
Post by: Oncer on Sat 07/05/2005 21:06:48
Quote from: PumamanYou can use the AGS_MAX_HOTSPOTS constant to reflect the maximum number supported by AGS, if that helps.
Yes, that helps  :D

Now, what about my other problem?
Quote from: OncerThe blinking circle looks perfect on hotspots, but it is drawn "behind" the objects! The reference manual says
Quote from: ManualNOTE: The Raw functions always draw onto the current background frame only.
What can I do about that?

What I want is to display a blinking icon on top of each object (and hotspot). But if there is an object, the raw functions draw behind it (on the background frame).

EDIT: Oh, sorry, you have answered that question too, thanks!
[quote="Pumaman]You won't be able to make any raw drawn stuff appear in front of objects. You might find you need to create an overlay and place it on top of the object.[/quote]
Yeah, an overlay probably is a good idea!