• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*******************************************************************************
2  * Copyright 2011 See AUTHORS file.
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  *   http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  ******************************************************************************/
16 
17 package com.badlogic.gdx.tests;
18 
19 import static com.badlogic.gdx.scenes.scene2d.actions.Actions.moveBy;
20 import static com.badlogic.gdx.scenes.scene2d.actions.Actions.parallel;
21 import static com.badlogic.gdx.scenes.scene2d.actions.Actions.sequence;
22 
23 import com.badlogic.gdx.Gdx;
24 import com.badlogic.gdx.graphics.GL20;
25 import com.badlogic.gdx.graphics.Texture;
26 import com.badlogic.gdx.graphics.Texture.TextureFilter;
27 import com.badlogic.gdx.graphics.g2d.TextureRegion;
28 import com.badlogic.gdx.scenes.scene2d.Stage;
29 import com.badlogic.gdx.scenes.scene2d.actions.Actions;
30 import com.badlogic.gdx.scenes.scene2d.ui.Image;
31 import com.badlogic.gdx.tests.utils.GdxTest;
32 
33 public class ActionSequenceTest extends GdxTest implements Runnable {
34 
35 	Image img;
36 	Image img2;
37 	Image img3;
38 	Stage stage;
39 	Texture texture;
40 
41 	@Override
create()42 	public void create () {
43 		stage = new Stage();
44 		texture = new Texture(Gdx.files.internal("data/badlogic.jpg"), false);
45 		texture.setFilter(TextureFilter.Linear, TextureFilter.Linear);
46 		img = new Image(new TextureRegion(texture));
47 		img.setSize(100, 100);
48 		img.setOrigin(50, 50);
49 		img.setPosition(100, 100);
50 
51 		img2 = new Image(new TextureRegion(texture));
52 		img2.setSize(100, 100);
53 		img2.setOrigin(50, 50);
54 		img2.setPosition(100, 100);
55 
56 		img3 = new Image(new TextureRegion(texture));
57 		img3.setSize(100, 100);
58 		img3.setOrigin(50, 50);
59 		img3.setPosition(100, 100);
60 
61 		stage.addActor(img);
62 		stage.addActor(img2);
63 		stage.addActor(img3);
64 
65 		img.addAction(sequence());
66 		img2.addAction(parallel(sequence(), moveBy(100, 0, 1)));
67 		img3.addAction(sequence(parallel(moveBy(100, 200, 2)), Actions.run(this)));
68 	}
69 
70 	@Override
render()71 	public void render () {
72 		Gdx.gl.glClear(GL20.GL_COLOR_BUFFER_BIT);
73 
74 		stage.act(Math.min(Gdx.graphics.getDeltaTime(), 1 / 30f));
75 		stage.draw();
76 	}
77 
78 	@Override
run()79 	public void run () {
80 		System.out.println("completed");
81 	}
82 
83 	@Override
dispose()84 	public void dispose () {
85 		stage.dispose();
86 		texture.dispose();
87 	}
88 }
89