Search in sources :

Example 1 with EventListener

use of com.badlogic.gdx.scenes.scene2d.EventListener in project Catacomb-Snatch by Catacomb-Snatch.

the class MenuScene method init.

protected void init() {
    // Set actor width
    for (Actor actor : getActors()) {
        actor.setWidth(150);
        actor.addListener(new EventListener() {

            @Override
            public boolean handle(Event event) {
                aniY = (int) event.getListenerActor().getY();
                return true;
            }
        });
    }
    // Set index to the topmost actor
    index = getActors().size - 1;
    // Properly place actors
    update(true);
}
Also used : Actor(com.badlogic.gdx.scenes.scene2d.Actor) KeyReleaseEvent(net.catacombsnatch.game.event.input.events.KeyReleaseEvent) Event(com.badlogic.gdx.scenes.scene2d.Event) EventListener(com.badlogic.gdx.scenes.scene2d.EventListener)

Example 2 with EventListener

use of com.badlogic.gdx.scenes.scene2d.EventListener in project Catacomb-Snatch by Catacomb-Snatch.

the class Scene method tick.

@Override
public void tick(float delta) {
    // Draw background
    if (drawBackground && background != null) {
        getBatch().begin();
        getBatch().setColor(backgroundColor);
        getBatch().draw(background, 0, 0, Screen.getWidth(), Screen.getHeight());
        getBatch().end();
    }
    // Updating mouse dependent stuff in render()
    if (!Gdx.input.isTouched()) {
        mousePos = screenToStageCoordinates(mousePos.set(Gdx.input.getX(), Gdx.input.getY()));
        for (Actor a : getActors()) {
            currentActorRect.set(a.getX(), a.getY(), a.getWidth(), a.getHeight());
            for (EventListener el : a.getListeners()) {
                if (!(el instanceof InputListener))
                    continue;
                InputListener il = (InputListener) el;
                if (currentActorRect.contains(mousePos.x, mousePos.y)) {
                    il.enter(null, mousePos.x, mousePos.y, -1, null);
                } else {
                    il.exit(null, mousePos.x, mousePos.y, -1, null);
                }
            }
        }
    }
    super.draw();
    getBatch().begin();
}
Also used : InputListener(com.badlogic.gdx.scenes.scene2d.InputListener) Actor(com.badlogic.gdx.scenes.scene2d.Actor) EventListener(com.badlogic.gdx.scenes.scene2d.EventListener)

Aggregations

Actor (com.badlogic.gdx.scenes.scene2d.Actor)2 EventListener (com.badlogic.gdx.scenes.scene2d.EventListener)2 Event (com.badlogic.gdx.scenes.scene2d.Event)1 InputListener (com.badlogic.gdx.scenes.scene2d.InputListener)1 KeyReleaseEvent (net.catacombsnatch.game.event.input.events.KeyReleaseEvent)1