Parallax effect scrolling of live wallpaper background

只愿长相守 提交于 2020-01-02 05:00:11

问题


I'm trying to get a background in a live wallpaper to behave like a regular wallpaper with regard to scrolling when the user changes homescreens. I know the method required for this is onOffestsChanged, but I can't seem to get it working.

Does anyone have advice or a code snippet to get this working?


回答1:


Have your engine implement onOffsetsChanged. The xOffset variable is a float value from 0 to 1 with 0 being the leftmost screen and 1 being the rightmost. Use the width of the screen (from onSurfaceChanged) and the width of your image to determine the left x coordinate with which to draw your image.

(screenWidth - yourImageWidth) * (1 - xOffset);

This should work with both screenWidth > yourImageWidth and screenWidth < yourImageWidth.



来源:https://stackoverflow.com/questions/5044363/parallax-effect-scrolling-of-live-wallpaper-background

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!