move mouse over object, view-animation does not work properly

Started by onizuka666, Sun 02/02/2014 16:37:03

Previous topic - Next topic

onizuka666

Hey guys,

I have a delicate problem here:

After I used,
function repeatedly_execute()
{
   Object *obj = Object.GetAtScreenXY(mouse.x, mouse.y);
   if (obj != null)
   {
     // set new mouse mode until mouse leaves object
      Mouse.SaveCursorUntilItLeaves();
      Mouse.Mode = eModePickUp;
   }
}
which worked in principle to make my cursor to change its appearance while moving over an object to the pick up-cursor,
it appeared that the pickUp-curser was flickering permanently.

It turned out that using this congiguration, my pick up-cursor switched between my view-animation loop I created, and the image which I set for the pick up-cursor.
Finally when testing the game it looks like this: when I move the curser over an object, between every single sprite of my view-loop appears the image-sprite which I set up for my pick up-cursor (and this looks like a flickering).

I hope anybody has also experienced this problem and can help me with it!
Thanks in advance!


Khris

This is a very common problem; what happens is the condition keeps being true, and the code is executed 40 times per second (or whatever your GameSpeed is set to).

You want to use a variable to track the state of what's under the cursor and only run code when it changes.
Code: ags
// above rep_ex
int previousLocationType;

void UpdateMouseCursor() {
  int lt = Game.GetLocationType(mouse.x, mouse.y);
  if (lt != previousLocationType) {  // location type has changed as of this game loop
    if (lt == eLocationObject) mouse.Mode = eModePickup;
    else if (lt == eLocationHotspot) mouse.Mode = eModeInteract;
    else if (lt == eLocationCharacter) mouse.Mode = eModeTalkto;
    else mouse.Mode = eModeWalkto;
  }
  previousLocationType = lt;
}

  // inside rep_ex
  UpdateMouseCursor();

onizuka666

Thank you Khris!
That worked. I thought I would get nuts the last two days!

SMF spam blocked by CleanTalk