Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
S
Star Wars Game
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Benjamin LEROUX
Star Wars Game
Commits
3e84d2bb
Commit
3e84d2bb
authored
Feb 28, 2021
by
Lila NICKLER
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Animation asteroid1 et asteroid2
parent
ea6eeb94
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
20 additions
and
9 deletions
+20
-9
MainActivity.java
app/src/main/java/com/imtm1/starwarsgame/MainActivity.java
+20
-9
No files found.
app/src/main/java/com/imtm1/starwarsgame/MainActivity.java
View file @
3e84d2bb
...
...
@@ -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
(
0
f
,
0
f
,
1000
f
,
1000
f
,
270
f
,
-
180
f
,
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
)
{
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment