现场墙纸背景视差效果滚动 [英] Parallax effect scrolling of live wallpaper background

查看:111
本文介绍了现场墙纸背景视差效果滚动的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图让一个动态壁纸的背景下表现得就像一个普通的壁纸就当用户更改homescreens滚动。我知道,为此所需的方法onOffestsChanged,但我似乎无法得到它的工作。

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.

有没有人有意见或code片段来得到这个工作?

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

推荐答案

让你的引擎实现onOffsetsChanged。该xOffset变量是从0 float值1 0是最左边的屏幕,1为最右边。使用屏幕(从onSurfaceChanged)的宽度和图像的宽度,以确定左X外的坐标绘制你的形象。

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);

这应该既屏幕宽度&GT的工作; yourImageWidth 屏幕宽度< yourImageWidth。

这篇关于现场墙纸背景视差效果滚动的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆