List of usage examples for com.badlogic.gdx.graphics.g2d Sprite setBounds
public void setBounds(float x, float y, float width, float height)
From source file:CB_Locator.Map.MapViewBase.java
License:Open Source License
protected void renderPositionMarker(Batch batch) { PointD point = Descriptor.ToWorld( Descriptor.LongitudeToTileX(MapTileLoader.MAX_MAP_ZOOM, Locator.getLongitude()), Descriptor.LatitudeToTileY(MapTileLoader.MAX_MAP_ZOOM, Locator.getLatitude()), MapTileLoader.MAX_MAP_ZOOM, MapTileLoader.MAX_MAP_ZOOM); Vector2 vPoint = new Vector2((float) point.X, -(float) point.Y); myPointOnScreen = worldToScreen(vPoint); myPointOnScreen.y -= ySpeedVersatz;/*from w ww.j av a2s .com*/ if (showAccuracyCircle) { if (accuracyDrawable == null) { accuracyDrawable = new AccuracyDrawable(this.mapIntWidth, this.mapIntWidth); } float radius = (pixelsPerMeter * Locator.getCoordinate().getAccuracy()); if (radius > GL_UISizes.PosMarkerSize / 2) { accuracyDrawable.draw(batch, myPointOnScreen.x, myPointOnScreen.y, radius); } } boolean lastUsedCompass = Locator.UseMagneticCompass(); boolean Transparency = LocatorSettings.PositionMarkerTransparent.getValue(); int arrowId = 0; if (lastUsedCompass) { arrowId = Transparency ? 1 : 0; } else { arrowId = Transparency ? 3 : 2; } if (CarMode) arrowId = 15; Sprite arrow = Sprites.Arrows.get(arrowId); arrow.setRotation(-arrowHeading); arrow.setBounds(myPointOnScreen.x - GL_UISizes.halfPosMarkerSize, myPointOnScreen.y - GL_UISizes.halfPosMarkerSize, GL_UISizes.PosMarkerSize, GL_UISizes.PosMarkerSize); arrow.setOrigin(GL_UISizes.halfPosMarkerSize, GL_UISizes.halfPosMarkerSize); arrow.draw(batch); }
From source file:CB_Locator.Map.ZoomScale.java
License:Open Source License
@Override protected void render(Batch batch) { if (this.getWidth() < 1 || this.getHeight() < 1) return;//from ww w . j a v a 2s.com int valueRecHeight = (int) (this.getWidth() / 2); if (ScaleDrawRec == null) { ScaleDrawRec = this.copy(); ScaleDrawRec.setHeight(this.getHeight() - valueRecHeight); ScaleDrawRec.setPos(new Vector2(0, valueRecHeight / 2)); } if (!isVisible) return; checkFade(); // Draw Scale Sprite scale = drawSprite(ScaleDrawRec); if (scale != null) { scale.setY(valueRecHeight / 2); scale.draw(batch, FadeValue); } // Draw Value Background if (ValueRec != null) { Sprite valueBack; valueBack = Sprites.ZoomValueBack; valueBack.setBounds(ValueRec.getX() + 1.5f, ValueRec.getY(), ValueRec.getWidth(), ValueRec.getHeight()); valueBack.draw(batch, FadeValue); } int intZoom = (int) zoom; try { com.badlogic.gdx.graphics.Color c = COLOR.getFontColor(); Fonts.getNormal().setColor(c.r, c.g, c.b, FadeValue); Fonts.getNormal().draw(batch, String.valueOf(intZoom), ValueRec.getX() + (ValueRec.getWidth() / 3), ValueRec.getY() + ValueRec.getHeight() / 1.15f); Fonts.getNormal().setColor(c.r, c.g, c.b, 1f); } catch (Exception e) { e.printStackTrace(); } invalidateTextureEventList.Add(this); }
From source file:CB_UI.GL_UI.Controls.ArrowView.java
License:Open Source License
@Override public void render(Batch batch) { Sprite arrow = Sprites.Arrows.get(0); arrow.setRotation(0);/*from www .j a va 2 s.c o m*/ arrow.setBounds(-(getWidth() / 2), 0, getWidth(), getHeight()); arrow.setOrigin(this.getCenterPosX(), this.getCenterPosY()); arrow.draw(batch); }
From source file:CB_UI.GL_UI.Views.MapView.java
License:Open Source License
private void RenderTargetArrow(Batch batch) { if (GlobalCore.getSelectedCache() == null) return;//from w w w . j a v a2 s . co m Coordinate coord = (GlobalCore.getSelectedWaypoint() != null) ? GlobalCore.getSelectedWaypoint().Pos : GlobalCore.getSelectedCache().Pos; if (coord == null) { return; } float x = (float) (256.0 * Descriptor.LongitudeToTileX(MapTileLoader.MAX_MAP_ZOOM, coord.getLongitude())); float y = (float) (-256.0 * Descriptor.LatitudeToTileY(MapTileLoader.MAX_MAP_ZOOM, coord.getLatitude())); float halfHeight = (mapIntHeight / 2) - ySpeedVersatz; float halfWidth = mapIntWidth / 2; // create ScreenRec try { if (TargetArrowScreenRec == null) { TargetArrowScreenRec = new CB_RectF(0, 0, mapIntWidth, mapIntHeight); if (Mode != MapMode.Compass) { TargetArrowScreenRec.ScaleCenter(0.9f); if (Mode == MapMode.Normal) { TargetArrowScreenRec.setHeight(TargetArrowScreenRec.getHeight() - (TargetArrowScreenRec.getHeight() - info.getY()) - zoomBtn.getHeight()); TargetArrowScreenRec.setY(zoomBtn.getMaxY()); } } } Vector2 ScreenCenter = new Vector2(halfWidth, halfHeight); Vector2 screen = worldToScreen(new Vector2(x, y)); Vector2 target = new Vector2(screen.x, screen.y); Vector2 newTarget = TargetArrowScreenRec.getIntersection(ScreenCenter, target); // Rotation berechnen if (newTarget != null) { float direction = get_angle(ScreenCenter.x, ScreenCenter.y, newTarget.x, newTarget.y); direction = 180 - direction; // draw sprite Sprite arrow = Sprites.Arrows.get(4); arrow.setRotation(direction); float boundsX = newTarget.x - GL_UISizes.TargetArrow.halfWidth; float boundsY = newTarget.y - GL_UISizes.TargetArrow.height; arrow.setBounds(boundsX, boundsY, GL_UISizes.TargetArrow.width, GL_UISizes.TargetArrow.height); arrow.setOrigin(GL_UISizes.TargetArrow.halfWidth, GL_UISizes.TargetArrow.height); arrow.draw(batch); // get real bounding box of TargetArrow float t[] = arrow.getVertices(); float maxX = Math.max(Math.max(t[0], t[5]), Math.max(t[10], t[15])); float minX = Math.min(Math.min(t[0], t[5]), Math.min(t[10], t[15])); float maxY = Math.max(Math.max(t[1], t[6]), Math.max(t[11], t[16])); float minY = Math.min(Math.min(t[1], t[6]), Math.min(t[11], t[16])); TargetArrow.set(minX, minY, maxX - minX, maxY - minY); } else { TargetArrow.set(0, 0, 0, 0); } } catch (Exception e) { TargetArrow.set(0, 0, 0, 0); } }
From source file:CB_UI.GL_UI.Views.MapView.java
License:Open Source License
public void renderWPI(Batch batch, SizeF WpUnderlay, SizeF WpSize, WaypointRenderInfo wpi) { Vector2 screen = worldToScreen(new Vector2(wpi.MapX, wpi.MapY)); screen.y -= ySpeedVersatz;// w ww . ja v a 2 s . c o m // FIXME create a LineDrawable class for create one times and set the Coordinates with calculated Triangles if (myPointOnScreen != null && showDirectLine && (wpi.Selected) && (wpi.Waypoint == GlobalCore.getSelectedWaypoint())) { // FIXME render only if visible on screen (intersect the screen rec) Quadrangle line = new Quadrangle(myPointOnScreen.x, myPointOnScreen.y, screen.x, screen.y, 3 * UI_Size_Base.that.getScale()); if (paint == null) { paint = new GL_Paint(); paint.setGLColor(Color.RED); } PolygonDrawable po = new PolygonDrawable(line.getVertices(), line.getTriangles(), paint, this.mapIntWidth, this.mapIntHeight); po.draw(batch, 0, 0, this.mapIntWidth, this.mapIntHeight, 0); po.dispose(); } // Don't render if outside of screen !! if ((screen.x < 0 - WpSize.width || screen.x > this.getWidth() + WpSize.height) || (screen.y < 0 - WpSize.height || screen.y > this.getHeight() + WpSize.height)) { if (wpi.Cache != null && (wpi.Cache.Id == infoBubble.getCacheId()) && infoBubble.isVisible()) { // check if wp selected if (wpi.Waypoint != null && wpi.Waypoint.equals(infoBubble.getWaypoint()) || wpi.Waypoint == null && infoBubble.getWaypoint() == null) infoBubble.setInvisible(); } return; } float NameYMovement = 0; if ((aktZoom >= zoomCross) && (wpi.Selected) && (wpi.Waypoint == GlobalCore.getSelectedWaypoint())) { // Draw Cross and move screen vector Sprite cross = Sprites.MapOverlay.get(3); cross.setBounds(screen.x - WpUnderlay.halfWidth, screen.y - WpUnderlay.halfHeight, WpUnderlay.width, WpUnderlay.height); cross.draw(batch); screen.add(-WpUnderlay.width, WpUnderlay.height); NameYMovement = WpUnderlay.height; } if (wpi.UnderlayIcon != null) { wpi.UnderlayIcon.setBounds(screen.x - WpUnderlay.halfWidth, screen.y - WpUnderlay.halfHeight, WpUnderlay.width, WpUnderlay.height); wpi.UnderlayIcon.draw(batch); } if (wpi.Icon != null) { wpi.Icon.setBounds(screen.x - WpSize.halfWidth, screen.y - WpSize.halfHeight, WpSize.width, WpSize.height); wpi.Icon.draw(batch); } // draw Favorite symbol if (wpi.Cache != null && wpi.Cache.isFavorite()) { batch.draw(Sprites.getSprite(IconName.favorit.name()), screen.x + (WpSize.halfWidth / 2), screen.y + (WpSize.halfHeight / 2), WpSize.width, WpSize.height); } if (wpi.OverlayIcon != null) { wpi.OverlayIcon.setBounds(screen.x - WpUnderlay.halfWidth, screen.y - WpUnderlay.halfHeight, WpUnderlay.width, WpUnderlay.height); wpi.OverlayIcon.draw(batch); } boolean drawAsWaypoint = wpi.Waypoint != null; // Rating des Caches darstellen if (wpi.Cache != null && showRating && (!drawAsWaypoint) && (wpi.Cache.Rating > 0) && (aktZoom >= 15)) { Sprite rating = Sprites.MapStars.get((int) Math.min(wpi.Cache.Rating * 2, 5 * 2)); rating.setBounds(screen.x - WpUnderlay.halfWidth, screen.y - WpUnderlay.halfHeight - WpUnderlay.Height4_8, WpUnderlay.width, WpUnderlay.Height4_8); rating.setOrigin(WpUnderlay.width / 2, WpUnderlay.Height4_8 / 2); rating.setRotation(0); rating.draw(batch); NameYMovement += WpUnderlay.Height4_8; } // Beschriftung if (wpi.Cache != null && showTitles && (aktZoom >= 15)) { try { String Name = drawAsWaypoint ? wpi.Waypoint.getTitle() : wpi.Cache.getName(); if (layout == null) layout = new GlyphLayout(Fonts.getNormal(), Name); else layout.setText(Fonts.getNormal(), Name); float halfWidth = layout.width / 2; Fonts.getNormal().draw(batch, layout, screen.x - halfWidth, screen.y - WpUnderlay.halfHeight - NameYMovement); } catch (Exception e) { } } // Show D/T-Rating if (wpi.Cache != null && showDT && (!drawAsWaypoint) && (aktZoom >= 15)) { Sprite difficulty = Sprites.MapStars.get((int) Math.min(wpi.Cache.getDifficulty() * 2, 5 * 2)); difficulty.setBounds(screen.x - WpUnderlay.width - GL_UISizes.infoShadowHeight, screen.y - (WpUnderlay.Height4_8 / 2), WpUnderlay.width, WpUnderlay.Height4_8); difficulty.setOrigin(WpUnderlay.width / 2, WpUnderlay.Height4_8 / 2); difficulty.setRotation(90); difficulty.draw(batch); Sprite terrain = Sprites.MapStars.get((int) Math.min(wpi.Cache.getTerrain() * 2, 5 * 2)); terrain.setBounds(screen.x + GL_UISizes.infoShadowHeight, screen.y - (WpUnderlay.Height4_8 / 2), WpUnderlay.width, WpUnderlay.Height4_8); terrain.setOrigin(WpUnderlay.width / 2, WpUnderlay.Height4_8 / 2); terrain.setRotation(90); terrain.draw(batch); } if (wpi.Cache != null && (wpi.Cache.Id == infoBubble.getCacheId()) && infoBubble.isVisible()) { if (infoBubble.getWaypoint() == wpi.Waypoint) { Vector2 pos = new Vector2(screen.x - infoBubble.getHalfWidth(), screen.y); infoBubble.setPos(pos); } } }
From source file:CB_UI_Base.GL_UI.Controls.ZoomButtons.java
License:Open Source License
@Override public void render(Batch batch) { if (withoutDrawing) return;//from w w w . ja v a 2s.c o m super.render(batch); if (firstDraw) { resetFadeOut(); firstDraw = false; } if (!this.isVisible()) return; // Log.d("CACHEBOX", "in=" + fadeIn + " out=" + fadeOut + " Fade=" + FadeValue); checkFade(); // draw down button Sprite btnDown; if (zoom == minzoom) { btnDown = Sprites.ZoomBtn.get(2);// disabled } else { btnDown = Sprites.ZoomBtn.get(onTouchDown ? 1 : 0); } float hw = HitRecDown.getWidth(); float hh = HitRecDown.getHeight(); float hx = HitRecDown.getX(); float hy = HitRecDown.getY(); float offX = 0; float offY = 0; if (portrait) { float e = btnDown.getWidth() / 2; float f = btnDown.getHeight() / 2; btnDown.setOrigin(e, f); btnDown.setRotation(90); hw = hh; hh = HitRecDown.getWidth(); // caclc offset offX = -(e - f); offY = -(f - e); } else { btnDown.setRotation(0f); } btnDown.setBounds(hx + offX, hy + offY, hw, hh); btnDown.draw(batch, FadeValue); // draw up button Sprite btnUp; if (zoom == maxzoom) { btnUp = Sprites.ZoomBtn.get(5);// disabled } else { btnUp = Sprites.ZoomBtn.get(onTouchUp ? 4 : 3); } hw = HitRecUp.getWidth(); hh = HitRecUp.getHeight(); hx = HitRecUp.getX(); hy = HitRecUp.getY(); if (portrait) { float e = btnUp.getWidth() / 2; float f = btnUp.getHeight() / 2; btnUp.setOrigin(e, f); btnUp.setRotation(90); hw = hh; hh = HitRecUp.getWidth(); } else { btnUp.setRotation(0f); } btnUp.setBounds(hx + offX, hy + offY, hw, hh); btnUp.draw(batch, FadeValue); }
From source file:com.gmail.emersonmx.tictactoe.BaseScreen.java
License:Open Source License
protected Actor createBackground() { Texture texture = ttt.manager.get("background.png", Texture.class); texture.setWrap(TextureWrap.Repeat, TextureWrap.Repeat); Sprite sprite = new Sprite(texture); sprite.setBounds(0, 0, TicTacToe.WINDOW_WIDTH, TicTacToe.WINDOW_HEIGHT); sprite.setRegion(0, 0, 5, 5);//w w w. j a v a2 s.co m return new SpriteActor("background", sprite); }
From source file:de.quadspot.beatnbrawl.screens.MainMenuScreen.java
@Override public void show() { Sprite sp = new Sprite(new Texture(Gdx.files.internal("button.png"))); sp.setBounds(Gdx.graphics.getWidth() / 2, Gdx.graphics.getHeight() / 2, 1000, 100); SpriteDrawable sprite = new SpriteDrawable(sp); TextButtonStyle style = new TextButtonStyle(sprite, sprite, sprite, game.font); startGameButton = new TextButton("Start game", style); startGameButton.setBounds(500, 500, 900, 400); startGameButton.addListener(new InputListener() { public boolean touchDown(InputEvent event, float x, float y, int pointer, int button) { game.setScreen(new GameScreen(game)); return true; // return true to indicate the event was handled }/*from ww w. ja v a 2 s.co m*/ }); stage.addActor(startGameButton); Gdx.input.setInputProcessor(stage); }
From source file:presentation.concretion.game.UIGameLoop.java
License:Open Source License
@Override public void renderHero(HeroState stateHero, float posHeroX, float posHeroY, float widthHero, float heightHero, boolean isFaceRight, GameState gameState) { // Draw hero. batch.begin();//from w w w . j ava2 s. c o m Sprite sHero = characters.loadAnimationHero(stateHero, isFaceRight, gameState); sHero.setBounds(posHeroX - sHero.getWidth() / 2 + widthHero / 2, posHeroY, sHero.getWidth(), sHero.getHeight()); sHero.draw(batch); batch.end(); // Camera limits. if (posHeroX + widthHero / 2 <= width / 2) { camera.position.x = width / 2; } else if (posHeroX + widthHero / 2 >= WIDTH_WORLD - width / 2) { camera.position.x = WIDTH_WORLD - width / 2; } else { camera.position.x = posHeroX + widthHero / 2; } }
From source file:presentation.concretion.game.UIGameLoop.java
License:Open Source License
@Override public void renderProyectiles(HeroState stateHero, EnemyState enemyState, float posProyectileX, float posProyectileY, float width, float height, float widthProyectile, float heightProyectile, float delta) { width = width == widthProyectile ? 0 : width; height = height == heightProyectile ? 0 : height; batch.begin();//w ww . ja v a2 s.c om // Draw proyectile heros. if (stateHero != null) { Sprite proyectile = characters.loadAnimationProyectilesHeros(stateHero, delta); proyectile.setBounds(posProyectileX - width, posProyectileY - height, widthProyectile, heightProyectile); proyectile.draw(batch); } // Draw projectiles enemies. if (enemyState != null) { Sprite proyectile = characters.loadAnimationProyectilesEnemy(enemyState, delta); proyectile.setBounds(posProyectileX - width, posProyectileY - height, widthProyectile, heightProyectile); proyectile.draw(batch); } batch.end(); }