List of usage examples for com.badlogic.gdx.graphics.g2d Sprite Sprite
public Sprite(Texture texture, int srcWidth, int srcHeight)
From source file:CB_Locator.Map.ZoomScale.java
License:Open Source License
/** * Zeichnet die Scala in eine Bitmap, damit diese als Sprite benutzt werden kann! * //from w w w . j a v a 2 s . c o m * @param rect */ private Sprite drawSprite(CB_RectF rect) { if (rect == null) return null; if (storedRec == null || !(storedRec.equals(rect))) { storedRec = rect.copy(); ValueRec = null; } int y = 0; if (ValueRec == null) { topRow = (int) rect.getHeight() - 2; bottomRow = 2; centerColumn = (int) (rect.getWidth() / 2); halfWidth = (int) (rect.getWidth() / 4); lineHeight = 10; numSteps = maxzoom - minzoom; grundY = rect.getY() - halfWidth; // dist = (bottomRow - topRow) / numSteps; y = (int) ((1 - ((zoom) - minzoom) / numSteps) * (bottomRow - topRow)) + topRow; ValueRec = new CB_RectF( rect.getX() + GL_UISizes.infoShadowHeight + centerColumn - rect.getWidth() / 2 - lineHeight / 2, grundY + y, rect.getWidth(), rect.getWidth() / 2); } else { y = (int) ((1 - ((zoom) - minzoom) / numSteps) * (bottomRow - topRow)) + topRow; ValueRec.setY(grundY + y); } if (CachedScaleSprite != null) return CachedScaleSprite; disposeTexture(); // int w = getNextHighestPO2((int) getWidth()); // int h = getNextHighestPO2((int) getHeight()); int w = (int) getWidth(); int h = (int) getHeight(); CachedScalePixmap = new Pixmap(w, h, Pixmap.Format.RGBA4444); CachedScalePixmap.setColor(0f, 0f, 0f, 1f); CachedScalePixmap.drawLine(centerColumn, bottomRow, centerColumn, topRow); for (int i = minzoom; i <= maxzoom; i++) { y = (int) ((1 - (i - minzoom) / numSteps) * (bottomRow - topRow)) + topRow; CachedScalePixmap.drawRectangle(3, y, (int) getWidth() - 3, 1); } CachedScaleTexture = new Texture(CachedScalePixmap); CachedScaleSprite = new Sprite(CachedScaleTexture, (int) rect.getWidth(), (int) rect.getHeight()); return CachedScaleSprite; }
From source file:CB_UI.GL_UI.Activitys.MeasureCoordinate.java
License:Open Source License
private void repaintPreview() { if (inRepaint.get()) return;//from w ww .j a va 2 s. c om inRepaint.set(true); disposeTexture(); CB_RectF panelRec = new CB_RectF(leftBorder, bOK.getMaxY(), innerWidth, innerWidth); int w = (int) panelRec.getWidth(); int h = (int) panelRec.getHeight(); drawingPixmap = new Pixmap(w, h, Pixmap.Format.RGBA8888); drawingPixmap.setColor(Color.LIGHT_GRAY); drawingPixmap.fillRectangle(0, 0, (int) panelRec.getWidth(), (int) panelRec.getHeight()); int centerX = (int) panelRec.getHalfWidth(); int centerY = (int) panelRec.getHalfHeight(); float minPix = Math.min(panelRec.getWidth(), panelRec.getHeight()); try { synchronized (mMeasureList) { if (mMeasureList.size() > 0) { // Gemittelter Punkt der GPS-Messungen double medianLat = MeasuredCoord.Referenz.getLatitude(); double medianLon = MeasuredCoord.Referenz.getLongitude(); MeasuredCoordList sortetdList = (MeasuredCoordList) mMeasureList.clone(); sortetdList.sort(); double peakLat = Math.max(Math.abs(sortetdList.get(0).getLatitude() - medianLat), Math.abs(sortetdList.get(sortetdList.size() - 1).getLatitude() - medianLat)); double peakLon = Math.max(Math.abs(sortetdList.get(0).getLongitude() - medianLon), Math.abs(sortetdList.get(sortetdList.size() - 1).getLongitude() - medianLon)); // Umrechnung in XY double medianX = Descriptor.LongitudeToTileX(projectionZoom, medianLon); double medianY = Descriptor.LatitudeToTileY(projectionZoom, medianLat); double extremeX = Descriptor.LongitudeToTileX(projectionZoom, peakLon + medianLon); double extremeY = Descriptor.LatitudeToTileY(projectionZoom, peakLat + medianLat); double peakX = Math.abs(extremeX - medianX); double peakY = Math.abs(extremeY - medianY); double maxPeak = Math.max(peakX, peakY); double factor = 1; if (maxPeak > 0) factor = minPix / maxPeak; factor /= 2; int x = (int) centerX; int y = (int) centerY; // Track zeichnen for (int i = 1; i < mMeasureList.size(); i++) { PointD lastDrawEntry = Descriptor.projectCoordinate(mMeasureList.get(i - 1).getLatitude(), mMeasureList.get(i - 1).getLongitude(), projectionZoom); int lastX = (int) (centerX + (lastDrawEntry.X - medianX) * factor); int lastY = (int) (centerY - (lastDrawEntry.Y - medianY) * factor); PointD thisDrawEntry = Descriptor.projectCoordinate(mMeasureList.get(i).getLatitude(), mMeasureList.get(i).getLongitude(), projectionZoom); x = (int) (centerX + (thisDrawEntry.X - medianX) * factor); y = (int) (centerY - (thisDrawEntry.Y - medianY) * factor); drawingPixmap.setColor(Color.RED); drawingPixmap.drawLine(lastX, lastY, x, y); } drawingPixmap.setColor(Color.BLUE); drawingPixmap.drawCircle(x, y, 4); } } // int m2 = (int) ((4 * minPix) / metersPerTile); int m4 = m2 * 2; drawingPixmap.setColor(Color.BLACK); drawingPixmap.drawCircle(centerX, centerY, m2); drawingPixmap.drawCircle(centerX, centerY, m4); drawingPixmap.drawLine(centerX, 0, centerX, (int) panelRec.getHeight()); drawingPixmap.drawLine(0, centerY, (int) panelRec.getWidth(), centerY); drawingTexture = new Texture(drawingPixmap); drawing = new Sprite(drawingTexture, (int) panelRec.getWidth(), (int) panelRec.getHeight()); drawing.setX(leftBorder); drawing.setY(bOK.getMaxY() + this.getBottomHeight()); inRepaint.set(false); } catch (Exception e) { e.printStackTrace(); } redraw = false; GL.that.renderOnce(); }
From source file:CB_UI_Base.GL_UI.Controls.Box.java
License:Open Source License
protected void drawBorder(Batch batch) { if (borderSprite == null) { try {/*from w ww . ja va 2 s . c o m*/ GL.that.RunOnGLWithThreadCheck(new IRunOnGL() { @Override public void run() { int w = (int) getWidth(); int h = (int) getHeight(); Pixmap borderRegPixmap = new Pixmap(w, h, Pixmap.Format.RGBA8888); borderRegPixmap.setColor(borderColor); int borderAsInt = Math.round(Box.this.borderSize); for (int i = 0; i < borderAsInt + 1; i++) { borderRegPixmap.drawRectangle(i, i, ((int) getWidth()) - (i), ((int) getHeight()) - (i)); } borderSprite = new Sprite(new Texture(borderRegPixmap, Pixmap.Format.RGBA8888, false), (int) getWidth(), (int) getHeight()); } }); } catch (Exception e) { e.printStackTrace(); } } if (borderSprite != null) batch.draw(borderSprite, 0, 0); }
From source file:CB_UI_Base.GL_UI.Controls.PopUps.PopUpMenu.java
License:Open Source License
@Override protected void writeDebug() { if (DebugSprite == null) { try {/*from w w w .j ava2 s .c o m*/ GL.that.RunOnGLWithThreadCheck(new IRunOnGL() { @Override public void run() { // int w = getNextHighestPO2((int) getWidth()); // int h = getNextHighestPO2((int) getHeight()); int w = (int) getWidth(); int h = (int) getHeight(); debugRegPixmap = new Pixmap(w, h, Pixmap.Format.RGBA8888); debugRegPixmap.setColor(1f, 0f, 0f, 1f); debugRegPixmap.drawRectangle(1, 1, (int) getWidth() - 1, (int) getHeight() - 1); debugRegPixmap.drawLine(1, 1, (int) getWidth() - 1, (int) getHeight() - 1); debugRegPixmap.drawLine(1, (int) getHeight() - 1, (int) getWidth() - 1, 1); debugRegTexture = new Texture(debugRegPixmap, Pixmap.Format.RGBA8888, false); DebugSprite = new Sprite(debugRegTexture, (int) getWidth(), (int) getHeight()); } }); } catch (Exception e) { e.printStackTrace(); } } }
From source file:CB_UI_Base.GL_UI.GL_View_Base.java
License:Open Source License
protected void writeDebug() { if (DebugSprite == null) { try {/*ww w. jav a 2s. c o m*/ GL.that.RunOnGLWithThreadCheck(new IRunOnGL() { @Override public void run() { // int w = getNextHighestPO2((int) getWidth()); // int h = getNextHighestPO2((int) getHeight()); int w = (int) getWidth(); int h = (int) getHeight(); debugRegPixmap = new Pixmap(w, h, Pixmap.Format.RGBA8888); debugRegPixmap.setColor(1f, 0f, 0f, 1f); debugRegPixmap.drawRectangle(1, 1, (int) getWidth() - 1, (int) getHeight() - 1); debugRegTexture = new Texture(debugRegPixmap, Pixmap.Format.RGBA8888, false); DebugSprite = new Sprite(debugRegTexture, (int) getWidth(), (int) getHeight()); } }); } catch (Exception e) { e.printStackTrace(); } } }
From source file:com.game.libgdx.roguelikeengine.Layout.java
License:Open Source License
public Layout() { // tiles/*from ww w . jav a 2 s.c om*/ menu_img = new Sprite(new Texture(Gdx.files.internal("UI/charactermenu.png")), WrapperEngine.OPTION_MENU_X_SIZE, WrapperEngine.WINDOWHEIGHT); actionmenu_img = new Sprite(new Texture(Gdx.files.internal("UI/actionmenu.png")), WrapperEngine.ON_SCREEN_TILES_X * WrapperEngine.TILE_X_SIZE, 64); androidcommands_img = new Sprite(new Texture(Gdx.files.internal("UI/androidcommands.png")), 128, 320); androiddirections_img = new Sprite(new Texture(Gdx.files.internal("UI/androiddirections.png")), 256, 256); energybar_img = new Sprite(new Texture(Gdx.files.internal("UI/energybar.png")), 60, 5); redbar_img = new Sprite(new Texture(Gdx.files.internal("UI/redbar.png")), 6, 5); magicbar_img = new Sprite(new Texture(Gdx.files.internal("UI/energybar.png")), 60, 5); bluebar_img = new Sprite(new Texture(Gdx.files.internal("UI/bluebar.png")), 6, 5); }
From source file:com.subzero.entities.Cactus.java
License:Open Source License
public Cactus(float x, float y, float health, AssetManager assetManager) { super(x, y, health, assetManager); bigCactus = true;/* ww w. j a v a 2 s . com*/ bounds = new Rectangle[3]; bounds[0] = new Rectangle(0, 6, 4, 10); bounds[1] = new Rectangle(6, 0, 6, 22); bounds[2] = new Rectangle(14, 10, 3, 9); texture = assetManager.get("Cactus.png", Texture.class); sprite = new Sprite(texture, 17, 22); sprite.setX(imageProvider.getScreenWidth() + x); sprite.setY(y); speed = 1; }
From source file:com.subzero.entities.Cloud.java
License:Open Source License
public Cloud(float x, float y, float health, AssetManager assetManager) { super(x, y, health, assetManager); smallCloud = assetManager.get("Cloud.png", Texture.class); bigCloud = assetManager.get("Cloud2.png", Texture.class); texture = smallCloud;// www.jav a 2 s .com sprite = new Sprite(texture, 20, 11); sprite.setX(x); sprite.setY(y); speed = 0.1f; }
From source file:com.subzero.entities.Player.java
License:Open Source License
public Player(float x, float y, float health, AssetManager assetManager) { super(x, y, health, assetManager); bounds = new Rectangle[2]; bounds[0] = new Rectangle(-20, 0, 8, 8); bounds[1] = new Rectangle(-20, 6, 18, 16); pref = Gdx.app.getPreferences("com.subzero.runners"); defaultCharacter = pref.getString("defaultCharacter", "Nikola"); texture = assetManager.get(defaultCharacter + ".png", Texture.class); textureRegion = new TextureRegion(assetManager.get(defaultCharacter + "-w.png", Texture.class)); animatedTextures = textureRegion.split(18, 22)[0]; animation = new Animation(period, animatedTextures); animation.setPlayMode(PlayMode.LOOP); textureRegion = new TextureRegion(assetManager.get(defaultCharacter + "-j.png", Texture.class)); animatedJumpTextures = textureRegion.split(18, 22)[0]; groundLevel = new Vector2(x, y); sprite = new Sprite(texture, 18, 22); sprite.setX(x);/*from ww w . j a va 2s . c o m*/ sprite.setY(y); }
From source file:com.subzero.entities.Player.java
License:Open Source License
public void setCharacter() { defaultCharacter = pref.getString("defaultCharacter", "Nikola"); texture = assetManager.get(defaultCharacter + ".png", Texture.class); textureRegion = new TextureRegion(assetManager.get(defaultCharacter + "-w.png", Texture.class)); animatedTextures = textureRegion.split(18, 22)[0]; animation = new Animation(period, animatedTextures); animation.setPlayMode(PlayMode.LOOP); textureRegion = new TextureRegion(assetManager.get(defaultCharacter + "-j.png", Texture.class)); animatedJumpTextures = textureRegion.split(18, 22)[0]; groundLevel = new Vector2(x, y); sprite = new Sprite(texture, 18, 22); sprite.setX(x);// www.j a v a 2 s .c o m sprite.setY(y); }