Thread: Animation tweening definition/example

Page 1 of 2 12 LastLast
Results 1 to 10 of 14
  1. #1 Animation tweening definition/example 
    Member Market Banned Market Banned

    Zee Best's Avatar
    Join Date
    Feb 2007
    Age
    29
    Posts
    3,036
    Thanks given
    24
    Thanks received
    210
    Rep Power
    1171
    Well, alot of people don't understand what "Animation tweening" means, so i decided to write a short but informative thread about what animation tweening does and how it can be usefull to us.

    When you have an animation it uses "frames", whether we are talking about 2D or 3D animation there are always these "frames" which drawn after each other create the illusion of animation.

    The basic animation system uses a frame for every movement of the character, however, by introducing "tweening" it is possible to add more smooth emotes with less "frames".

    Basically;

    Instead of using normal "frames", the animation would use "key frames" these frames would be used as the guideline for generating new frames and drawing them in between.

    Example;

    The following example i wrote for a simple 2D x, y based animation.

    Code:
    	public void drawAnimation()
    	{
    		Animation animation; // Let's assume this is already instanced, animation is our animation
    		long timeSince = 0;
    		int currentFrame = 0;
    		while (currentFrame < animation.frames.size())
    		{
    			if(animation.frames.get(currentFrame).delay <= (System.currentTimeMillis() - timeSince))
    			{
    				drawFrame(animation.frames.get(currentFrame).x, animation.frames.get(currentFrame).y);
    				timeSince = System.currentTimeMillis();	
    				currentFrame++;
    			}
    			Thread.sleep(animation.frames.get(currentFrame).delay);
    		}
    	}
    Whereas this would be an example of a basic tweening system;

    Code:
    	public void drawAnimation()
    	{
    		Animation animation; // Let's assume this is already instanced, animation is our animation
    		int currentFrame = 0;
    		int currentX;
    		int currentY;
    		while (currentFrame < animation.frames.size())
    		{
    			if(animation.frames.get(currentFrame).delay <= (System.currentTimeMillis() - timeSince))
    			{
    				drawFrame(animation.frames.get(currentFrame).x, animation.frames.get(currentFrame).y);
    				currentX = 0;
    				currentY = 0;
    				timeSince = System.currentTimeMillis();	
    				currentFrame++;
    			} else
    			{
    				int addX = ((animation.frames.get(currentFrame).x + currentX) > animation.frames.get(currentFrame + 1).x) ? currentX-- : currentX++);
    				int addY = ((animation.frames.get(currentFrame).y + currentY) > animation.frames.get(currentFrame + 1).y) ? currentY-- : currentY++);
    				drawFrame((animation.frames.get(currentFrame).x + addX), (animation.frames.get(currentFrame).y + addY));
    				int largest = (animation.frames.get(currentFrame).x > animation.frames.get(currentFrame).y ? animation.frames.get(currentFrame).x : animation.frames.get(currentFrame).y);
    				int sleepTime = (animation.frames.get(currentFrame).delay) / largest;
    				Thread.sleep(sleepTime);
    			}
    		}
    				
    
    	}
    Please note, the above code may not work, i just wrote it for an example.

    __

    As you can see, with the above to draw an animation with the old system you would have to have the frames like this;

    Code:
    frames.add(new Frame(0, 1, 0));
    frames.add(new Frame(0, 2, 20));
    frames.add(new Frame(0, 3, 20));
    frames.add(new Frame(0, 4, 20));
    frames.add(new Frame(0, 5, 20));
    frames.add(new Frame(0, 6, 20));
    frames.add(new Frame(0, 7, 20));
    Which would draw the dot going up from pixel 0,0 to 0,7, the delay for the movement would be every 20 milliseconds.

    Now, to do the same with the tweening system you would only have to do;

    Code:
    frames.add(new Frame(0, 1, 0));
    frames.add(new Frame(0, 7, 120));
    Now, the delay is 120, so devide that by the 5 frames we added plus the last frame itself and that is;

    120 / 6 = 20.

    Now, the tweening system would draw the exact same animation but using 2 "key frames" not 7 normal frames;

    Basically, what "key frame" means is a frame which is needed, it's a key part of the system.

    __

    How this relates to RuneScape;

    Basically, now instead of creating single frames which gives choppy animations, they can create frames and let their client generate the rest of the frames, this means less data is needed to preform the task and less effort.

    If anyone wants any more information feel free to ask.

    I might right a system to work with the 317 client if i get time.


    [Only registered and activated users can see links. ]
    Reply With Quote  
     

  2. #2  
    Member

    Join Date
    Jun 2009
    Age
    27
    Posts
    432
    Thanks given
    13
    Thanks received
    2
    Rep Power
    0
    I know I read something about this on one of jagex's devoloper blogs before they released animation pack 1. Great work, I learned something.
    Reply With Quote  
     

  3. #3  
    Member Market Banned Market Banned

    Robin Spud's Avatar
    Join Date
    Aug 2008
    Age
    28
    Posts
    2,338
    Thanks given
    46
    Thanks received
    73
    Rep Power
    1068
    Quote Originally Posted by Xae_ View Post
    good work zee, informative like always
    i never unstand any of this animation stuff. btw zee req a informative thread for clients. they have em for server sections
    ILY Stewie.
    Reply With Quote  
     

  4. #4  
    Fuckin PRO

    Tyler's Avatar
    Join Date
    Jan 2008
    Age
    30
    Posts
    6,023
    Thanks given
    46
    Thanks received
    507
    Rep Power
    3330
    nice.
    Free Filehost Premium Accounts
    [Only registered and activated users can see links. ]
    Reply With Quote  
     

  5. #5  
    RedBull
    Guest
    Yeh I understood this by reading the KB, but well done for explaining . Its very helpful for like anims that are rotations, as you could start at one end and use 1 more frame for the other, and it would evenly fill out it all with the frames offsets etc, which would probably do a better job than a human would. .
    Reply With Quote  
     

  6. #6  
    Apocalyptism
    Harry's Avatar
    Join Date
    Apr 2007
    Posts
    3,783
    Thanks given
    594
    Thanks received
    1,833
    Rep Power
    2934
    Quote Originally Posted by RedBull View Post
    Yeh I understood this by reading the KB, but well done for explaining . Its very helpful for like anims that are rotations, as you could start at one end and use 1 more frame for the other, and it would evenly fill out it all with the frames offsets etc, which would probably do a better job than a human would. .
    Yeah using keyframes for animation can help alot.

    The dance in my sig was done with just a couple of stances. Then just calculation/adding the changes between each stance.
    ~ Harry
    Please bear this in mind when hearing the word 'soon' from a software programmer.

    As coding software generally takes thousands of years, software programmers have developed a natural adaptation to this in the form of an altered perception of the flow of time.

    Due to this, the word 'soon' when uttered by a programmer should be taken to mean 'a very, very long time from now' in the terminology used by common human specimens who have not developed such an adaptation.
    knowledge can be taught, but passion cannot.
    It's better to create something that others criticise than to create nothing and criticise others.
    Reply With Quote  
     

  7. #7  
    Donator


    Join Date
    Nov 2008
    Posts
    1,017
    Thanks given
    21
    Thanks received
    32
    Rep Power
    161
    ?Nice
    Reply With Quote  
     

  8. #8  
    Registered Member

    Join Date
    Sep 2007
    Age
    27
    Posts
    523
    Thanks given
    0
    Thanks received
    2
    Rep Power
    89
    Zee do you still want to try working on adding the hand cannon with tweening? We have clients that could help with the code.
    Computer Specs:

    Operating System: Windows 7 Home Premium 64-bit
    Processor: AMD Athlon(tm) II X4 620 Processor, ~2.6GHz
    Memory: 6GB RAM
    HDD: 1Tb
    Mobo Chipset: NVIDIA GeForce 9100
    Graphics Card: Galaxy GeForce GTS 450
    Reply With Quote  
     

  9. #9  
    Member Market Banned Market Banned

    Zee Best's Avatar
    Join Date
    Feb 2007
    Age
    29
    Posts
    3,036
    Thanks given
    24
    Thanks received
    210
    Rep Power
    1171
    Quote Originally Posted by Areo8 View Post
    Zee do you still want to try working on adding the hand cannon with tweening? We have clients that could help with the code.
    If you can get me the latest deob ill have a look into it, but im a little bit busy with college, work and girlfriend at the moment so i might not be able to do it that quick.


    [Only registered and activated users can see links. ]
    Reply With Quote  
     

  10. #10  
    Registered Member
    Slay No More's Avatar
    Join Date
    Oct 2008
    Age
    25
    Posts
    2,334
    Thanks given
    695
    Thanks received
    170
    Rep Power
    554
    Quote Originally Posted by Zee best View Post
    If you can get me the latest deob ill have a look into it, but im a little bit busy with college, work and girlfriend at the moment so i might not be able to do it that quick.
    zee has a girlfriend yet is l33t in java. :O?
    Add me on skype if you wish to contact me.
    slaynomore
    My Steam Profile (from [Only registered and activated users can see links. ])
    • Worth: $719 ($245 with sales)
    • Games owned: 86
    • Games not played: 27 (31%)
    • Hours on record: 1,851.8h
    Reply With Quote  
     

Page 1 of 2 12 LastLast

Thread Information
Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)


User Tag List

Posting Permissions
  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •