Problem(s) with Mouse Hotpoint in Room.

Started by C.T.C.B, Fri 03/05/2013 04:45:41

Previous topic - Next topic

C.T.C.B

I have this code:
[embed=425,349]
function hNewGame_MouseMove()
{
  oNewGame.Graphic = 5;
  AudioChannel* Click = aMenuClick.Play(eAudioPriorityNormal, eOnce);
  Click.Volume = 50;
}
[/embed]

My Problems:
1) When the mouse is moved over oNewGame, which is the New Game Button on the menu, the click happens each time the mouse moves a pixel, whereas I want it to only play once.

2) I want the Graphic of oNewGame to go back to how it was if the mouse is not over it.

Khris

#1
Empty your function, add the room's RepExec event, then use this:
Code: ags
Hotspot*old_h;

function room_RepExec() {
  Hotspot*h = Hotspot.GetAtScreenXY(mouse.x, mouse.y);
  if (h != old_h) {  // we have just moved over a hotspot or left one
    // new game
    if (h == hNewGame) {  // mouse moved over hNewGame
      oNewGame.Graphic = 5;
      AudioChannel* Click = aMenuClick.Play(eAudioPriorityNormal, eOnce);
      Click.Volume = 50;
    }
    else if (old_h == hNewGame) {  // mouse left hNewGame
      oNewGame.Graphic = 4;
    }

    // other buttons here

    old_h = h;
  }
}



(Also, just in case there are typos, try to fix them yourself this time using the manual and AGS's auto-complete feature :))

Edit: also, if you're going to use the same audio for all the buttons, the audio code can be typed once instead of separately for each button.
Just move it to
Code: ags
    if (old_h.ID == 0) {  // mouse left hotspot 0 (no hotspot)
      AudioChannel ...
      ...
    }

SMF spam blocked by CleanTalk