Hi guys,
I got this to work "all by myself" with no help (hey, dont laugh, Im learning!) and Im pretty proud about it... 8)
I wanted my mouse cursor to change graphics when its clicked...for example, when Im in Interact Mode, when Im over a hotspot, the hand cursor animated showing me its a hotspot...and when I click on a hotspot, object or character, the mouse changes to a closed hand. When you release the click, the hand cursor just goes back to normal.
In "rep_exec":
//If the mouse cursor was changed during a click animation, change it back to default
if(!mouse.IsButtonDown(eMouseLeft))
{
if (mouse.GetModeGraphic(eModeInteract)==628)
{
mouse.ChangeModeGraphic(eModeInteract, 199);
}
}
In "on_mouse_click":
//if the mouse has been clicked, change the cursor graphic to show its clicked
if (mouse.IsButtonDown(eMouseLeft))
{
if (mouse.Mode == eModeInteract)
{
if ((GetLocationType(mouse.x, mouse.y) == eLocationObject) || (GetLocationType(mouse.x, mouse.y) == eLocationHotspot) || (GetLocationType(mouse.x, mouse.y) == eLocationCharacter))
{
//Display ("HandAnim");
mouse.ChangeModeGraphic(eModeInteract, 628);
}
}
}
Only problem, it works ok objects...but not for characters or hotspots...
What did I do wrong?
**EDIT**
It seems that since the object disappears once you click the hand on it, it must be doing something to enable everything to work like I wanted...I think my problem is there (something to do with the object no longer there makes it work upon the mouse click).
**EDIT PART 2**
Ok I think I solved it:
1) In on_mouse_click, I disabled the animation in the cursor:
//if the mouse has been clicked, change the cursor graphic to show its clicked
if (mouse.IsButtonDown(eMouseLeft))
{
if (mouse.Mode == eModeInteract)
{
if ((GetLocationType(mouse.x, mouse.y) == eLocationNothing))
{
mouse.ChangeModeGraphic(eModeInteract, 630);
}
else if ((GetLocationType(mouse.x, mouse.y) == eLocationObject) || (GetLocationType(mouse.x, mouse.y) == eLocationHotspot) || (GetLocationType(mouse.x, mouse.y) == eLocationCharacter))
{
mouse.ChangeModeView(eModeInteract, -1);
mouse.ChangeModeGraphic(eModeInteract, 628);
}
}
}
2) In rep_exec I enabled the animation once again:
//If the mouse cursor was changed during a click animation, change it back to default
if(!mouse.IsButtonDown(eMouseLeft))
{
if ((mouse.GetModeGraphic(eModeInteract)==628) || (mouse.GetModeGraphic(eModeInteract)==630))
{
mouse.ChangeModeView(eModeInteract, 24);
mouse.ChangeModeGraphic(eModeInteract, 199);
}
}
I noticed there is a "Mouse.GetModeGraphic", is there something similiar for the modeView...something like "Mouse.GetModeView"??
If not, we should have that feature added !
Why is this necessary:
if ((GetLocationType(mouse.x, mouse.y) == eLocationObject) || (GetLocationType(mouse.x, mouse.y) == eLocationHotspot) || (GetLocationType(mouse.x, mouse.y) == eLocationCharacter))
If you want to ensure that there's an available interaction where the player is clicking, just use IsInteractionAvailable(x,y,eModeInteract).
Hey discordance,
Wasnt aware of that function...much shorter than what I was using...
Thanks!
Also, using the same coding concept as what you were already using, it would be much simpler to store the location type in a variable. It's probably even faster than requesting the engine to perform the check against the screen three times.
LocationType loctype = GetLocationType(mouse.x, mouse.y);
if ((loctype == eLocationObject) || (loctype == eLocationHotspot) || (loctype == eLocationCharacter)) {
// ...
}
Or even simpler yet:
if (GetLocationType(mouse.x, mouse.y) != eLocationNothing) {
// ...
}
And looking at your edits, you're already performing a check to see if the LocationType is eLocationNothing. So the secondary if-statement with all the checks to the other types of locations is redundant. Just use an else-clause instead:
if (GetLocationType(mouse.x, mouse.y) == eLocationNothing) {
// wasn't over a character, hotspot, or object
}
else {
// was over a character, hotspot, or object
}
;)
Ok, this is even better...much simpler!
Ive got everything working just nicely, except now Im trying to get it to work for the inventory cursors...(sigh, theres always somethin')...
I was able to check "is cursor over a hotspot, object or character" for the normal gameplay cursors, but now for inventory items I can no longer use that function...Im guessing something like this I would have to do (?):
"InventoryItem *item = InventoryItem.GetAtScreenXY(mouse.x, mouse.y);
if (item == null)
{
//mouse isnt over an inventory item, dont animate mouse cursor...
}
else
{
//mouse IS over an inventory item, animate mouse cursor...
}
...but Im not too sure how to proceed. Im trying though :P...
I just want AGS to check if the mouse cursor (and custom mode) I have is over an inventory item...if it is, animate the cursor, if not, do nothing.
Right now I cant get it to work like I did for the "normal" gameplay cursors.
Also, "mouse.IsButtonDown(eMouseLeftInv)" doesnt work...it only works with eMouseLeft or eMouseRight...so how am I supposed to check if the left mouse button is pressed over (or not) while in the inventory?
Regarding your code for checking for inventory items under the cursor that seems correct.
However, I forgot to mention previously, why are you using mouse.IsButtonDown in on_mouse_click? The on_mouse_click function takes (and by takes I mean receives :P) a MouseButton parameter which will allow you to check which mouse button registered the click.
Also AFAIK mouse.IsButtonDown only works with eMouseLeft/eMouseRight because it checks the raw state of the buttons. So even if it's over an inventory item it should still register the button being held down (I believe).
But since you said you're doing this in on_mouse_click, use the MouseButton parameter already supplied:
// on_mouse_click
//if the mouse has been clicked, change the cursor graphic to show its clicked
if ((button == eMouseLeft) || (button == eMouseLeftInv))
{
// ...
}
Hey guys!
Ive still been trying to get this to work without success, arrrrggg!!
In normal gameplay, the cursors only animate when they are over a character or hotspot...I want the same thing to happen when the inventory is open, but instead of the cursor animating when its over a hotspot or character, Id like it to animate only when over an inventory item.
The problem with this is for the normal gameplay, I can set in the cursor properties "animate over hotspot", but there is no function "animate over an inventory item"...know what I mean?
So this is what I tried as a workaround, it kind of works, but the animation is looped super super fast when over an inventory item...how can I correct this super fast view animation? (probably cause its in repedeatly execute, :P)
I placed this in my rep_exec:
if (gInventory.Visible)
{
InventoryItem *item = InventoryItem.GetAtScreenXY(mouse.x, mouse.y);
if (item == null)
{
//dont animate the cursor since the mouse isnt over an inventory item
//reset normal views to cursors
if (mouse.Mode == eModeSelectInv)
{
mouse.ChangeModeView(eModeSelectInv, 0);
mouse.ChangeModeGraphic(eModeSelectInv, 571);
}
}
else
{
//animate the cursor since the mouse is now over an inventory item
if (mouse.Mode == eModeSelectInv)
{
mouse.ChangeModeView(eModeSelectInv, 25);
}
}
}
Test this out, and youll see what I mean, the cursor anim is super whacked-out! Any ideas to the solution....Ive ripped my hair out trying to fix this by myself...argggg
It seems to me that the problem lies in the fact that you are setting the view for the cursor mode on every loop (when the cursor is over an inv item).
I think you should first get the view for the cursor mode, and set it to 25 only if it is not already 25.
I think that every time you set the view it will start the animation from the beginning and that will make it look quirky...
Hi tzachs,
Ok I tried the solution with a variable. I get no errors, and testing it with a display message to debug also works...but the speed it still very fast (I tried changing the loop's frame delays, but that doesnt change anything).
Still stumped ???
Ill try some more things out and post if I find anything :P