Synching sinchronised animations.

  • #1, by bananeisafreeWednesday, 08. June 2016, 15:32 8 years ago
    Hi everyone.
    This is not a vital problem for our game, more of a free thinking idea, and I was wondering what you guys might imagine:

    Ok, here is the theory :

    You move your cursor to an item area, that changes the item to have a glowy border around it.
    Basicly you just change a condition and show a new image that goes on top of your item. easy peasy.

    But what if you want to do the same with an animation ?
    You would need two sets of animations, one with your object/character in 'un-selected' mode, and one set of animations that would have the glowy boreder. Again, fairly simple. But in order for the trick to be as beautifull as possible, We need a way to make sure that when we mouse over the item/character, the glowy animations starts where the standard one left. same thing when we leave the object/character area.

    to put it simply, if we have two sets of 4 frames animations (named 1,2,3,4 and 1g(for glowy), 2g, 3g and 4g.
    if the character is at frame 3 when we mouse over, we want 3g to be the starting point of our new loop.


    I'm not really good at creating scripts yet (I manage to read it, decode it and modify it ... with time) , So I can't really give you a backbone to chew on right now. (will do though when I got the time)
    But I think a good way would be to use the "SetAnimFrames" script found https://wiki.visionaire-tracker.net/wiki/SetAnimFrames_(CMS) to set the new animation cycle.
    But I did not found on the wiki a way to check wich frame is playing on an animation at a given moment.

    Any imput would be fantastic!
    Cheers

    Forum Fan

    120 Posts


  • #2, by ke4Wednesday, 08. June 2016, 15:40 8 years ago
    You can't have 2 animations for your item, so you would have to have one animation that would contain both of the versions and then you would set that it's supposed to loop only the first half of frames in the animation and if you would hover the item it would loop the other half.

    You can check what is the current playing frame and then run the second animation - if you are on the 10 frame of the first animation you would start the loop of the second animation on "10" frame of the second.

    ActiveAnimations[name].AnimationCurrentSpriteIndex
    

    This will return the current frame.

    Key Killer

    810 Posts

  • #3, by bananeisafreeWednesday, 08. June 2016, 16:03 8 years ago
    Thank you for your awnser !

    You can't have 2 animations for your item

    I don't really get it. Can't I just change the active animation of an item ?
    Or simply have two items, one of wich is associated to an if condition that switches with "entering/leaving object area" ?
    (it's a real question, I feel like I'm missing something).

    Because If I say as you reccomend. then I won't be abble,I think, (but again, I'm usualy wrong) to use the SetAnimFrames function proprely.

    for a 2x10 frames animation for example, if I stop the animation at 3. that means I have to start the second at frame 13. but, when it reaches frame 20 how do I tell him to skip frame 1 to 10 in order to have it loop at frame 11?
    (I don't know if I make myself clear :p sorry)
    I mean I guess I could go with some kind of conditions checking, that would redefine the animation first and last frame when it reaches frame 20. But still, if I can just switch animation it would save (I think) somme code and energy

    Thank you for the bit of code regarding the frame checking !
    That is (I think) exactly what I was looking for.
    Now I have to test around !

    Forum Fan

    120 Posts

  • #4, by ke4Wednesday, 08. June 2016, 16:16 8 years ago
    The thing is that you can have only one animation for your item. There's no active / in-active tab. That's why you have to be setting which frames to loop. But since you want this feature to start on the frame where you left, i believe it would start always from the beggining if there would be an active / in-activate tab anyway.

    If you have 2x10 frames animation.
    I'm not sure, haha. If you are on 3 frame you would set.
    setAnimFrames("Name", 13, 20)

    I don't know without testing if you can set the first frame of the loop without skiping there right after this line of code. That would be one way to do it.

    Key Killer

    810 Posts

  • #5, by afrlmeWednesday, 08. June 2016, 16:28 8 years ago
    You can't have 2 static images, but you can have as many animations listed inside of a single scene object, you mean @ Ke4. You can only play one animation at a time.

    He's right that you can return the current frame index value, so you could store that current value inside of a value or variable on mouse over / out then instantly hide & show the other animation & then set the frame for the animation you just started.

    The code line that Ke4 shared can also be set by adding an = x to the end of it, so let's say you added the current frame index value to a global variable called "ani_indx"...
    ActiveAnimations["test"].AnimationCurrentSpriteIndex = ani_indx
    

    Imperator

    7278 Posts

  • #6, by ke4Wednesday, 08. June 2016, 16:33 8 years ago
    Really? How can you add more than one animation to an item?

    Key Killer

    810 Posts

  • #7, by afrlmeWednesday, 08. June 2016, 16:35 8 years ago
    Oh right yeah items... was thinking of scene objects. My bad. grin

    It would be nice if they simply removed the static image bit & replaced it with active & inactive animations like the mouse cursors instead.

    If I remember correctly, there's also no mouse over / out actions for items either is there?

    Imperator

    7278 Posts

  • #8, by ke4Wednesday, 08. June 2016, 16:45 8 years ago
    So with what you have written it could work like that? While it returns 3 frame of 2x10 animation.

    setAnimFrames("name", 10, 20)
    ActiveAnimations["name"].AnimationCurrentSpriteIndex = 13
    


    no there's not.. it needs to be done through loop. Store current items and check for a match.

    items = game.CurrentCharacter.Items
    for i = 1, #items do
    if game.CurrentObject:getName() == items[i]:getName() then
    


    It would be really handy if there would be active / in-active option for items.

    Key Killer

    810 Posts

  • #9, by afrlmeWednesday, 08. June 2016, 16:55 8 years ago
    I'll speak to Simon about active / inactive animations section. I believe I already mentioned it to him a while back, but I forget.

    Yeah, you need to iterate through items to restore them after mouse leaves, at least that's what I did for when I tested having items scale on mouse over. I didn't use a loop though, I opted for mouse event & each time mouse moved I checked if current item didn't = last item & if not then we reset all current items to the default scale value & if the new value didn't return nil then we scaled up the item under the cursor. I don't know if I added that example to the wiki or whether it was just in a thread on this forum.

    I always prefer to use states over loops as they save on precious resources, compared to having something queried / executed a boat load of times every millisecond.

    As for using the same animation... you could do the value by checking if it's above or below a certain value. If it falls in the first part of the animation then you simply double add the max amount of frames of the animation to it, so if the animation was 10 frames for inactive state & 10 for active state then you would take the current value & add 10 to it. You would do the opposite if the value was higher than 10.

    I foresee a slight looping issue when combining multiple animations inside of a single animation, but that's easily remedied by adding adding a line of code to make to the last frame of each animation to make sure it loops back to the intended first frame of said animation.

    Imperator

    7278 Posts

  • #10, by bananeisafreeWednesday, 08. June 2016, 16:57 8 years ago
    Ok I'm the douche induncing everyone in error.

    I'm french, and object and items usualy translate the same way (at least for me), I tend use the french word "objet" for both, even though I percieve the difference.

    I was mainly thinking about scene objects. And indeed you don't have the ability to have more than one animation for items, wich is kind of sad when you think of it. (if you had a scanner of some sort in your inventory that would change depending on where you are or what your cursor is hovering ... I guess it can be done in another way though. or a compas in a first person "à la myst" adventure).

    But yes, with the AnimationCurrentSpriteIndex, I can kind of imagine where to go in order to get the desired effect, at least for characters and scene objects.

    (in other words, You guys rock !!)

    Forum Fan

    120 Posts

  • #11, by ke4Wednesday, 08. June 2016, 17:00 8 years ago
    That's what i have in my game. I have hidden inventory, when i'm opening it i'm registering loop and unregistering it on closing the inventory again. I don't really understand the concpet you are mentioning, this is the script i wrote.

    local items
    
    function scaleItem()
    items = game.CurrentCharacter.Items
    for i =1, #items do
    	if game.CurrentObject:getName() == items[i]:getName() then
    		if  ActiveAnimations[items[i]:getName()].AnimationCurrentSpriteIndex < 4 then	
    			setAnimFrames(items[i]:getName(), 1, 5)
    		else
    			setAnimFrames(items[i]:getName(), 5, 5)
    		end
    	else
    		if ActiveAnimations[items[i]:getName()].AnimationCurrentSpriteIndex > 0 then
    			ActiveAnimations[items[i]:getName()].PlayOppositeDirection = true
    			setAnimFrames(items[i]:getName(), 1, 5)	
    		else
    			ActiveAnimations[items[i]:getName()].PlayOppositeDirection = false
    			setAnimFrames(items[i]:getName(), 1, 1)
    		end	
    	end
    end
    end
    

    Key Killer

    810 Posts