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.
- The way I implemented it is fine
- Create static ui-canvas-images and move theses with transform.position and reseting the position once it had been moved one tile.
- like 2. but with sprites
- Is there an even better way?
Thank you for your help!
Best regards
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”