Icons Pop up Over Player's Head

Started by Stranga, Thu 03/11/2016 08:22:44

Previous topic - Next topic

Stranga

Hello everyone!

I have yet another question, though this one is more of a figure out how to do it type.

I want to add a small pop up animation over the players head when the cursor is over an object. The reason I want this effect is to remove the objects name to create more of a search and explore kind of feel.

I've made a mock up image of what I want it to look like but my problem is I have no idea on which way I should make it.


Any help would be greatly appreciated!

Khris

#1
Use a GUI for that. When the mouse moves over an active area, position the GUI and turn it visible. When the mouse moves away, turn it off again.

Here's how to track what's under the mouse:
Code: ags
bool wasActiveArea = false;
function mouseUpdate() {
  bool isActiveArea = GetLocationType(mouse.x, mouse.y) != eLocationNothing;
  if (isActiveArea && !wasActiveArea) {
    // mouse just moved over an active area
    gExclam.SetPosition(player.x - 2, player.y - 40);
    gExclam.Visible = true;
  }
  else if (!isActiveArea && wasActiveArea) {
    // mouse just moved off an active area
    gExclam.Visible = false;
  }
  wasActiveArea = isActiveArea;
}

Now put that code somewhere above your GlobalScript's repeatedly_execute, then call the function inside it.

I just noticed that in case the player is walking and the user moves the mouse over an active area, the pop up will remain where it first appeared.
What you can do instead of a GUI is use another character that follows the player closely. To make sure it's always in the same room, add this to the GlobalScript:
Code: ags
function on_event(EventType event, int data9) {
  if (event == eEventEnterRoomBeforeFadein) {
    cExclam.ChangeRoom(player.Room, 0, -1); // move to current room but out of sight
  }
}

Now simply use cExclam.FollowCharacter(player, FOLLOW_EXACTLY, 0); to turn on the popup.

On the other hand, if you don't want the popup to remain but animate for a few frames them disappear again, use the first approach, put a button on the GUI and animate it, the turn it off again (using a Timer).

Edit: fixed code

Stranga

Hey thanks for the response! This is neat! I will try it and let you know how it goes!

SMF spam blocked by CleanTalk