Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
1 capture
13 Jun 22 - 13 Jun 22
sparklines
Close Help
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
This post has been wikified, any user with enough reputation can edit it.
avatar image
1
Question by kiatu24 · Jul 22, 2013 at 10:49 PM · animation2dtexturesprite

Best Practices on 2D Animation?

So I'm making a game that is a 2D top-down style game like old Final Fantasy or Zelda. So I have several images that make up my 2D sprite animations for movement and everything else. So my question is, can anyone offer any advice about the best way to store and change out the different frames?

I've tried it a few different ways and I'm not sure which is the best. These are the ways I've tried it:

  • Store all 40+ images in a tileset (combined into one image) then just using the texture offset on the material to show different "frames".

  • Make each individual image into a material and just swap out the materials to change frames.

  • Keep each image just as a texture and change the texture out on the same material to change frames.

I'm also open to new suggestions. I'm just looking for the best way to do this, and it seems like it's a pretty common thing to do. So how would you go about 2D frame animation?

Thanks in advance, Kiatu24

Comment
Add comment
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

1 Reply

· Add your reply
  • Sort: 
avatar image
2
Best Answer

Answer by clunk47 · Jul 22, 2013 at 10:57 PM

Here's something I did a while back along the lines of animating a 2D character with separate frames. I made a folder named Resources in my Assets folder, then made folders accordingly where I wanted to load the resources from. This is only for a 4 frame animation, but you could use this as a reference, then take a look at Resources.LoadAll if you have something with a ton of frames, I know you can load all from a certain path, just kinda rusty. Here is my C# script that I used to animate my character though, hope it helps point you in the right direction.

 using UnityEngine;
 using System.Collections;
 using System.Collections.Generic;
 
 public class AI_Anim : MonoBehaviour 
 {
     public Texture[] walk;
     List<Texture> frames;
     public bool animate = false;
     float delay = .07f;
     int f = 0;
     
     void Start () 
     {
         walk = new Texture[]
             {Resources.Load ("Characters/Actor0/walk0") as Texture,
             Resources.Load ("Characters/Actor0/walk1") as Texture,
             Resources.Load ("Characters/Actor0/walk2") as Texture,
             Resources.Load ("Characters/Actor0/walk3") as Texture};
         frames = new List<Texture>(walk);
         StartCoroutine("Animate");
     }
 
     IEnumerator Animate()
     {
         while(true)
         {
             if(animate)
             {
                 yield return new WaitForSeconds(delay);
                 for(int i = 0; i < frames.Count; i++)
                 {
                     frames[i] = walk[i];
                 }
                 f++;
                 if(f >= frames.Count)
                     f = 0;        
                 renderer.material.mainTexture = frames[f];
             }
             yield return new WaitForEndOfFrame();
         }
     }
 }
 





Comment
Add comment · Show 1 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image kiatu24 · Jul 23, 2013 at 04:05 AM 2
Share

Thank you for your help. I'll give this a try.

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this Question

Answers Answers and Comments

16 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

Most efficient way to do 2D animation 2 Answers

2d Sprite Sheet on characters ruined in unity 1 Answer

reset 2d animation(sprite sheet texture) 0 Answers

How change sprite animation texture?? 2 Answers

SpriteManager 2 1 Answer


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges