/** Sets the y position where the sprite will be drawn. If origin, rotation, or scale are changed, it is slightly more efficient * to set the position after those operations. If both position and size are to be changed, it is better to use * {@link #setBounds(float, float, float, float)}. */ public void setY (float y) { translateY(y - this.y); }
/** Sets the y position where the sprite will be drawn. If origin, rotation, or scale are changed, it is slightly more efficient * to set the position after those operations. If both position and size are to be changed, it is better to use * {@link #setBounds(float, float, float, float)}. */ public void setY (float y) { translateY(y - this.y); }
/** Sets the y position where the sprite will be drawn. If origin, rotation, or scale are changed, it is slightly more efficient * to set the position after those operations. If both position and size are to be changed, it is better to use * {@link #setBounds(float, float, float, float)}. */ public void setY (float y) { translateY(y - this.y); }
for (Sprite sprite : enemies){ sprite.translateY(deltaTime * ENEMY_SPEED); }
Sprite cape; switch (frame) { case 0: cape = modules.get(Module.CAPE); //cape.setRegion(region); cape.translateY(+1); break; case 1: cape = modules.get(Module.CAPE); //cape.setRegion(region); cape.translateY(-1); break; default: throw new IllegalArgumentException( "Undefined frame number: " + frame); }
public void draw(SpriteBatch batch) { for (Iterator<Sprite> iterator = enemies.iterator(); iterator.hasNext();) { Sprite drawEnemy = iterator.next(); drawEnemy.draw(batch); drawEnemy.translateY(deltaTime * movement); if (touched((drawEnemy.getX(),drawEnemy.getY(), drawEnemy.getWidth(),drawEnemy.getHeight())){ iterator.remove(); Pools.free(sprite); } } }
private Vector3 TMPVEC = new Vector3(); public void update (Camera camera, float deltaTime) { boolean checkTouch = Gdx.input.justTouched(); if (checkTouch) { TMPVEC.set(Gdx.input.getX(), Gdx.input.getY(), 0); camera.unproject(TMPVEC); } //This way we only unproject the point once for all sprites for (Iterator<Sprite> iterator = enemies.iterator(); iterator.hasNext();) { Sprite enemy = iterator.next(); enemy.translateY(deltaTime * movement); if (checkTouch && touched(enemy, TMPVEC)){ iterator.remove(); Pools.free(sprite); } } } private void touched (Sprite sprite, Vector3 touchPoint){ return sprite.getX() <= touchPoint.x && sprite.getX() + sprite.getWidth() <= touchPoint.x; } public void draw (SpriteBatch batch){ for (Sprite sprite : enemies) sprite.draw(batch); }