Java Code Examples for com.badlogic.gdx.utils.Pools#obtain()
The following examples show how to use
com.badlogic.gdx.utils.Pools#obtain() .
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: ControllerMenuStage.java From gdx-controllerutils with Apache License 2.0 | 6 votes |
protected boolean fireEventOnActor(Actor actor, InputEvent.Type type, int pointer, Actor related) { if (actor == null || !isActorFocusable(actor) || !isActorHittable(actor)) return false; InputEvent event = Pools.obtain(InputEvent.class); event.setType(type); event.setStage(this); event.setRelatedActor(related); event.setPointer(pointer); event.setButton(pointer); event.setStageX(0); event.setStageY(0); actor.fire(event); boolean handled = event.isHandled(); Pools.free(event); return handled; }
Example 2
Source File: Scene2dUtils.java From gdx-vfx with Apache License 2.0 | 6 votes |
public static void simulateClickGlobal(Actor actor, int button, int pointer, float stageX, float stageY) { InputEvent event = Pools.obtain(InputEvent.class); event.setStage(actor.getStage()); event.setRelatedActor(actor); event.setTarget(actor); event.setStageX(stageX); event.setStageY(stageY); event.setButton(button); event.setPointer(pointer); event.setType(InputEvent.Type.touchDown); actor.notify(event, false); event.setType(InputEvent.Type.touchUp); actor.notify(event, false); Pools.free(event); }
Example 3
Source File: GameServicesMultiplayer.java From dice-heroes with GNU General Public License v3.0 | 6 votes |
@SuppressWarnings("unchecked") public void loadInvitations(InvitationBuffer invitations) { ObjectSet<String> tmp = Pools.obtain(ObjectSet.class); tmp.addAll(invites); invites.clear(); for (Invitation invitation : invitations) { invites.add(invitation.getInvitationId()); if (!tmp.contains(invitation.getInvitationId())) { showInvitation(invitation); } } tmp.clear(); Pools.free(tmp); Gdx.app.postRunnable(new Runnable() { @Override public void run() { invitesDispatcher.setState(invites.size); } }); }
Example 4
Source File: ProgressBar.java From cocos-ui-libgdx with Apache License 2.0 | 6 votes |
/** * Sets the progress bar position, rounded to the nearest step size and clamped to the minumum and maximim values. * {@link #clamp(float)} can be overidden to allow values outside of the progress bars min/max range. * * @return false if the value was not changed because the progress bar already had the value or it was canceled by a listener. */ public boolean setValue(float value) { value = snap(clamp(Math.round(value / stepSize) * stepSize)); float oldValue = this.value; if (value == oldValue) { return false; } float oldVisualValue = getVisualValue(); this.value = value; ChangeEvent changeEvent = Pools.obtain(ChangeEvent.class); boolean cancelled = fire(changeEvent); if (cancelled) { this.value = oldValue; } else if (animateDuration > 0) { animateFromValue = oldVisualValue; animateTime = animateDuration; } Pools.free(changeEvent); return !cancelled; }
Example 5
Source File: SeekBar.java From gdx-texture-packer-gui with Apache License 2.0 | 6 votes |
/** * Called by {@link SeekBarModel}. Notifies when underlying model value has changed and text field and slider must update. * Typically there is no need to call this method manually. * @param fireEvent if true then {@link ChangeListener.ChangeEvent} will be fired */ public void notifyValueChanged (boolean updateTextField, boolean updateSlider, boolean fireEvent) { if (updateTextField) { VisValidatableTextField textField = getTextField(); int cursor = textField.getCursorPosition(); textField.setCursorPosition(0); this.setListenTextChangeEvents(false); textField.setText(model.prepareTextValue()); this.setListenTextChangeEvents(true); textField.setCursorPosition(cursor); } if (updateSlider) { VisSlider slider = getSlider(); this.setListenSliderChangeEvents(false); slider.setValue(model.prepareSliderValue()); this.setListenSliderChangeEvents(true); } if (fireEvent) { ChangeListener.ChangeEvent changeEvent = Pools.obtain(ChangeListener.ChangeEvent.class); fire(changeEvent); Pools.free(changeEvent); } }
Example 6
Source File: Scene2dUtils.java From gdx-texture-packer-gui with Apache License 2.0 | 6 votes |
public static void simulateClickGlobal(Actor actor, int button, int pointer, float stageX, float stageY) { InputEvent event = Pools.obtain(InputEvent.class); event.setStage(actor.getStage()); event.setRelatedActor(actor); event.setTarget(actor); event.setStageX(stageX); event.setStageY(stageY); event.setButton(button); event.setPointer(pointer); event.setType(InputEvent.Type.touchDown); actor.notify(event, false); event.setType(InputEvent.Type.touchUp); actor.notify(event, false); Pools.free(event); }
Example 7
Source File: EventUtils.java From riiablo with Apache License 2.0 | 6 votes |
public static boolean click(Button button) { if (button.isDisabled()) return false; InputEvent event = Pools.obtain(InputEvent.class); event.setType(InputEvent.Type.touchDown); event.setStage(button.getStage()); event.setStageX(0); event.setStageY(0); event.setPointer(0); event.setButton(Input.Buttons.LEFT); event.setListenerActor(button); button.fire(event); event.setType(InputEvent.Type.touchUp); button.fire(event); Pools.free(event); return true; }
Example 8
Source File: TabbedPane.java From gdx-ai with Apache License 2.0 | 5 votes |
/** Sends a ChangeEvent, with this TabbedPane as the target, to each registered listener. This method is called each time there * is a change to the selected index. */ protected void fireStateChanged () { ChangeEvent changeEvent = Pools.obtain(ChangeEvent.class); changeEvent.setBubbles(false); fire(changeEvent); Pools.free(changeEvent); }
Example 9
Source File: ChainLight.java From box2dlights with Apache License 2.0 | 5 votes |
@Override public boolean contains(float x, float y) { // fast fail if (!this.chainLightBounds.contains(x, y)) return false; // actual check FloatArray vertices = Pools.obtain(FloatArray.class); vertices.clear(); for (int i = 0; i < rayNum; i++) { vertices.addAll(mx[i], my[i]); } for (int i = rayNum - 1; i > -1; i--) { vertices.addAll(startX[i], startY[i]); } int intersects = 0; for (int i = 0; i < vertices.size; i += 2) { float x1 = vertices.items[i]; float y1 = vertices.items[i + 1]; float x2 = vertices.items[(i + 2) % vertices.size]; float y2 = vertices.items[(i + 3) % vertices.size]; if (((y1 <= y && y < y2) || (y2 <= y && y < y1)) && x < ((x2 - x1) / (y2 - y1) * (y - y1) + x1)) intersects++; } boolean result = (intersects & 1) == 1; Pools.free(vertices); return result; }
Example 10
Source File: ChainLight.java From box2dlights with Apache License 2.0 | 5 votes |
/** * Draws a polygon, using ray start and end points as vertices */ public void debugRender(ShapeRenderer shapeRenderer) { shapeRenderer.setColor(Color.YELLOW); FloatArray vertices = Pools.obtain(FloatArray.class); vertices.clear(); for (int i = 0; i < rayNum; i++) { vertices.addAll(mx[i], my[i]); } for (int i = rayNum - 1; i > -1; i--) { vertices.addAll(startX[i], startY[i]); } shapeRenderer.polygon(vertices.shrink()); Pools.free(vertices); }
Example 11
Source File: ChannelBar.java From vis-ui with Apache License 2.0 | 5 votes |
private void updateValueFromTouch (float x) { int newValue = (int) (x / BasicColorPicker.BAR_WIDTH * maxValue / sizes.scaleFactor); setValue(newValue); ChangeEvent changeEvent = Pools.obtain(ChangeEvent.class); fire(changeEvent); Pools.free(changeEvent); }
Example 12
Source File: Palette.java From vis-ui with Apache License 2.0 | 5 votes |
private void updateValueFromTouch (float touchX, float touchY) { int newV = (int) (touchX / BasicColorPicker.PALETTE_SIZE * maxValue / sizes.scaleFactor); int newS = (int) (touchY / BasicColorPicker.PALETTE_SIZE * maxValue / sizes.scaleFactor); setValue(newS, newV); ChangeEvent changeEvent = Pools.obtain(ChangeEvent.class); fire(changeEvent); Pools.free(changeEvent); }
Example 13
Source File: VerticalChannelBar.java From vis-ui with Apache License 2.0 | 5 votes |
private void updateValueFromTouch (float y) { int newValue = (int) (y / BasicColorPicker.PALETTE_SIZE * maxValue / sizes.scaleFactor); setValue(newValue); ChangeEvent changeEvent = Pools.obtain(ChangeEvent.class); fire(changeEvent); Pools.free(changeEvent); }
Example 14
Source File: Spinner.java From vis-ui with Apache License 2.0 | 5 votes |
/** * Called by {@link SpinnerModel}. Notifies when underlying model value has changed and spinner text field must updated. * Typically there is no need to call this method manually. * @param fireEvent if true then {@link ChangeListener.ChangeEvent} will be fired */ public void notifyValueChanged (boolean fireEvent) { VisValidatableTextField textField = getTextField(); int cursor = textField.getCursorPosition(); textField.setCursorPosition(0); textField.setText(model.getText()); textField.setCursorPosition(cursor); if (fireEvent) { ChangeListener.ChangeEvent changeEvent = Pools.obtain(ChangeListener.ChangeEvent.class); fire(changeEvent); Pools.free(changeEvent); } }
Example 15
Source File: Audio.java From riiablo with Apache License 2.0 | 5 votes |
static Instance obtain(AssetDescriptor descriptor, Object delegate, long id) { Instance instance = Pools.obtain(Instance.class); instance.descriptor = descriptor; instance.stream = delegate instanceof Music; instance.delegate = delegate; instance.id = id; return instance; }
Example 16
Source File: ParticleActor.java From dice-heroes with GNU General Public License v3.0 | 5 votes |
@Override public void draw(Batch batch, float parentAlpha) { effect.setPosition(getX(), getY()); Color c = getColor(); batch.setColor(c.r, c.g, c.b, c.a * parentAlpha); effect.draw(batch, Gdx.graphics.getDeltaTime()); if (effect.isComplete()) { ChangeListener.ChangeEvent event = Pools.obtain(ChangeListener.ChangeEvent.class); fire(event); Pools.free(event); } }
Example 17
Source File: SpawnController.java From dice-heroes with GNU General Public License v3.0 | 5 votes |
@SuppressWarnings("unchecked") private void autoPlace() { if (placed.size > 0) { ObjectSet<Creature> tmp = Pools.obtain(ObjectSet.class); tmp.addAll(placed); for (Creature c : tmp) { removeFromPlaced(c); } tmp.clear(); Pools.free(tmp); } Array<Grid2D.Coordinate> coordinates = Pools.obtain(Array.class); Set<Map.Entry<Grid2D.Coordinate, Fraction>> spawns = world.level.getElements(LevelElementType.spawn); for (Map.Entry<Grid2D.Coordinate, Fraction> e : spawns) { if (e.getValue() == world.viewer.fraction) { coordinates.add(e.getKey()); } } coordinates.shuffle(); int usedCount = Math.min(creatures.size, coordinates.size); Array<Creature> toPlace = Pools.obtain(Array.class); toPlace.addAll(creatures); toPlace.shuffle(); toPlace.truncate(usedCount); for (Creature creature : toPlace) { Grid2D.Coordinate coordinate = coordinates.pop(); place(creature, coordinate.x(), coordinate.y()); } toPlace.clear(); coordinates.clear(); Pools.free(toPlace); Pools.free(coordinates); }
Example 18
Source File: MenuItem.java From vis-ui with Apache License 2.0 | 4 votes |
void fireChangeEvent () { ChangeListener.ChangeEvent changeEvent = Pools.obtain(ChangeListener.ChangeEvent.class); fire(changeEvent); Pools.free(changeEvent); }