晃动window

本文介绍如何在Android应用中实现自定义界面切换动画效果,包括放大缩小及淡出动画,并提供了具体的XML配置文件示例和Java代码实现方式。
zoomin.xml
<?xml version="1.0" encoding="utf-8"?>
<set xmlns:android="http://schemas.android.com/apk/res/android"
android:interpolator="@android:anim/decelerate_interpolator">
<scale android:fromXScale="2.0" android:toXScale="1.0"
android:fromYScale="2.0" android:toYScale="1.0"
android:pivotX="50%p" android:pivotY="50%p"
android:duration="@android:integer/config_mediumAnimTime" />
</set>
zoomout.xml
<?xml version="1.0" encoding="utf-8"?>
<set xmlns:android="http://schemas.android.com/apk/res/android"
android:interpolator="@android:anim/decelerate_interpolator"
android:zAdjustment="top">
<scale android:fromXScale="1.0" android:toXScale=".5"
android:fromYScale="1.0" android:toYScale=".5"
android:pivotX="50%p" android:pivotY="50%p"
android:duration="@android:integer/config_mediumAnimTime" />
<alpha android:fromAlpha="1.0" android:toAlpha="0"
android:duration="@android:integer/config_mediumAnimTime"/>
</set>


Java


Intent intent = new Intent(FirstActivity.this, SecondActivity.class);
startActivityForResult(intent, 11);

//添加界面切换效果,注意只有Android的2.0(SdkVersion版本号为5)以后的版本才支持
int version = Integer.valueOf(android.os.Build.VERSION.SDK);
if(version >= 5) {
overridePendingTransition(R.anim.zoomin, R.anim.zoomout); //此为自定义的动画效果,下面两个为系统的动画效果
//overridePendingTransition(android.R.anim.fade_in,android.R.anim.fade_out);
//overridePendingTransition(android.R.anim.slide_in_left,android.R.anim.slide_out_right);
}
在Unity中实现物体模仿水面船只晃动效果可以通过以下几种常见方法: ### 方法一:使用脚本控制旋转和位移 可以编写一个C#脚本,通过不断改变物体的旋转和位置来模拟船只在水面上的晃动。以下是一个示例脚本: ```csharp using UnityEngine; public class BoatSway : MonoBehaviour { public float rotationAmplitude = 5f; // 旋转幅度 public float rotationFrequency = 1f; // 旋转频率 public float positionAmplitude = 0.1f; // 位移幅度 public float positionFrequency = 1f; // 位移频率 private void Update() { // 模拟旋转晃动 float rotationX = Mathf.Sin(Time.time * rotationFrequency) * rotationAmplitude; float rotationZ = Mathf.Sin(Time.time * rotationFrequency + Mathf.PI / 2) * rotationAmplitude; transform.rotation = Quaternion.Euler(rotationX, 0, rotationZ); // 模拟位置晃动 float positionY = Mathf.Sin(Time.time * positionFrequency) * positionAmplitude; transform.position = new Vector3(transform.position.x, transform.position.y + positionY, transform.position.z); } } ``` 将上述脚本挂载到需要模拟晃动的船只物体上,然后在Inspector面板中调整`rotationAmplitude`、`rotationFrequency`、`positionAmplitude`和`positionFrequency`参数,以达到不同的晃动效果。 ### 方法二:使用动画系统 可以在Unity的动画编辑器中创建一个动画,手动设置物体在不同时间点的旋转和位置,模拟船只的晃动。具体步骤如下: 1. 选中需要模拟晃动的船只物体,在菜单栏中选择`Window` -> `Animation`打开动画编辑器。 2. 点击`Create`按钮创建一个新的动画剪辑。 3. 在动画编辑器中,通过设置关键帧来改变物体的旋转和位置,模拟船只的晃动。 4. 调整关键帧的时间间隔和数值,以达到理想的晃动效果。 5. 将创建好的动画剪辑赋值给物体的Animator组件,并确保Animator组件的`Play Automatically`选项被勾选。 ### 方法三:使用物理模拟 可以使用Unity的物理系统来模拟船只在水面上的晃动。具体步骤如下: 1. 为船只物体添加`Rigidbody`组件,使其受物理系统控制。 2. 创建一个脚本,通过施加力和扭矩来模拟船只在水面上的晃动。以下是一个示例脚本: ```csharp using UnityEngine; public class BoatPhysicsSway : MonoBehaviour { public float forceAmplitude = 10f; // 力的幅度 public float forceFrequency = 1f; // 力的频率 public float torqueAmplitude = 10f; // 扭矩的幅度 public float torqueFrequency = 1f; // 扭矩的频率 private Rigidbody rb; private void Start() { rb = GetComponent<Rigidbody>(); } private void FixedUpdate() { // 施加力模拟晃动 float forceX = Mathf.Sin(Time.time * forceFrequency) * forceAmplitude; float forceY = Mathf.Sin(Time.time * forceFrequency + Mathf.PI / 2) * forceAmplitude; rb.AddForce(new Vector3(forceX, forceY, 0)); // 施加扭矩模拟旋转晃动 float torqueX = Mathf.Sin(Time.time * torqueFrequency) * torqueAmplitude; float torqueZ = Mathf.Sin(Time.time * torqueFrequency + Mathf.PI / 2) * torqueAmplitude; rb.AddTorque(new Vector3(torqueX, 0, torqueZ)); } } ``` 将上述脚本挂载到船只物体上,然后在Inspector面板中调整`forceAmplitude`、`forceFrequency`、`torqueAmplitude`和`torqueFrequency`参数,以达到不同的晃动效果。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值