Iterate through Objects and Hotspots

Started by Oncer, Fri 06/05/2005 21:26:39

Previous topic - Next topic

Oncer

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

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

Pumaman

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.

Oncer

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?

Ashen

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.
I know what you're thinking ... Don't think that.

Oncer

You mean Room Properties?

E.g.
Code: ags

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  ;)

Ashen

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.

I know what you're thinking ... Don't think that.

Oncer

#6
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...

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.

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.

Oncer

#8
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!

SMF spam blocked by CleanTalk