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 /
avatar image
1
Question by JeffRosenberg · Sep 03, 2012 at 02:45 PM · texturematerial2d animation

2D Sprite Texture Animation - SetTexture or SetTextureOffset

I'm working on a rather simple Animation2D class that'll let me cycle through textures or frames on a material. I'll be using it as the basis of a 2D sprite-based game.

My question is whether it would be more efficient to use Material.SetTextureOffset() or Material.SetTexture() to cycle through my frames. The former would use a spritesheet and would have a list of indexes to cycle through, while the latter would have a list of textures to cycle through. While I'm thinking the former is more efficient, it's not as easy to use in the editor. You'd have to provide for image size, frame columns/rows, etc. as well as follow some sort of chart for setting the indexes. With the latter, you just drag your individual frame textures into the list in the inspector, which would be great for my artist friend to be able to easily build his own sprites and get them to me in a package or whatever.

 animatedMaterial.SetTexture("_MainTex", textures[currentIndex]);
 // or
 animatedMaterial.SetTextureOffset("_MainTex", frames[currentIndex]);

A smaller and less important question: Which would be better, using Update and Time.deltaTime or FixedUpdate and Time.fixedDeltaTime to measure the time between frames? Time between frames is a float currently set through a fps variable in the editor.

 timeSinceLastFrame += Time.fixedDeltaTime;
 // or
 timeSinceLastFrame += Time.deltaTime;
 
 if (timeSinceLastFrame >= timeBetweenFrames)
     //...

[Third small question found myself, will omit]

Thanks!

Comment
Add comment · Show 1
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 Fattie · Sep 14, 2012 at 05:44 PM 0
Share

if any answer helps please TIC$$anonymous$$ to keep the board tidy, thanks!

1 Reply

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

Answer by Fattie · Sep 03, 2012 at 03:26 PM

(1) Sure just move the texture around, so SetTextureOffset

(1B .. ?) Would it be sensible to just use 2DToolkit? it saves say 2 man years of work on any such project. he's completely figured out all the draw call blah blah and you just drop things in, it is unbelievably easy

(2) "which is better update or fixedupdate" what do you mean .. to do what ??? You'd have to explain.

{To some extent, my answer to this is "You should never have to use either for any purpose!")

"FixedUpdate is for physics only" ... (it's funny how many people say that!) I would say rather, if you're doing physics, you should do that in fixedupdate (for the straightforward reason that it happens a certain number of times per frame, rather than "incredibly fast" and indeed "at various unknown speeds" as it would happen in update)

{A classic problem is someone asks "hey my game/car/whatever runs at different speeds on different platforms!" the answer is immediately "dude you accidentally used update rather than fixedupdate somewhere}

{To repeat, again ideally you SHOULD NOT EVEN EVER have to use physics in that way!! think more like a simulate and less like an animator. (Sounds like a slogan!) Just set off an explosion or something and let PhysX sort it out.}

so, I'd perhaps say there's no sense in which FU is "for physics only". it's "for" anything you need to do, well, on the frame rate. physics, generally, needs to be done in F.U. -- well at any rate, you can do it however the hell you want, so long as you understand that a physics step needs to happen in some measured certain time

"you should have as little info in FixedUpdate as possible" Why ?? I don't see that .............. I mean "your game should run well" and if there's some problem "you'll have to optimise

That's my understanding anyway ! Cheers!

(3) You're third question .. um, yes you were right! :)

Comment
Add comment · 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

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

8 People are following this question.

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

Related Questions

SetTexture on Quad black (but only on one camera) 0 Answers

Is it bad to have this many materials? 2 Answers

2D cube material pattern not repeating 1 Answer

3d Object always behind with Render Queue doesn't work? 0 Answers

How do I add a texture to a cube with different faces? 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