Java Examples for com.badlogic.gdx.utils.SnapshotArray
The following java examples will help you to understand the usage of com.badlogic.gdx.utils.SnapshotArray. These source code samples are taken from different open source projects.
Example 1
Project: snappyfrog-master File: Salary.java View source code |
@Override
public void act(float delta) {
super.act(delta);
// Move
if (leftToRight)
moveBy(SPEED * delta, 0);
else
moveBy(-SPEED * delta, 0);
// Check for out of bounds
if (getX() + getWidth() < -1 || getX() > Game.getWidth() + 1) {
parent.removeSalary(this);
} else if (!hit) {
SnapshotArray<Actor> lasers = parent.lasersGroup.getChildren();
Actor laser;
for (int i = 0; i < lasers.size; i++) {
laser = lasers.get(i);
if (laser.getX() > getX() && laser.getX() < getX() + getWidth() && laser.getY() < getY() + getHeight() && laser.getY() > getY()) {
hit = true;
Game.getCrashSound().play();
explosion.setPosition(getX(), getY());
explosion.explode();
// Bounce down
addAction(Actions.moveBy(0, ResHelper.LinearHeightValue(-100.0f), 1.0f, Interpolation.circleOut));
// remove laser
parent.removeLaserBeam((LaserBeam) laser);
parent.increaseSalaryHitCount();
break;
}
}
} else {
explosion.act(delta);
}
}
Example 2
Project: overlap2d-runtime-libgdx-master File: CompositeSystem.java View source code |
private void recalculateSize() {
float lowerX = Float.MAX_VALUE;
float lowerY = Float.MAX_VALUE;
float upperX = Float.MIN_VALUE;
float upperY = Float.MIN_VALUE;
SnapshotArray<Entity> entities = nodeComponent.children;
for (Entity entity : entities) {
TransformComponent transformComponent = transformMapper.get(entity);
DimensionsComponent childDimCom = dimensionsMapper.get(entity);
float x = transformComponent.x;
float y = transformComponent.y;
float width = childDimCom.width;
float height = childDimCom.height;
Matrix3 transMat = TransformMathUtils.transform(transformComponent);
p1.set(x, y).mul(transMat);
p2.set(x + width, y).mul(transMat);
p3.set(x + width, y + height).mul(transMat);
p4.set(x, y + height).mul(transMat);
tmpBoundPoints.set(lowerX, 0);
lowerX = getX(MinMaxOp.MIN, p1, p2, p3, p4, tmpBoundPoints);
tmpBoundPoints.set(upperX, 0);
upperX = getX(MinMaxOp.MAX, p1, p2, p3, p4, tmpBoundPoints);
tmpBoundPoints.set(0, lowerY);
lowerY = getY(MinMaxOp.MIN, p1, p2, p3, p4, tmpBoundPoints);
tmpBoundPoints.set(0, upperY);
upperY = getY(MinMaxOp.MAX, p1, p2, p3, p4, tmpBoundPoints);
}
for (Entity entity : entities) {
if (lowerX == 0 && lowerY == 0)
break;
TransformComponent transformComponent = transformMapper.get(entity);
transformComponent.x -= lowerX;
transformComponent.y -= lowerY;
}
dimensionsComponent.width = (upperX - lowerX);
dimensionsComponent.height = (upperY - lowerY);
lowerX = 0;
lowerY = 0;
dimensionsComponent.boundBox.set(lowerX, lowerY, dimensionsComponent.width, dimensionsComponent.height);
}
Example 3
Project: maps-editor-master File: HorizontalFlowGroup.java View source code |
private void computeSize() {
prefWidth = 0;
prefHeight = 0;
sizeInvalid = false;
SnapshotArray<Actor> children = getChildren();
float groupWidth = getWidth();
float x = 0;
float maxHeight = 0;
for (int i = 0, n = children.size; i < n; i++) {
Actor child = children.get(i);
float width = child.getWidth();
float height = child.getHeight();
if (child instanceof Layout) {
Layout layout = (Layout) child;
width = layout.getPrefWidth();
height = layout.getPrefHeight();
}
if (x + width <= groupWidth) {
prefWidth += width + spacing;
x += width + spacing;
maxHeight = Math.max(height, maxHeight);
} else {
prefHeight += maxHeight + spacing;
maxHeight = height;
x = width + spacing;
}
}
prefHeight += maxHeight;
}
Example 4
Project: libgdx-cocostudio-master File: Stage.java View source code |
/**
* Applies a touch moved event to the stage and returns true if an actor in the scene {@link Event#handle() handled}
* the event. Only {@link InputListener listeners} that returned true for touchDown will receive this event.
*/
public boolean touchDragged(int screenX, int screenY, int pointer) {
pointerScreenX[pointer] = screenX;
pointerScreenY[pointer] = screenY;
if (touchFocuses.size == 0)
return false;
screenToStageCoordinates(stageCoords.set(screenX, screenY));
InputEvent event = Pools.obtain(InputEvent.class);
event.setType(Type.touchDragged);
event.setStage(this);
event.setStageX(stageCoords.x);
event.setStageY(stageCoords.y);
event.setPointer(pointer);
SnapshotArray<TouchFocus> touchFocuses = this.touchFocuses;
TouchFocus[] focuses = touchFocuses.begin();
for (int i = 0, n = touchFocuses.size; i < n; i++) {
TouchFocus focus = focuses[i];
if (focus.pointer != pointer)
continue;
event.setTarget(focus.target);
event.setListenerActor(focus.listenerActor);
if (focus.listener.handle(event))
event.handle();
}
touchFocuses.end();
boolean handled = event.isHandled();
Pools.free(event);
return handled;
}
Example 5
Project: bladecoder-adventure-engine-master File: PropertyTable.java View source code |
@SuppressWarnings("unchecked")
public void setProperty(String name, String value) {
SnapshotArray<Actor> actors = table.getChildren();
for (Actor a : actors) {
if (name.equals(a.getName())) {
if (a instanceof SelectBox<?>) {
((SelectBox<String>) a).setSelected(value == null ? "" : value);
} else {
((TextField) a).setText(value == null ? "" : value);
}
return;
}
}
}
Example 6
Project: Missing_Words-master File: NPCPlayer.java View source code |
@Override public void run() { SnapshotArray<Actor> array = new SnapshotArray<>(); int score = 0; // Obtenemos la palabra en un array de Tiles array = submitBox.getChildren(); /* * Con la clase StringBuilder creamos un array de strings a partir del array de * Tiles */ StringBuilder word = new StringBuilder(); for (int i = 0; i < array.size; ++i) { Tile t = (Tile) array.get(i); if (i == 0) word.append(t.getLetter().toUpperCase()); else // a�adimos la letra al array de strings word.append(t.getLetter().toUpperCase()); // sumamos los puntos de la Tile score += t.getPoints(); } /* Reproducimos el efecto de sonido si est� activo */ missingWords.getSoundFX().getPositiveSound().play(missingWords.getSoundFX().getVolume()); /* Incrementamos el n�mero de palabras formadas */ missingWords.getGameScreen().increaseTotalWords(); /* Asignamos las tiradas correspondientes en base a la puntuaci�n */ calculateRolls(score); /* La m�quina juega el minijuego */ playMinigame(); /* Restablecemos el score */ missingWords.getGameScreen().getWordScore().setScore(0); /* Finaliza el turno de la m�quina */ setMyTurn(false); }
Example 7
Project: netthreads-libgdx-master File: SceneHelper.java View source code |
/**
* 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;
}
Example 8
Project: overlap2d-master File: SandboxMediator.java View source code |
private void initItemListeners() {
Engine engine = getViewComponent().getEngine();
Family rootFamily = Family.all(ViewPortComponent.class).get();
Entity rootEntity = engine.getEntitiesFor(rootFamily).iterator().next();
NodeComponent nodeComponent = ComponentRetriever.get(rootEntity, NodeComponent.class);
SnapshotArray<Entity> childrenEntities = nodeComponent.children;
for (Entity child : childrenEntities) {
addListenerToItem(child);
}
}
Example 9
Project: Scene3d-master File: Stage3d.java View source code |
public Actor3d getObject(int screenX, int screenY) {
Actor3d temp = null;
SnapshotArray<Actor3d> children = root.getChildren();
Actor3d[] actors = children.begin();
for (int i = 0, n = children.size; i < n; i++) {
temp = hit3d(screenX, screenY, actors[i]);
if (actors[i] instanceof Group3d)
temp = hit3d(screenX, screenY, (Group3d) actors[i]);
}
children.end();
return temp;
}
Example 10
Project: libgdx-master File: Stage.java View source code |
/** Applies a touch moved event to the stage and returns true if an actor in the scene {@link Event#handle() handled} the
* event. Only {@link InputListener listeners} that returned true for touchDown will receive this event. */
public boolean touchDragged(int screenX, int screenY, int pointer) {
pointerScreenX[pointer] = screenX;
pointerScreenY[pointer] = screenY;
mouseScreenX = screenX;
mouseScreenY = screenY;
if (touchFocuses.size == 0)
return false;
screenToStageCoordinates(tempCoords.set(screenX, screenY));
InputEvent event = Pools.obtain(InputEvent.class);
event.setType(Type.touchDragged);
event.setStage(this);
event.setStageX(tempCoords.x);
event.setStageY(tempCoords.y);
event.setPointer(pointer);
SnapshotArray<TouchFocus> touchFocuses = this.touchFocuses;
TouchFocus[] focuses = touchFocuses.begin();
for (int i = 0, n = touchFocuses.size; i < n; i++) {
TouchFocus focus = focuses[i];
if (focus.pointer != pointer)
continue;
// Touch focus already gone.
if (!touchFocuses.contains(focus, true))
continue;
event.setTarget(focus.target);
event.setListenerActor(focus.listenerActor);
if (focus.listener.handle(event))
event.handle();
}
touchFocuses.end();
boolean handled = event.isHandled();
Pools.free(event);
return handled;
}
Example 11
Project: Cardshifter-master File: DeckBuilderScreen.java View source code |
private DeckCardView labelFor(int id) {
SnapshotArray<Actor> children = cardsInDeckList.getChildren();
int index = 0;
String name = (String) config.getCardData().get(id).getProperties().get("name");
for (Actor actor : children) {
DeckCardView view = (DeckCardView) actor;
if (view.getId() == id) {
return view;
}
if (name.compareTo(view.getName()) < 0) {
break;
}
index++;
}
DeckCardView view = new DeckCardView(game.skin, id, name, this);
cardsInDeckList.addActorAt(index, view);
return view;
}
Example 12
Project: RogueLike-master File: HorizontalFlowGroup.java View source code |
private void computeSize() {
prefWidth = 0;
prefHeight = 0;
sizeInvalid = false;
SnapshotArray<Actor> children = getChildren();
float groupWidth = getWidth();
float x = 0;
float maxHeight = 0;
for (int i = 0, n = children.size; i < n; i++) {
Actor child = children.get(i);
float width = child.getWidth();
float height = child.getHeight();
if (child instanceof Layout) {
Layout layout = (Layout) child;
width = layout.getPrefWidth();
height = layout.getPrefHeight();
}
if (x + width <= groupWidth) {
prefWidth += width + spacing;
x += width + spacing;
maxHeight = Math.max(height, maxHeight);
} else {
prefHeight += maxHeight + spacing;
maxHeight = height;
x = width + spacing;
}
}
prefHeight += maxHeight;
}
Example 13
Project: gdx-lml-master File: GdxArrays.java View source code |
/** @return a new, empty SnapshotArray. * @param <Type> type of stored elements. */ public static <Type> SnapshotArray<Type> newSnapshotArray() { return new SnapshotArray<Type>(); }
Example 14
Project: Sink-master File: Sink.java View source code |
public static SnapshotArray<Actor> getChildren() {
return stage.getRoot().getChildren();
}
Example 15
Project: gdx-kiwi-master File: GdxArrays.java View source code |
/** @return a new, empty SnapshotArray. * @param <Type> type of stored elements. */ public static <Type> SnapshotArray<Type> newSnapshotArray() { return new SnapshotArray<Type>(); }