use of com.badlogic.gdx.scenes.scene2d.Actor in project netthreads-libgdx by alistairrutherford.
the class SceneHelper method hit.
/**
* Find hit class.
*
* @param x
* Current x position.
* @param y
* Current y position
* @param group
* The starting Group.
* @param targetClass
* The target class type.
*
* @return The target or null if not found.
*/
@SuppressWarnings("rawtypes")
public static Actor hit(float x, float y, Group group, Class targetClass) {
SnapshotArray<Actor> children = group.getChildren();
Actor hit = null;
boolean found = false;
int index = children.size - 1;
while (!found && index >= 0) {
Actor child = children.get(index);
if (child.getClass().isAssignableFrom(targetClass)) {
point.x = x;
point.y = y;
group.localToDescendantCoordinates(child, point);
if (child.hit(point.x, point.y, true) != null) {
found = true;
hit = child;
} else if (child instanceof Group) {
child = hit(x, y, (Group) child, targetClass);
}
}
index--;
}
return hit;
}
use of com.badlogic.gdx.scenes.scene2d.Actor in project netthreads-libgdx by alistairrutherford.
the class SceneHelper method hit.
/**
* Look for target hit of specified class.
*
* @param x
* Current x position.
* @param y
* Current y position
* @param stage
* The starting stage.
* @param targetClass
* The target class type.
* @return Target class or null if not found.
*/
@SuppressWarnings("rawtypes")
public static Actor hit(float x, float y, Stage stage, Class targetClass) {
Group root = stage.getRoot();
SnapshotArray<Actor> children = root.getChildren();
Actor hit = null;
boolean found = false;
int index = children.size - 1;
while (!found && index >= 0) {
Actor child = children.get(index);
point.x = x;
point.y = y;
root.localToDescendantCoordinates(child, point);
Actor childHit = root.hit(point.x, point.y, true);
if (childHit != null && childHit.getClass().isAssignableFrom(targetClass)) {
found = true;
hit = childHit;
} else {
index--;
}
}
return hit;
}
use of com.badlogic.gdx.scenes.scene2d.Actor 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();
}
use of com.badlogic.gdx.scenes.scene2d.Actor in project Entitas-Java by Rubentxu.
the class GUIManagerGDX method createGUIElement.
@Override
public Actor createGUIElement(String name) {
GUIFactory<Actor, GUIManagerGDX> factory = guiFactories.get(name);
Actor element = null;
if (factory != null) {
element = factory.create(this);
}
return element;
}
use of com.badlogic.gdx.scenes.scene2d.Actor in project Entitas-Java by Rubentxu.
the class GuiFactory method createTouchPad.
public Touchpad createTouchPad(float width, float height, InputEntity player) {
Touchpad touchpad = new Touchpad(10 * ScaleUtil.getSizeRatio(), skin);
touchpad.setPosition(25 * ScaleUtil.getSizeRatio(), 15);
touchpad.setWidth(width);
touchpad.setHeight(height);
PlayerInputController stateController = player.getPlayerInputController();
touchpad.addListener(new ChangeListener() {
@Override
public void changed(ChangeEvent event, Actor actor) {
System.out.println("PercentX " + ((Touchpad) actor).getKnobPercentX() + "PercentY " + ((Touchpad) actor).getKnobPercentY());
if (((Touchpad) actor).getKnobPercentX() == 0 || ((Touchpad) actor).getKnobPercentX() < 0.5 && ((Touchpad) actor).getKnobPercentX() > -0.5) {
// controller.rightReleased();
// controller.leftReleased();
player.replacePlayerInputController(false, false, stateController.jumpPressed);
}
if (((Touchpad) actor).getKnobPercentX() > 0.5) {
// controller.rightPressed();
// controller.leftReleased();
player.replacePlayerInputController(false, true, stateController.jumpPressed);
}
if (((Touchpad) actor).getKnobPercentX() < -0.5) {
// controller.leftPressed();
// controller.rightReleased();
player.replacePlayerInputController(true, false, stateController.jumpPressed);
}
if (((Touchpad) actor).getKnobPercentY() > 0.5) {
// controller.jumpPressed();
player.replacePlayerInputController(stateController.leftPressed, stateController.rightPressed, true);
} else {
// controller.jumpReleased();
player.replacePlayerInputController(stateController.leftPressed, stateController.rightPressed, false);
}
}
});
return touchpad;
}
Aggregations