@Override public float getY () { return super.getY() - region.offsetY; }
@Override public float getY () { return super.getY() - region.offsetY; }
y = editor.renderer.bgImage.getY(); w = editor.renderer.bgImage.getWidth(); h = editor.renderer.bgImage.getHeight();
y = editor.renderer.bgImage.getY(); w = editor.renderer.bgImage.getWidth(); h = editor.renderer.bgImage.getHeight();
private void renderSingleLine () { String text = "Single Line"; float x = logoSprite.getX(); float y = logoSprite.getY(); float width = logoSprite.getWidth(); float height = logoSprite.getHeight(); layout.setText(font, text); x += width / 2 - layout.width / 2; y += height / 2 + layout.height / 2; font.draw(spriteBatch, text, x, y); }
private void renderMultiLine () { String text = "Multi\nLine"; float x = logoSprite.getX(); float y = logoSprite.getY(); float width = logoSprite.getWidth(); float height = logoSprite.getHeight(); layout.setText(font, text); x += width / 2 - layout.width / 2; y += height / 2 + layout.height / 2; font.draw(spriteBatch, text, x, y); // Note that multi line text can be aligned: // font.draw(spriteBatch, text, x, y, width, Align.center, false); }
private void renderWrapped () { String text = "Wrapped Wrapped Wrapped Wrapped"; float x = logoSprite.getX(); float y = logoSprite.getY(); float width = logoSprite.getWidth(); float height = logoSprite.getHeight(); layout.setText(font, text, Color.WHITE, width, Align.left, true); x += width / 2 - layout.width / 2; y += height / 2 + layout.height / 2; font.draw(spriteBatch, text, x, y, width, Align.left, true); // More efficient to draw the layout used for bounds: // font.draw(spriteBatch, layout, x, y); // Note that wrapped text can be aligned: // font.draw(spriteBatch, text, x, y, width, Align.center, true); }
private void renderWrappedCached () { String text = "Wrapped Cached Wrapped Cached"; float x = logoSprite.getX(); float y = logoSprite.getY(); float width = logoSprite.getWidth(); float height = logoSprite.getHeight(); // Obviously you wouldn't set the cache text every frame in real code. GlyphLayout layout = cache.setText(text, 0, 0, width, Align.left, true); // Note that wrapped text can be aligned: // cache.setWrappedText(text, 0, 0, width, HAlignment.CENTER); x += width / 2 - layout.width / 2; y += height / 2 + layout.height / 2; cache.setPosition(x, y); cache.draw(spriteBatch); }
private void renderMultiLineCached () { String text = "Multi Line\nCached"; int lines = 2; float x = logoSprite.getX(); float y = logoSprite.getY(); float width = logoSprite.getWidth(); float height = logoSprite.getHeight(); // Obviously you wouldn't set the cache text every frame in real code. GlyphLayout layout = cache.setText(text, 0, 0); // Note that multi line text can be aligned: // cache.setText(text, 0, 0, width, Align.center, false); x += width / 2 - layout.width / 2; y += height / 2 + layout.height / 2; cache.setPosition(x, y); cache.draw(spriteBatch); }
private void renderSingleLineCached () { String text = "Single Line Cached"; float x = logoSprite.getX(); float y = logoSprite.getY(); float width = logoSprite.getWidth(); float height = logoSprite.getHeight(); // Obviously you wouldn't set the cache text every frame in real code. GlyphLayout layout = cache.setText(text, 0, 0); cache.setColors(Color.BLUE, 1, 4); x += width / 2 - layout.width / 2; y += height / 2 + layout.height / 2; cache.setPosition(x, y); cache.draw(spriteBatch); }
@Override public float getY () { return super.getY() - region.offsetY; }
Iterator<Sprite> enemyIterator = enemies.iterator(); while (enemyIterator.hasNext()){ Sprite sprite = enemyIterator.next(); if (sprite.getY() + sprite.getHeight() < screenBottom) //screenBottom is something you can calculate from your camera like camera.getPosition().y - camera.getHeight()/2 removeEnemy(sprite); }
public boolean overlaps(Sprite s) { return ( (this.getX() < s.getX()+s.getWidth()) && // check right side overlap (this.getX()+this.getWidth() > s.getX()) && // check left side overlap (this.getY() < s.getY()+s.getHeight()) && // check bottom side overlap (this.getY()+this.getHeight() > s.getY()) // check top side overlap ); }
Sprite player = world.getPlayer(); //Just to tidy up the code //Half width, half height and rotation float hw = player.getWidth() / 2.0f; float hh = player.getHeight() / 2.0f; float rot = Math.toRadians(player.getRotation()); bullet.setPosition(player.getX() + hw + hw * (float) Math.cos(rot), player.getY() + hh + hh * (float) Math.sin(rot));
@Override public void addPos(float x, float y) { super.addPos(x, y); sprite.setPosition(sprite.getX() + x, sprite.getY() + y); }
int x = 0; for (Sprite spr : gSprite){ System.out.println("Ball: " + x + " X: " + spr.getX()+ " Y: " + spr.getY() + " vX: " + spr.getvX() + " vY: " + spr.getvY() + " Color: " + spr.getColor().toString()); x++; }
void fitOnScreen(Sprite sprite) { if (sprite.getX() > Gdx.graphics.getWidth()){ sprite.setX(-64f); } else if(sprite.getX()<-64f){ sprite.setX(Gdx.graphics.getWidth()); } if (sprite.getY() > Gdx.graphics.getHeight()){ sprite.setY(-64); } else if(sprite.getY() < -64f){ sprite.setY(Gdx.graphics.getHeight()); } }
@Override public void addPos(float x, float y) { super.addPos(x, y); sprite.setPosition(sprite.getX() + x, sprite.getY() + y); }
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); } } }