Forum rules - please read before posting.

Change cursor icon from script

I have a trouble I can not solve.
I change the cursor icon (Cursor option in Inventory Manager) from script, while the cursor is in Selected Item the texture is single when over to another item or hotspot becomes animated.
The problem is that the texture does not enter in animation even though Inventory Manager shows the check on Animate.
But if I temporarily remove my script and I set directly the cursor as animated it works regularly, so I reactivate my script and the icon this time is animated as it should be.
If I close and I re-open unity again no animation.
It would seem like an internal update problem or cache.

In EventManager.OnMouseOverMenu I do:

KickStarter.runtimeInventory.SelectedItem.cursorIcon.ClearCache ();
KickStarter.runtimeInventory.SelectedItem.cursorIcon.ClearSprites ();
KickStarter.runtimeInventory.SelectedItem.cursorIcon.texture = KickStarter.cursorManager.GetCursorIconFromID (iconTargetOver) .texture;
KickStarter.runtimeInventory.SelectedItem.cursorIcon.isAnimated = true;
KickStarter.runtimeInventory.SelectedItem.cursorIcon.numFrames = 2;
KickStarter.runtimeInventory.SelectedItem.cursorIcon.numRows = 1;
KickStarter.runtimeInventory.SelectedItem.cursorIcon.numCols = 2;
KickStarter.runtimeInventory.SelectedItem.cursorIcon.animSpeed = 2;




Comments

  • What is it you're trying to do, exactly?  Inventory cursors should already only animate when over another item / Hotspot.

    But rather than changing the isAnimated bool at runtime, try just setting up the "still" cursor as a 1-frame animation, so that all you need to do is change the frame settings.
  • edited November 2017
    What is it you're trying to do, exactly? 

    I have 5 states for inventory items:

    image

    The last two change together when a selected item is over to another item and the cursor should be animated.
    But the problem is that the initial cursor (optional) has a different texture from the second because it is without the gear and the green border.
    I can not use your suggestion to show just a frame.
    When at runtime I change Active graphic there are no problems but the Cursor (optional) would seem to not accept the change of icon or Animate field. To be precise, they change in Inventory Manager but the cursor in the game does not change the texture or does not animate.
    For the time being I solved by changing the initial Cursor (optional) icon with two identical frames and I can leave the animated field always selected.

    image

    Your code only shows the first frame when the cursor does not have to be animated and at runtime I change this texture with Cursor (optional) 2 when the cursor is over to an item or hotspot.
    It's always your code to activate the animation.
    However, I need to use ClearCache () before exchanging textures otherwise the icon does not change.
  • edited November 2017
    In that case, it looks like a "Skip first frame when looping animation" option would be beneficial - since you can make cursors only animate when over another item, it would then play frames 2 & 3 of a 3-frame animation.

    Whether you have one-frame or two, that's basically what I was getting at - so that you can leave the animated field selected always.
  • It would be ideal. 
    But I did not understand if this option already exists or if you plan to realize it in the future. I do not find it in the editor or in the scripting guide.

  • It doesn't yet, but I'll add it.  This is why it's important to explain the core of what you're trying to achieve - as opposed to just asking how to achieve the solution you've decided for it.
  • Thanks Chris, I saw that you added this option in the new 1.60.2 update.
    This way I can remove the cursor change at runtime, less lines of code less risk of bugs.

      This is why it's important to explain the core...
    I understand it but I also think that you have to do more important things than these finesses.
    I do not know how many people will benefit this option, which is why I try to do it on my own.
    Thanks again.
  • Hi Chris, I would like to inform you of a detail, Animation starts a moment after the item is over on the other item while transition from animation to single frame is instantaneous.
    I have tried to compare it with the response times of my code and it looks like there is a "moment of reflection" before the animation starts with Skip first when looping.
    I think it's a small thing, if you do not have time to check it out can you tell me which part of the code to look at?
  • The first frame of the animation will still play before the loop is complete - that's probably what you're experiencing.

    If so, you'd want to look in the GetAnimatedRect (first instance) function inside CursorIcon, though I'll look into it as well.
Sign In or Register to comment.

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Welcome to the official forum for Adventure Creator.
Do NOT follow this link or you will be banned from the site!