我正在开发一个android的滑块拼图,其中有一个图像分解成小图像,我们需要排序这些部分,以形成正确的图像。我使用了一个3x3的网格视图,其中包含8个图像和一个黑点。所以基本上,当你触摸8个棋子中的任何一个时,拼图取决于它是否是有效的移动,棋子会移动到空白点。这一切都很好,但我想给它滑动的效果。因此,当你触摸该块时,它应该滑入空白点。我想我必须使用onFling方法,但我不太确定如何使用。
任何帮助都将不胜感激。谢谢
发布于 2012-11-01 18:25:27
此代码在时间延迟和幻灯片图像上运行:
public class SliderActivity extends Activity {
public int currentimageindex=0;
Timer timer;
TimerTask task;
ImageView slidingimage;
private int[] IMAGE_IDS = {
R.drawable.splash0, R.drawable.splash1, R.drawable.splash2,
R.drawable.splash3
};
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.mygame);
final Handler mHandler = new Handler();
// Create runnable for posting
final Runnable mUpdateResults = new Runnable() {
public void run() {
AnimateandSlideShow();
}
};
int delay = 1000; // delay for 1 sec.
int period = 8000; // repeat every 4 sec.
Timer timer = new Timer();
timer.scheduleAtFixedRate(new TimerTask() {
public void run() {
mHandler.post(mUpdateResults);
}
}, delay, period);
}
public void onClick(View v) {
finish();
android.os.Process.killProcess(android.os.Process.myPid());
}
/**
* Helper method to start the animation on the splash screen
*/
private void AnimateandSlideShow() {
slidingimage = (ImageView)findViewById(R.id.ImageView3_Left);
slidingimage.setImageResource(IMAGE_IDS[currentimageindex%IMAGE_IDS.length]);
currentimageindex++;
Animation rotateimage = AnimationUtils.loadAnimation(this, R.anim.custom_anim);
slidingimage.startAnimation(rotateimage);
}
}发布于 2014-03-29 04:47:30
为此,您可能需要考虑使用游戏引擎。它的价值在于它可以为您处理动画,并且动画效果就像一行代码一样简单。
tile.MoveTo(newPosition)。
我推荐用于安卓系统的cocos2d,你可以在这里找到构建滑块拼图的详细教程。
http://denvycom.com/blog/step-by-step-guide-on-how-to-build-your-first-slider-puzzle-game-in-cocos2d-for-android-part-1/
本教程还介绍了如何在此处构建图像滑块拼图。http://denvycom.com/blog/step-by-step-guide-on-how-to-build-your-first-slider-puzzle-game-in-cocos2d-for-android-part-3-2/#comment-1313951361
https://stackoverflow.com/questions/13174371
复制相似问题