Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 12 Next capture
2021 2022 2023
1 capture
12 Jun 22 - 12 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 SomehowLuke · Mar 26, 2017 at 05:15 PM · texturespritemobileperformanceimage

Best Performance for Background Movement

Hello, I was implementing a background - movement for a little mobile game. There is a sprite that covers the entire display and the floor texture is tiled vertically. In code I use the offset value to move the texture from top to bottom depending on the speed. It works great on new generation phones (iphone 6/7 or S6/7) but on older phones I can see lags.

I was wondering now, what would have better performance.

  1. The way I implemented it is fine

  2. Create static ui-canvas-images and move theses with transform.position and reseting the position once it had been moved one tile.

  3. like 2. but with sprites

  4. Is there an even better way?

Thank you for your help! Best regards

Comment
Add comment · Show 2
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 beStrange · Mar 26, 2017 at 08:21 PM 0
Share

It would help if you add your implementation to your question, this will help finding the correct answer for you specific case.

avatar image SomehowLuke beStrange · Mar 28, 2017 at 11:55 AM 1
Share

Hi, actually its nothing more then that:

 //Calculate the current movement for the current frame
 m_fDelta$$anonymous$$ove = m_fCurrentSpeed * Time.deltaTime;
 
 //adjust the rectangle for the uv settings of the sprite by adding the current delta to the y coordinates      
 m_rect$$anonymous$$oveBackground.y += m_fDelta$$anonymous$$ove;
 
 //apply the new rect to the uvRect of the sprite
 m_rawBackground.uvRect = m_rect$$anonymous$$oveBackground;
 
 

alt text

The rawBackground is just a Raw Image that has it sprite texture in it.

rawimage.png (10.4 kB)

1 Reply

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

Answer by beStrange · Mar 28, 2017 at 12:47 PM

Your implementation looks good already, but it might help if you shift the offset if it is more than 1 to prevent some issues with floats:

 //...     
 m_rectMoveBackground.y += m_fDeltaMove;
 
 // shift offeset if required
 if (m_rectMoveBackground.y >= 1f)
   m_rectMoveBackground.y -= 1f;

That way you can prevent to large floats and in turn so weird behaviour.

Performance wise, there aren't really many differences, depending of the implementation on different methods. There might be something else going on in your game that results in poor performance.

Since you're on mobile, i highly recommend Mark Harkness and Ian Dundore talk from Unite Europe 2016 on "Optimizing Mobile Applications"

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 SomehowLuke · Mar 28, 2017 at 03:01 PM 0
Share

Thank you very much for your advice! I will also look into that video!

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

5 People are following this question.

avatar image avatar image avatar image avatar image avatar image

Related Questions

Texture parameter preview. 0 Answers

Sprites grey when camera zoomed out 3 Answers

Best practices for large background image on mobile? 0 Answers

Sprite renderer, bad perfomance on mobile 1 Answer

How do you crop a Texture2d 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