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.alpha; 20 import static com.badlogic.gdx.scenes.scene2d.actions.Actions.forever; 21 import static com.badlogic.gdx.scenes.scene2d.actions.Actions.parallel; 22 import static com.badlogic.gdx.scenes.scene2d.actions.Actions.rotateBy; 23 import static com.badlogic.gdx.scenes.scene2d.actions.Actions.scaleTo; 24 import static com.badlogic.gdx.scenes.scene2d.actions.Actions.sequence; 25 26 import com.badlogic.gdx.Gdx; 27 import com.badlogic.gdx.graphics.GL20; 28 import com.badlogic.gdx.graphics.Texture; 29 import com.badlogic.gdx.graphics.Texture.TextureFilter; 30 import com.badlogic.gdx.graphics.g2d.TextureRegion; 31 import com.badlogic.gdx.scenes.scene2d.Action; 32 import com.badlogic.gdx.scenes.scene2d.Stage; 33 import com.badlogic.gdx.scenes.scene2d.ui.Image; 34 import com.badlogic.gdx.tests.utils.GdxTest; 35 36 public class ComplexActionTest extends GdxTest { 37 38 Stage stage; 39 Texture texture; 40 41 @Override 42 public void create () { 43 stage = new Stage(); 44 45 Action complexAction = forever(sequence(parallel(rotateBy(180, 2), scaleTo(1.4f, 1.4f, 2), alpha(0.7f, 2)), 46 parallel(rotateBy(180, 2), scaleTo(1.0f, 1.0f, 2), alpha(1.0f, 2)))); 47 48 texture = new Texture(Gdx.files.internal("data/badlogic.jpg"), false); 49 texture.setFilter(TextureFilter.Linear, TextureFilter.Linear); 50 51 final Image img1 = new Image(new TextureRegion(texture)); 52 img1.setSize(100, 100); 53 img1.setOrigin(50, 50); 54 img1.setPosition(50, 50); 55 56 final Image img2 = new Image(new TextureRegion(texture)); 57 img2.setSize(50, 50); 58 img2.setOrigin(50, 50); 59 img2.setPosition(150, 150); 60 61 stage.addActor(img1); 62 stage.addActor(img2); 63 64 img1.addAction(complexAction); 65 // img2.action(complexAction.copy()); 66 } 67 68 @Override 69 public void render () { 70 Gdx.gl.glClear(GL20.GL_COLOR_BUFFER_BIT); 71 stage.act(Math.min(Gdx.graphics.getDeltaTime(), 1 / 30f)); 72 stage.draw(); 73 } 74 75 @Override 76 public void dispose () { 77 stage.dispose(); 78 texture.dispose(); 79 } 80 } 81