RepeatActionExampleScene.java :  » Graphics-3D-2D-OpenGL » amarena2d » org » amarena2d » examples » scenes » Android Open Source

Android Open Source » Graphics 3D 2D OpenGL » amarena2d 
amarena2d » org » amarena2d » examples » scenes » RepeatActionExampleScene.java
/*
 * Copyright 2010 Christoph Widulle (christoph.widulle@googlemail.com)
 *
 * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the
 * License. You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS"
 * BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language
 * governing permissions and limitations under the License.
 */



package org.amarena2d.examples.scenes;

import com.android1.amarena2d.actions.base.Action;
import com.android1.amarena2d.actions.base.Repeat;
import com.android1.amarena2d.actions.interval.RotateBy;
import com.android1.amarena2d.commons.Callback;
import com.android1.amarena2d.nodes.Scene;
import com.android1.amarena2d.nodes.SimpleLabel;
import com.android1.amarena2d.nodes.behavior.ActionTarget;
import com.android1.amarena2d.nodes.sprites.Sprite;
import com.android1.amarena2d.texture.Textures;
import com.badlogic.gdx.graphics.Color;
import org.amarena2d.examples.Example;


@Example(name = "Repeat", category = "Actions")
public class RepeatActionExampleScene extends Scene {

    final Sprite sprite;
    final SimpleLabel simpleLabel;
    final SimpleLabel counterLabel;
    int counter = 0;

    //we increase the counter when the sequnce has finished
    final Callback<ActionTarget> seqFinishCallback = new Callback<ActionTarget>() {
        @Override
        public void on(ActionTarget element) {
            counterLabel.setText("Round = " + (++counter));
        }
    };

    final Action actionSequence = Repeat.$(4, RotateBy.$(1, 360).setOnStopCallback(seqFinishCallback));

    public RepeatActionExampleScene() {

        engine.getRenderer().setClearColor(Color.WHITE);

        sprite = new Sprite(Textures.$("andou_die02.png").get(), 50, 50);

        sprite.transform().setTransformAnchor(32, 22);

        //the sprite is now a child of the scene-layer.
        add(sprite);




        add(simpleLabel = new SimpleLabel("(Andou Sprite repeats a sequence of actions.)", 20, 40, Color.BLACK));
        add(counterLabel = new SimpleLabel("Round = 0", 20, 20, Color.BLACK));

        touch().makeTouchable(this);
    }

    @Override
    public boolean onTouchDown(float x, float y, int pointer, boolean isHit) {
          sprite.action().run(actionSequence);

        return true;
    }
}
java2s.com  | Contact Us | Privacy Policy
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.