Search in sources :

Example 1 with Action

use of com.almasb.fxgl.entity.action.Action in project FXGL by AlmasB.

the class EntityActionSample method initInput.

@Override
protected void initInput() {
    getInput().addAction(new UserAction("Move Now") {

        @Override
        protected void onActionBegin() {
            entity.getControl(ActionControl.class).clearActions();
            entity.getControl(ActionControl.class).addAction(new MoveAction(getInput().getMouseXWorld(), getInput().getMouseYWorld()));
        }
    }, MouseButton.PRIMARY);
    getInput().addAction(new UserAction("Queue Move Action") {

        @Override
        protected void onActionBegin() {
            entity.getControl(ActionControl.class).addAction(new MoveAction(getInput().getMouseXWorld(), getInput().getMouseYWorld()));
        }
    }, MouseButton.SECONDARY);
    getInput().addAction(new UserAction("Remove Current Action") {

        @Override
        protected void onActionBegin() {
            Action<?> a = actionsView.getSelectionModel().getSelectedItem();
            if (a != null) {
                entity.getControl(ActionControl.class).removeAction(a);
            }
        }
    }, KeyCode.F);
}
Also used : UserAction(com.almasb.fxgl.input.UserAction) Action(com.almasb.fxgl.entity.action.Action) UserAction(com.almasb.fxgl.input.UserAction)

Example 2 with Action

use of com.almasb.fxgl.entity.action.Action in project FXGL by AlmasB.

the class EntityActionSample method initInput.

@Override
protected void initInput() {
    getInput().addAction(new UserAction("Move Now") {

        @Override
        protected void onActionBegin() {
            entity.getComponent(ActionComponent.class).cancelActions();
            entity.getComponent(ActionComponent.class).addAction(new MoveAction(getInput().getMouseXWorld(), getInput().getMouseYWorld()));
        }
    }, MouseButton.SECONDARY);
    getInput().addAction(new UserAction("Queue Move Action") {

        @Override
        protected void onActionBegin() {
            entity.getComponent(ActionComponent.class).addAction(new MoveAction(getInput().getMouseXWorld(), getInput().getMouseYWorld()));
        }
    }, MouseButton.PRIMARY);
    getInput().addAction(new UserAction("Remove Current Action") {

        @Override
        protected void onActionBegin() {
            Action a = actionsView.getSelectionModel().getSelectedItem();
            if (a != null) {
                entity.getComponent(ActionComponent.class).removeAction(a);
            }
        }
    }, KeyCode.F);
}
Also used : UserAction(com.almasb.fxgl.input.UserAction) Action(com.almasb.fxgl.entity.action.Action) UserAction(com.almasb.fxgl.input.UserAction) ContinuousAction(com.almasb.fxgl.entity.action.ContinuousAction) InstantAction(com.almasb.fxgl.entity.action.InstantAction)

Aggregations

Action (com.almasb.fxgl.entity.action.Action)2 UserAction (com.almasb.fxgl.input.UserAction)2 ContinuousAction (com.almasb.fxgl.entity.action.ContinuousAction)1 InstantAction (com.almasb.fxgl.entity.action.InstantAction)1