Dynamic Draw and reuse of a view sprite **SOLVED**

Started by Knox, Mon 18/10/2010 12:45:58

Previous topic - Next topic

Knox

Ive been doing an optimization pass recently on various things, and one of them I put on my "to-do" list consists of optimizing the way my cursor highlight system uses sprites.

Right now when my cursor is over an object, character or hotspot, it will play an animation from a view that loops. Ive made a different view for each cursor type, and now realize I could save sprite room if I just drew that animation under the current cursor's sprite. The current sprite also has a small animation, but its timing is different than the animation that is underneath...for example:

The look cursor gets a small animation of the eye blinking, while underneath that cursor there is a looping animation of a "storm cloud" moving/swirling around.

Ive got a vague idea how I can manage to just use 1 view of the looped cloud anim for every possible cursor I might have, even to be used for any inventory item aswell! (That would save me loads of views, sprites, and time!)

Could someone perhaps give me a nudge in the right direction? :)
--All that is necessary for evil to triumph is for good men to do nothing.

GarageGothic

I don't have any experience with the built-in icon animation (I don't think it was implemented when I coded my cursor modes, so I animate them in rep_exec), but what you could do is either 1) animate the storm cloud on a GUI underneath the cursor and update the gui coordinates to align with the mouse coordinates every loop, you will see a bit of lag/misalignment on fast cursor movement though. Or 2) Use a DynamicSprite to composit the cursor graphic. In rep_exec redraw it when the the animation frame changes (use a timer to set speed). I'd go with the second option myself.


Knox

hmm ok, I think Ill go with the 2nd option aswell...although your idea to use a GUI under the cursor sounds way way easier...I think Ill try that too, just to see :P

Ill see what I can do!

thanks GarageGothic (again) :)
--All that is necessary for evil to triumph is for good men to do nothing.

Knox

Ok, well I decided to create a GUI under the cursor for starters, to see if this works first before trying your 2nd suggestion (the dynamic drawing).

What I have now (to test) is my gui becomes visible when the cursor is over an object, hotspot or character...if that gui is visible, animate it (the storm loop view). I commented out the part where I update the gui's coordinates to take the current position of the mouse cursor because its acting "buggy" with those lines...it updates over and over again making that gui flicker...

...how should I update the coordinates of the GUI so its always under the mouse cursor without having it buggout? (For example, with those 2 lines I can no longer right-click to switch mouse modes, and I have a label that no longer updates its text to tell me what my mouse is over)...Im not sure how to do this part.

REP EXEC:
Code: ags
  
if (mouse.Mode == eModeLookat || mouse.Mode == eModeInteract || mouse.Mode == eModeQuestion || mouse.Mode == eModeCommand)
  {
    if (locType != eLocationNothing)
    {
      //move GUI to cursor position
      //if (gCursorStorm.X != mouse.x) gCursorStorm.X = mouse.x;
      //if (gCursorStorm.Y != mouse.y) gCursorStorm.Y = mouse.y;
      if (gCursorStorm.Visible == false) gCursorStorm.Visible = true;
    }
    else
    {
      if (gCursorStorm.Visible == true) gCursorStorm.Visible = false;
    }
  }
  if (gCursorStorm.Visible && !gCursorStorm.IsAnimating())
  {
    gCursorStorm.LockView(75);
    gCursorStorm.Animate(0, 5, eRepeat, eNoBlock);
  }
  else if (!gCursorStorm.Visible && gIconbar.IsAnimating()) gCursorStorm.UnlockView(false);  
--All that is necessary for evil to triumph is for good men to do nothing.

GarageGothic

Try setting the cloud GUI to non-clickable, I'm guessing the GUI is catching the click.

Knox

Awesome...placed it to non-clickable and it works!

Is there a way to "query" the current mouseMode's hotspot? Im aware of HotspotX and HotspotY...but it seems there is only "ChangeModeHotspot"...and not "GetModeHotspot" (for X and Y)...how could one get this information?

Actually, what would be better is how to get the real center of the current cursor mode's sprite with the SpriteWidth + SpriteHeight commands?
--All that is necessary for evil to triumph is for good men to do nothing.

Khris

This should do it:

Code: ags
  int slot = mouse.GetModeGraphic(mouse.Mode);
  int x = Game.SpriteWidth[slot]/2;
  int y = Game.SpriteHeight[slot]/2;

Knox

Yup, perfect!

Saved (no kidding) approx 400 sprites (40 sprites x 10 modes) :)
--All that is necessary for evil to triumph is for good men to do nothing.

SMF spam blocked by CleanTalk