Commit 3e84d2bb authored by Lila NICKLER's avatar Lila NICKLER

Animation asteroid1 et asteroid2

parent ea6eeb94
......@@ -2,13 +2,13 @@ package com.imtm1.starwarsgame;
import androidx.annotation.RequiresApi;
import androidx.appcompat.app.AppCompatActivity;
import android.animation.ObjectAnimator;
import android.animation.ValueAnimator;
import android.annotation.SuppressLint;
import android.content.Context;
import android.graphics.Path;
import android.graphics.Rect;
import android.graphics.RectF;
import android.os.Build;
import android.os.Bundle;
import android.os.Handler;
......@@ -25,9 +25,6 @@ import android.hardware.SensorEvent;
import android.hardware.SensorEventListener;
import android.hardware.SensorManager;
public class MainActivity extends AppCompatActivity implements SensorEventListener{
ImageView padExte;
......@@ -35,6 +32,7 @@ public class MainActivity extends AppCompatActivity implements SensorEventListen
ViewGroup mainLayout;
ImageView asteroid1;
ImageView asteroid2;
ImageView asteroid3;
ImageView tie;
ImageView explosion;
private SensorManager mSensorManager;
......@@ -54,6 +52,13 @@ public class MainActivity extends AppCompatActivity implements SensorEventListen
asteroid2 = findViewById(R.id.asteroid2);
explosion=findViewById(R.id.explosion);
DisplayMetrics metrics = new DisplayMetrics();
getWindowManager().getDefaultDisplay().getMetrics(metrics);
float height = metrics.heightPixels;
float width = metrics.widthPixels;
RectF oval = new RectF(100,100, width-180, height/2);
tie = findViewById(R.id.tie);
mSensorManager = (SensorManager) getSystemService(Context.SENSOR_SERVICE);
......@@ -63,11 +68,13 @@ public class MainActivity extends AppCompatActivity implements SensorEventListen
mSensorManager.registerListener((SensorEventListener) this, accelerometer, SensorManager.SENSOR_DELAY_NORMAL);
Path path = new Path();
path.arcTo(0f, 0f, 1000f, 1000f, 270f, -180f, true);
ObjectAnimator animator = ObjectAnimator.ofFloat(asteroid1, View.X, View.Y, path);
Path arc1 = new Path();
//path.arcTo(0f, 0f, 800f, 1200f, -270f, -180f, true);
arc1.arcTo(oval,-80,180);
ObjectAnimator animator = ObjectAnimator.ofFloat(asteroid1, View.X, View.Y, arc1);
animator.setDuration(2000);
animator.setRepeatCount(Animation.INFINITE);
animator.setRepeatMode(ValueAnimator.REVERSE);
animator.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() {
@Override
public void onAnimationUpdate(ValueAnimator animation) {
......@@ -81,9 +88,13 @@ public class MainActivity extends AppCompatActivity implements SensorEventListen
});
animator.start();
ObjectAnimator animator2 = ObjectAnimator.ofFloat(asteroid2, View.X, View.Y, path);
animator2.setDuration(5000);
Path line1 = new Path();
//path2.arcTo(100f, 50f, width/4f,(3*height)/5, -150f, -190f, true);
line1.lineTo((3*width)/4,(3*height)/5);
ObjectAnimator animator2 = ObjectAnimator.ofFloat(asteroid2, View.X, View.Y, line1);
animator2.setDuration(2400);
animator2.setRepeatCount(Animation.INFINITE);
animator2.setRepeatMode(ValueAnimator.REVERSE);
animator2.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() {
@Override
public void onAnimationUpdate(ValueAnimator animation) {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment