有一款游戏小人闯关很难手机游戏是操控一个小人绕着屏幕四周跑,需要点击屏幕控制小人

有一款安卓手机游戏是点击去是用手指操控一个小人一会儿上一会儿下去获得***的豆豆,并且可以获得武器_百度知道Android开发(43) 动画演示,会跑的小人,从屏幕左侧跑到右侧 - 简书
下载简书移动应用
写了126574字,被285人关注,获得了454个喜欢
Android开发(43) 动画演示,会跑的小人,从屏幕左侧跑到右侧
想做一个动画,一个会跑的小人,从屏幕右侧跑道右侧,于是做了个尝试,上图:
要完成这样需要三步:
做一个 帧动画 (frame animation),由多张图片组成,组成小人连续跑动的样子。
做一个 位移动画 使得小人 从左到右产生移动。
在onStart里启动动画
第一步,描述 “人物动作的变化”的动画
准备多个动作的图片,写个xml animation :
&?xml version="1.0" encoding="utf-8"?&
&animation-list xmlns:android="/apk/res/android"
android:oneshot="false" &
android:drawable="@drawable/loading_iv_00"
android:duration="60"&
android:drawable="@drawable/loading_iv_01"
android:duration="60"&
android:drawable="@drawable/loading_iv_02"
android:duration="60"&
android:drawable="@drawable/loading_iv_03"
android:duration="60"&
android:drawable="@drawable/loading_iv_04"
android:duration="60"&
android:drawable="@drawable/loading_iv_05"
android:duration="60"&
android:drawable="@drawable/loading_iv_06"
android:duration="60"&
android:drawable="@drawable/loading_iv_07"
android:duration="60"&
android:drawable="@drawable/loading_iv_08"
android:duration="60"&
android:drawable="@drawable/loading_iv_09"
android:duration="60"&
android:drawable="@drawable/loading_iv_10"
android:duration="60"&
&/animation-list&
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
imageView1 = (ImageView) findViewById(R.id.imageView1);
imageView1.setImageResource(R.anim.loading);
imageView1.setVisibility(View.GONE);
mAnimationDrawable = (AnimationDrawable) imageView1.getDrawable();
mAnimationDrawable.setOneShot(false);
第二步,位移动画
Animation translate = new TranslateAnimation(Animation.RELATIVE_TO_PARENT, -0.2f,
Animation.RELATIVE_TO_PARENT, 1, Animation.RELATIVE_TO_SELF, 0,
Animation.RELATIVE_TO_SELF, 0);
translate.setDuration(3000);
translate.setRepeatCount(Animation.INFINITE);
这句话的意思时,相对于 父容器 的x坐标移动,y轴不改变,一直循环
第三步,启动
启动动画即可,代码:
package com.example.demo_
import android.app.A
import android.graphics.drawable.AnimationD
import android.os.B
import android.view.V
import android.view.ViewTreeO
import android.view.animation.A
import android.view.animation.TranslateA
import android.widget.ImageV
public class MainActivity extends Activity {
ImageView imageView1;
AnimationDrawable mAnimationD
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
imageView1 = (ImageView) findViewById(R.id.imageView1);
imageView1.setImageResource(R.anim.loading);
imageView1.setVisibility(View.GONE);
mAnimationDrawable = (AnimationDrawable) imageView1.getDrawable();
mAnimationDrawable.setOneShot(false);
protected void onStart() {
startAnimation();
super.onStart();
private void startAnimation() {
mAnimationDrawable.start();
Animation translate = new TranslateAnimation(Animation.RELATIVE_TO_PARENT, -0.2f,
Animation.RELATIVE_TO_PARENT, 1, Animation.RELATIVE_TO_SELF, 0,
Animation.RELATIVE_TO_SELF, 0);
translate.setDuration(3000);
translate.setRepeatCount(Animation.INFINITE);
imageView1.startAnimation(translate);
imageView1.setVisibility(View.VISIBLE);
页面布局:
&RelativeLayout xmlns:android="/apk/res/android"
xmlns:tools="/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#3F99C3"
tools:context=".MainActivity" &
&ImageView
android:id="@+id/imageView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_alignParentLeft="true" /&
&/RelativeLayout&
如果觉得我的文章对您有用,请随意打赏。您的支持将鼓励我继续创作!
打开微信“扫一扫”,打开网页后点击屏幕右上角分享按钮
被以下专题收入,发现更多相似内容:
如果你是程序员,或者有一颗喜欢写程序的心,喜欢分享技术干货、项目经验、程序员日常?事等等,欢迎投稿《程序员》专题。
专题主编:小...
? 177729人关注
玩转简书的第一步,从这个专题开始。
想上首页热门榜么?好内容想被更多人看到么?来投稿吧!如果被拒也不要灰心哦~入选文章会进一个队...
? 131048人关注
分享Android开发的知识,教程,解析,前沿信息,都可以,欢迎大家投稿~
内容可搞笑,可逗比,另外欢迎申请管理员
? 21391人关注
如果觉得我的文章对您有用,请随意打赏。您的支持将鼓励我继续创作!
选择支付方式:手机游戏,像测试似的,一共有一百个场景,然后让你来控制小人,做出选择,其中有一个是让座,你可以点击_百度知道有一个游戏,里面有一个小人,手在屏幕上一划,就有风把他吹起来,,游戏里,小人可以四处飘荡,有洞,有_百度知道

参考资料

 

随机推荐