com.badlogic.gdx.scenes.scene2d.Action Java Examples

The following examples show how to use com.badlogic.gdx.scenes.scene2d.Action. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: CCSpriteViewTest.java    From cocos-ui-libgdx with Apache License 2.0 6 votes vote down vote up
@Test
@NeedGL
public void shouldParseSpriteView() throws Exception {
    CocoStudioUIEditor editor = new CocoStudioUIEditor(
        Gdx.files.internal("animation/MainScene.json"), null, null, null, null);

    Group group = editor.createGroup();
    Image image = group.findActor("st_2");
    Array<Action> actions = image.getActions();
    assertThat(actions.size, is(1));
    RepeatAction repeatAction = (RepeatAction) actions.get(0);
    ParallelAction parallelAction = (ParallelAction) repeatAction.getAction();
    assertThat(parallelAction.getActions().size, is(3));
    assertThat(parallelAction.getActions(), (Matcher) everyItem(instanceOf(SequenceAction.class)));
    SequenceAction moveAction = (SequenceAction) parallelAction.getActions().get(0);
    SequenceAction scaleAction = (SequenceAction) parallelAction.getActions().get(1);
    assertThat(moveAction.getActions().size, is(4));
    assertThat(moveAction.getActions(), (Matcher) everyItem(instanceOf(MoveToAction.class)));
    assertThat(scaleAction.getActions().size, is(4));
    assertThat(scaleAction.getActions(), (Matcher) everyItem(instanceOf(ScaleToAction.class)));
}
 
Example #2
Source File: StringSpin.java    From dice-heroes with GNU General Public License v3.0 6 votes vote down vote up
private void addActions(final Label label, final int i, final int idx, final float speed, final float spinTime, final float endTime, final Runnable callback) {
    label.addAction(new Action() {
        private float totalTime = spinTime + i * endTime;
        @Override public boolean act(float delta) {
            totalTime -= delta;
            label.moveBy(0, -speed * delta);
            boolean finished = totalTime <= 0;
            if (finished) {
                label.setY(-(letters.length() - idx - 1) * lineHeight);
                if (i == labels.size - 1) {
                    callback.run();
                }
            } else {
                while (label.getY() < -letters.length() * lineHeight) {
                    label.setY(label.getY() + letters.length() * lineHeight);
                }
            }
            return finished;
        }
    });
}
 
Example #3
Source File: LevelStartScreen.java    From ninja-rabbit with GNU General Public License v2.0 6 votes vote down vote up
@Override
public void show() {
	// Fade in / fade out effect
	stage.addAction(sequence(fadeIn(0.75f), delay(1.75f), fadeOut(0.35f), new Action() {
		@Override
		public boolean act(final float delta) {
			// Last action will move to the next screen
			if (levelScreen == null) {
				game.setScreen(new LevelScreen(game));
			} else {
				game.setScreen(levelScreen);
			}
			return true;
		}
	}));
}
 
Example #4
Source File: SoundManager.java    From dice-heroes with GNU General Public License v3.0 6 votes vote down vote up
public void stopMusicBeautifully(String name, Stage stage) {
    final Music music = musics.get(name);
    if (music == null) {
        Logger.error("there is no music for " + name);
        return;
    }
    final float initialVolume = music.getVolume();
    Action action = new TemporalAction(2f, Interpolation.linear) {
        @Override protected void update(float percent) {
            music.setVolume(initialVolume - percent * initialVolume);
        }

        @Override protected void end() {
            music.stop();
            playingMusics.remove(music);
            disabledMusics.remove(music);
        }
    };
    stage.addAction(action);
    replaceAction(music, action);
}
 
Example #5
Source File: ControllerMenuDialog.java    From gdx-controllerutils with Apache License 2.0 6 votes vote down vote up
@Override
public Dialog show(Stage stage, Action action) {
    previousFocusedActor = null;
    previousEscapeActor = null;

    super.show(stage, action);

    if (stage instanceof ControllerMenuStage) {
        previousFocusedActor = ((ControllerMenuStage) stage).getFocusedActor();
        previousEscapeActor = ((ControllerMenuStage) stage).getEscapeActor();

        ((ControllerMenuStage) stage).setFocusedActor(getConfiguredDefaultActor());
        ((ControllerMenuStage) stage).setEscapeActor(getConfiguredEscapeActor());
    }

    return this;

}
 
Example #6
Source File: ControllerMenuDialog.java    From gdx-controllerutils with Apache License 2.0 6 votes vote down vote up
@Override
public void hide(Action action) {
    if (getStage() != null && getStage() instanceof ControllerMenuStage) {
        Actor currentFocusedActor = ((ControllerMenuStage) getStage()).getFocusedActor();
        if (previousFocusedActor != null && previousFocusedActor.getStage() == getStage()
                && (currentFocusedActor == null || !currentFocusedActor.hasParent() ||
                currentFocusedActor.isDescendantOf(this)))
            ((ControllerMenuStage) getStage()).setFocusedActor(previousFocusedActor);
        Actor currentEscapeActor = ((ControllerMenuStage) getStage()).getEscapeActor();
        if (previousEscapeActor != null && previousEscapeActor.getStage() == getStage()
                && (currentEscapeActor == null || !currentEscapeActor.hasParent() ||
                currentEscapeActor.isDescendantOf(this)))
            ((ControllerMenuStage) getStage()).setEscapeActor(previousEscapeActor);
    }

    super.hide(action);
}
 
Example #7
Source File: CustomTargetAction.java    From gdx-vfx with Apache License 2.0 6 votes vote down vote up
private void recursivelyUpdateTarget(Action action, Actor target) {
    if (action instanceof CustomTargetAction) return;

    action.setTarget(target);

    if (action instanceof DelegateAction) {
        DelegateAction delegateAction = (DelegateAction) action;
        Action wrappedAction = delegateAction.getAction();
        if (!(wrappedAction instanceof CustomTargetAction)) {
            recursivelyUpdateTarget(wrappedAction, target);
        }

    } else if (action instanceof ParallelAction) {
        ParallelAction parallelAction = (ParallelAction) action;
        Array<Action> actions = parallelAction.getActions();
        for (int i = 0; i < actions.size; i++) {
            Action childAction = actions.get(i);
            if (!(childAction instanceof CustomTargetAction)) {
                recursivelyUpdateTarget(childAction, target);
            }
        }
    }
}
 
Example #8
Source File: SoundManager.java    From dice-heroes with GNU General Public License v3.0 6 votes vote down vote up
public void playMusicBeautifully(String name, Stage stage) {
    final Music music = musics.get(name);
    if (music == null) {
        Logger.error("there is no music for " + name);
        return;
    }
    music.setVolume(0);
    if (!usesMusic) {
        disabledMusics.add(music);
    } else {
        music.play();
    }
    music.setLooping(true);
    playingMusics.add(music);
    Action action = new TemporalAction(5f, Interpolation.linear) {
        @Override protected void update(float percent) {
            music.setVolume(percent * volume);
        }
    };
    stage.addAction(action);
    replaceAction(music, action);
}
 
Example #9
Source File: DefaultCardView.java    From Cardshifter with Apache License 2.0 5 votes vote down vote up
private Action removeThis() {
    return Actions.run(new Runnable() {
        @Override
        public void run() {
            getActor().remove();
        }
    });
}
 
Example #10
Source File: TCheckBox.java    From cocos-ui-libgdx with Apache License 2.0 5 votes vote down vote up
@Override
public void addAction(Action action) {
    super.addAction(action);
    if (bg != null) {
        bg.addAction(action);
    }
}
 
Example #11
Source File: Toast.java    From gdx-texture-packer-gui with Apache License 2.0 5 votes vote down vote up
public void fadeOut () {
	mainTable.addAction(Actions.sequence(Actions.fadeOut(VisWindow.FADE_TIME, Interpolation.fade), new Action() {
		@Override
		public boolean act (float delta) {
			toastManager.remove(Toast.this);
			return true;
		}
	}));
}
 
Example #12
Source File: DialogFactory.java    From skin-composer with MIT License 5 votes vote down vote up
public Dialog yesNoCancelDialog(String title, String text,
        ConfirmationListener listener, DialogListener dialogListener) {
    Dialog dialog = new Dialog(title, main.getSkin(), "bg") {
        @Override
        public Dialog show(Stage stage, Action action) {
            fire(new DialogEvent(DialogEvent.Type.OPEN));
            return super.show(stage, action);
        }
        @Override
        protected void result(Object object) {
            listener.selected((int) object);
            fire(new DialogEvent(DialogEvent.Type.CLOSE));
        }
    };
    
    if (dialogListener != null) {
        dialog.addListener(dialogListener);
    }


    dialog.getTitleTable().getCells().first().padLeft(5.0f);
    Label label = new Label(text, main.getSkin());
    label.setAlignment(Align.center);
    dialog.text(label);
    dialog.getContentTable().getCells().first().pad(10.0f);
    dialog.getButtonTable().defaults().padBottom(10.0f).minWidth(50.0f);
    dialog.button("Yes", 0);
    dialog.button("No", 1);
    dialog.button("Cancel", 2);
    dialog.getButtonTable().getCells().first().getActor().addListener(main.getHandListener());
    dialog.getButtonTable().getCells().get(1).getActor().addListener(main.getHandListener());
    dialog.getButtonTable().getCells().get(2).getActor().addListener(main.getHandListener());
    dialog.key(Input.Keys.ESCAPE, 2);
    dialog.key(Keys.ENTER, 0);
    dialog.key(Keys.SPACE, 0);
    dialog.show(main.getStage());
    return dialog;
}
 
Example #13
Source File: DialogFactory.java    From skin-composer with MIT License 5 votes vote down vote up
public Dialog yesNoDialog(String title, String text,
        ConfirmationListener listener, DialogListener dialogListener) {
    Dialog dialog = new Dialog(title, main.getSkin(), "bg") {
        @Override
        public Dialog show(Stage stage, Action action) {
            fire(new DialogEvent(DialogEvent.Type.OPEN));
            return super.show(stage, action);
        }
        @Override
        protected void result(Object object) {
            listener.selected((int) object);
            fire(new DialogEvent(DialogEvent.Type.CLOSE));
        }
    };
    
    if (dialogListener != null) {
        dialog.addListener(dialogListener);
    }

    dialog.getTitleTable().getCells().first().padLeft(5.0f);
    Label label = new Label(text, main.getSkin());
    label.setAlignment(Align.center);
    dialog.text(label);
    dialog.getContentTable().getCells().first().pad(10.0f);
    dialog.getButtonTable().defaults().padBottom(10.0f).minWidth(50.0f);
    dialog.button("Yes", 0);
    dialog.button("No", 1);
    dialog.getButtonTable().getCells().first().getActor().addListener(main.getHandListener());
    dialog.getButtonTable().getCells().get(1).getActor().addListener(main.getHandListener());
    dialog.key(Input.Keys.ESCAPE, 1);
    dialog.key(Keys.ENTER, 0);
    dialog.key(Keys.SPACE, 0);
    dialog.show(main.getStage());
    return dialog;
}
 
Example #14
Source File: DialogFactory.java    From skin-composer with MIT License 5 votes vote down vote up
public Dialog showMessageDialog(String title, String text, DialogListener dialogListener) {
    Dialog dialog = new Dialog(title, main.getSkin(), "bg") {
        @Override
        public Dialog show(Stage stage, Action action) {
            fire(new DialogEvent(DialogEvent.Type.OPEN));
            return super.show(stage, action);
        }
        @Override
        protected void result(Object object) {
            fire(new DialogEvent(DialogEvent.Type.CLOSE));
        }
    };
    
    if (dialogListener != null) {
        dialog.addListener(dialogListener);
    }
    
    dialog.getTitleTable().getCells().first().padLeft(5.0f);
    Label label = new Label(text, main.getSkin());
    label.setAlignment(Align.center);
    dialog.text(label);
    dialog.getContentTable().getCells().first().pad(10.0f);
    dialog.getButtonTable().defaults().padBottom(10.0f).minWidth(50.0f);
    dialog.button("OK");
    dialog.key(Input.Keys.ESCAPE, 0);
    dialog.key(Keys.ENTER, 0);
    dialog.key(Keys.SPACE, 0);
    dialog.show(main.getStage());
    return dialog;
}
 
Example #15
Source File: Toast.java    From vis-ui with Apache License 2.0 5 votes vote down vote up
public void fadeOut () {
	mainTable.addAction(Actions.sequence(Actions.fadeOut(VisWindow.FADE_TIME, Interpolation.fade), new Action() {
		@Override
		public boolean act (float delta) {
			toastManager.remove(Toast.this);
			return true;
		}
	}));
}
 
Example #16
Source File: DialogLoading.java    From skin-composer with MIT License 5 votes vote down vote up
@Override
public Dialog show(Stage stage) {
    Dialog dialog = super.show(stage);
    RunnableAction runnableAction = new RunnableAction();
    runnableAction.setRunnable(() -> {
        if (Utils.isMac()) {
            if (runnable != null) {
                runnable.run();
            }
            hide();
        } else {
            Thread thread = new Thread(() -> {
                if (runnable != null) {
                    runnable.run();
                }
                Gdx.app.postRunnable(() -> {
                    hide();
                });
            });
            thread.start();
        }
    });
    Action action = new SequenceAction(new DelayAction(.5f), runnableAction);
    addAction(action);
    
    return dialog;
}
 
Example #17
Source File: Core.java    From skin-composer with MIT License 5 votes vote down vote up
public static void transition(Table table1, final Table table2, float transitionTime1, final float transitionTime2) {
    table1.addAction(Actions.sequence(Actions.fadeOut(transitionTime1), new Action() {
        @Override
        public boolean act(float delta) {
            table2.setColor(1, 1, 1, 0);
            table2.setTouchable(Touchable.disabled);
            
            root.clear();
            root.add(table2).grow();
            table2.addAction(Actions.sequence(Actions.fadeIn(transitionTime2), Actions.touchable(Touchable.childrenOnly)));
            return true;
        }
    }));
}
 
Example #18
Source File: ActionsExt.java    From gdx-vfx with Apache License 2.0 5 votes vote down vote up
/** @see TimeModulationAction */
public static TimeModulationAction timeModulation(float timeFactor, Action wrappedAction) {
    TimeModulationAction action = action(TimeModulationAction.class);
    action.setAction(wrappedAction);
    action.setTimeFactor(timeFactor);
    return action;
}
 
Example #19
Source File: FileChooser.java    From gdx-soundboard with MIT License 5 votes vote down vote up
@Override
public Dialog show(Stage stage, Action action) {
    final Table content = getContentTable();
    content.add(fileListLabel).top().left().expandX().fillX().row();
    content.add(new ScrollPane(fileList, skin)).size(300, 150).fill().expand().row();

    if (fileNameEnabled) {
        content.add(fileNameLabel).fillX().expandX().row();
        content.add(fileNameInput).fillX().expandX().row();
        stage.setKeyboardFocus(fileNameInput);
    }

    if (newFolderEnabled) {
        content.add(newFolderButton).fillX().expandX().row();
    }
    
    if(directoryBrowsingEnabled){
        fileList.addListener(new ClickListener() {
            @Override
            public void clicked(InputEvent event, float x, float y) {
                final FileListItem selected = fileList.getSelected();
                if (selected.file.isDirectory()) {
                    changeDirectory(selected.file);
                }
            }
        });
    }

    this.stage = stage;
    changeDirectory(baseDir);
    return super.show(stage, action);
}
 
Example #20
Source File: ActionsExt.java    From gdx-vfx with Apache License 2.0 5 votes vote down vote up
/** @see PostAction */
public static PostAction post(int skipFrames, Action wrappedAction) {
    PostAction action = Actions.action(PostAction.class);
    action.setAction(wrappedAction);
    action.setSkipFrames(skipFrames);
    return action;
}
 
Example #21
Source File: ActionsExt.java    From gdx-texture-packer-gui with Apache License 2.0 4 votes vote down vote up
public static Action unfocus(Actor actor) {
    UnfocusAction action = action(UnfocusAction.class);
    action.setTarget(actor);
    return action;
}
 
Example #22
Source File: ActionsExt.java    From gdx-texture-packer-gui with Apache License 2.0 4 votes vote down vote up
/** @see PostAction */
public static PostAction post(Action action) {
    return PostAction.create(1, action);
}
 
Example #23
Source File: ActionsExt.java    From gdx-texture-packer-gui with Apache License 2.0 4 votes vote down vote up
/** @see PostAction */
public static PostAction post(int skipFrames, Action action) {
    return PostAction.create(skipFrames, action);
}
 
Example #24
Source File: NewFileDialog.java    From gdx-soundboard with MIT License 4 votes vote down vote up
@Override
public Dialog show(Stage stage, Action action) {
    super.show(stage, action);
    stage.setKeyboardFocus(fileName);
    return this;
}
 
Example #25
Source File: ActionsExt.java    From gdx-texture-packer-gui with Apache License 2.0 4 votes vote down vote up
public static Action unfocus() {
    return action(UnfocusAction.class);
}
 
Example #26
Source File: PostAction.java    From gdx-texture-packer-gui with Apache License 2.0 4 votes vote down vote up
public static PostAction create(int skipFrames, Action action) {
    PostAction postAction = Actions.action(PostAction.class);
    postAction.setAction(action);
    postAction.framesLeft = skipFrames;
    return postAction;
}
 
Example #27
Source File: SoundManager.java    From dice-heroes with GNU General Public License v3.0 4 votes vote down vote up
private void replaceAction(Music music, Action action) {
    Action prev = actions.put(music, action);
    if (prev != null && prev.getActor() != null)
        prev.getActor().removeAction(prev);
}
 
Example #28
Source File: CocoStudioUIEditor.java    From cocos-ui-libgdx with Apache License 2.0 4 votes vote down vote up
public Map<Actor, Action> getActorActionMap() {
    return actorActionMap;
}
 
Example #29
Source File: CocoStudioUIEditor.java    From cocos-ui-libgdx with Apache License 2.0 4 votes vote down vote up
/**
 * 查找动画
 */
public Action getAction(Actor actor) {
    return actorActionMap.get(actor);
}
 
Example #30
Source File: CocoStudioUIEditor.java    From cocos-ui-libgdx with Apache License 2.0 4 votes vote down vote up
/**
 * @param jsonFile     ui编辑成生成的json文件
 * @param textureAtlas 资源文件,传入 null表示使用小文件方式加载图片.
 * @param ttfs         字体文件集合
 * @param bitmapFonts  自定义字体文件集合
 * @param defaultFont  默认ttf字体文件
 */
public CocoStudioUIEditor(FileHandle jsonFile,
                          Map<String, FileHandle> ttfs, Map<String, BitmapFont> bitmapFonts,
                          FileHandle defaultFont, Collection<TextureAtlas> textureAtlas) {
    this.textureAtlas = textureAtlas;
    this.ttfs = ttfs;
    this.bitmapFonts = bitmapFonts;
    this.defaultFont = defaultFont;
    parsers = new HashMap<>();

    addParser(new CCButton());
    addParser(new CCCheckBox());
    addParser(new CCImageView());
    addParser(new CCLabel());
    addParser(new CCLabelBMFont());
    addParser(new CCPanel());
    addParser(new CCScrollView());
    addParser(new CCTextField());
    addParser(new CCLoadingBar());
    addParser(new CCTextAtlas());

    addParser(new CCLayer());

    addParser(new CCLabelAtlas());
    addParser(new CCSpriteView());
    addParser(new CCNode());

    addParser(new CCSlider());

    addParser(new CCParticle());
    addParser(new CCProjectNode());
    addParser(new CCPageView());

    addParser(new CCTImageView());

    actors = new HashMap<String, Array<Actor>>();
    actionActors = new HashMap<Integer, Actor>();

    //animations = new HashMap<String, Map<Actor, Action>>();

    actorActionMap = new HashMap<Actor, Action>();

    dirName = jsonFile.parent().toString();

    if (!dirName.equals("")) {
        dirName += File.separator;
    }
    String json = jsonFile.readString("utf-8");
    Json jj = new Json();
    jj.setIgnoreUnknownFields(true);
    export = jj.fromJson(CCExport.class, json);
}