@Override public void create () { cam = new OrthographicCamera(480, 320); cam.position.set(WIDTH * 32 / 2, HEIGHT * 32 / 2, 0); camController = new OrthoCamController(cam); Gdx.input.setInputProcessor(camController); texture = new Texture(Gdx.files.internal("data/tiles.png")); Random rand = new Random(); for (int i = 0; i < LAYERS; i++) { caches[i] = new SpriteCache(); SpriteCache cache = caches[i]; cache.beginCache(); for (int y = 0; y < HEIGHT; y++) { for (int x = 0; x < WIDTH; x++) { int tileX = rand.nextInt(5); int tileY = rand.nextInt(5); cache.add(texture, x << 5, y << 5, 1 + tileX * 33, 1 + tileY * 33, 32, 32); } } layers[i] = cache.endCache(); } }
@Override public void render () { Gdx.gl.glClear(GL20.GL_COLOR_BUFFER_BIT); cam.update(); Gdx.gl.glEnable(GL20.GL_BLEND); Gdx.gl.glBlendFunc(GL20.GL_SRC_ALPHA, GL20.GL_ONE_MINUS_SRC_ALPHA); for (int i = 0; i < LAYERS; i++) { SpriteCache cache = caches[i]; cache.setProjectionMatrix(cam.combined); cache.begin(); for (int j = 0; j < TILES_PER_LAYER; j += BLOCK_TILES) { cache.draw(layers[i], j, BLOCK_TILES); } cache.end(); } if (TimeUtils.nanoTime() - startTime >= 1000000000) { Gdx.app.log("TileTest", "fps: " + Gdx.graphics.getFramesPerSecond()); startTime = TimeUtils.nanoTime(); } }
public void create () { texture = new Texture(Gdx.files.internal("data/badlogicsmall.jpg")); Sprite sprite = new Sprite(texture); sprite.setSize(tileSize, tileSize); cache = new SpriteCache(1000, false); for (int y = 0; y < tileMapHeight; y++) { cache.beginCache(); for (int x = 0; x < tileMapWidth; x++) { sprite.setPosition(x * tileSize, y * tileSize); cache.add(sprite); } cache.endCache(); sprite.rotate90(true); } }
public GameGridRenderer(GameGrid gameGrid, OrthographicCamera camera) { this.gameGrid = gameGrid; this.camera = camera; renderTintColor = Color.WHITE; shouldRenderGridLines = false; shapeRenderer = new ShapeRenderer(); transitLines = Lists.newArrayList(); activeOverlay = null; makeOverlayFunctions(); spriteCache = new SpriteCache(); gameGrid.events().register(this); }
@Override public void render(SpriteBatch spriteBatch, SpriteCache spriteCache, Color renderTintColor) { if (animation != null) { if (isPlaying) { animationTime += Gdx.graphics.getDeltaTime(); if (animationTime >= animation.animationDuration) { endPlayback(); } else { Vector2 worldCenter = getWorldCenter(); spriteBatch.draw(animation.getKeyFrame(animationTime, false), worldCenter.x - 53.5f * getGridScale(), worldCenter.y - 19 * getGridScale(), 107 * getGridScale(), 44 * getGridScale()); } } } if (!isPlaying && movie == null && getEmploymentLevel() > 0f) { long millis = System.currentTimeMillis(); if (nextShowTime <= millis) { loadMovie(); } } super.render(spriteBatch, spriteCache, renderTintColor); }
public void render(SpriteBatch spriteBatch, SpriteCache spriteCache, Color renderTintColor) { Sprite sprite = getSprite(); if (sprite != null) { sprite.setColor(renderColor); sprite.setPosition(worldPosition.x, worldPosition.y); sprite.setSize(worldSize.x, worldSize.y); if (shouldUseSpriteCache()) { spriteCache.beginCache(); spriteCache.add(sprite); setSpriteCacheId(spriteCache.endCache()); } else { sprite.draw(spriteBatch); } } }
@Override public void create () { cam = new OrthographicCamera(480, 320); camController = new OrthoCamController(cam); Gdx.input.setInputProcessor(camController); renderer = new ShapeRenderer(); texture = new Texture(Gdx.files.internal("data/isotile.png")); Random rand = new Random(); for (int i = 0; i < LAYERS; i++) { caches[i] = new SpriteCache(); SpriteCache cache = caches[i]; cache.beginCache(); int colX = HEIGHT * TILE_WIDTH / 2 - TILE_WIDTH / 2; int colY = BOUND_Y - TILE_HEIGHT_DIAMOND; for (int x = 0; x < WIDTH; x++) { for (int y = 0; y < HEIGHT; y++) { int tileX = colX - y * TILE_WIDTH / 2; int tileY = colY - y * TILE_HEIGHT_DIAMOND / 2; cache.add(texture, tileX, tileY, rand.nextInt(2) * 54, 0, TILE_WIDTH, TILE_HEIGHT); } colX += TILE_WIDTH / 2; colY -= TILE_HEIGHT_DIAMOND / 2; } layers[i] = cache.endCache(); } }
@Override public void dispose () { renderer.dispose(); texture.dispose(); for (SpriteCache cache : caches) cache.dispose(); }
@Override public void render () { Gdx.gl.glClearColor(0.7f, 0.7f, 0.7f, 1); Gdx.gl.glClear(GL20.GL_COLOR_BUFFER_BIT); cam.update(); Gdx.gl.glEnable(GL20.GL_BLEND); Gdx.gl.glBlendFunc(GL20.GL_SRC_ALPHA, GL20.GL_ONE_MINUS_SRC_ALPHA); for (int i = 0; i < LAYERS; i++) { SpriteCache cache = caches[i]; cache.setProjectionMatrix(cam.combined); cache.begin(); cache.draw(layers[i]); cache.end(); } renderer.setProjectionMatrix(cam.combined); renderer.begin(ShapeType.Line); renderer.setColor(1, 0, 0, 1); renderer.line(0, 0, 500, 0); renderer.line(0, 0, 0, 500); renderer.setColor(0, 0, 1, 1); renderer.line(0, BOUND_Y, BOUND_X, BOUND_Y); renderer.setColor(0, 0, 1, 1); renderer.line(BOUND_X, 0, BOUND_X, BOUND_Y); renderer.end(); }
@Override public void render(SpriteBatch spriteBatch, SpriteCache spriteCache, Color renderTintColor) { super.render(spriteBatch, spriteCache, renderTintColor); if (activeVehicleTexture != null) { spriteBatch.setColor(Color.WHITE); spriteBatch.draw(activeVehicleTexture, getWorldCenter().x - activeVehicleTexture.getRegionWidth() / 2, getWorldCenter().y - activeVehicleTexture.getRegionHeight() / 2); } }
@Override public void render(SpriteBatch spriteBatch, SpriteCache spriteCache, Color renderTintColor) { // stairs need to support overflowing into adjacent cells. if (sprite != null) { sprite.setColor(renderColor); sprite.setPosition(position.getWorldX(), position.getWorldY()); sprite.draw(spriteBatch); } }
public OrthogonalTileLayerRenderer(TiledMap tiledMap, boolean cacheLayers) { super(); this.cacheLayers = cacheLayers; this.tiledMap = tiledMap; if (cacheLayers) { layerCache = new SpriteCache(5000, true); layerCacheIds = new HashMap<Integer, Integer>(); } mapClip = new TiledMapRenderArea(); tmpClip = new TiledMapRenderArea(); }
@Override public void drawSpriteCache(SpriteCache spriteCache, int cacheId) { beginRendering(); spriteCache.getProjectionMatrix().set(spriteBatch.getProjectionMatrix().cpy()); spriteCache.getTransformMatrix().set(spriteBatch.getTransformMatrix().cpy()); Gdx.gl.glEnable(GL20.GL_BLEND); spriteCache.begin(); spriteCache.draw(cacheId); spriteCache.end(); }
/** @param cacheSize The maximum number of tiles that can be cached. */ public OrthoCachedTiledMapRenderer (TiledMap map, float unitScale, int cacheSize) { this.map = map; this.unitScale = unitScale; spriteCache = new SpriteCache(cacheSize, true); }
public SpriteCache getSpriteCache () { return spriteCache; }
@Override public void create () { spriteCache = new SpriteCache(1000, true); texture = new Texture(Gdx.files.internal("data/badlogicsmall.jpg")); texture.setFilter(TextureFilter.Linear, TextureFilter.Linear); Pixmap pixmap = new Pixmap(32, 32, Format.RGBA8888); pixmap.setColor(1, 1, 0, 0.5f); pixmap.fill(); texture2 = new Texture(pixmap); pixmap.dispose(); sprites = new float[SPRITES * 6]; sprites2 = new float[SPRITES * 6]; Sprite[] sprites3 = new Sprite[SPRITES * 2]; for (int i = 0; i < sprites.length; i += 6) { sprites[i] = (int)(Math.random() * (Gdx.graphics.getWidth() - 32)); sprites[i + 1] = (int)(Math.random() * (Gdx.graphics.getHeight() - 32)); sprites[i + 2] = 0; sprites[i + 3] = 0; sprites[i + 4] = 32; sprites[i + 5] = 32; sprites2[i] = (int)(Math.random() * (Gdx.graphics.getWidth() - 32)); sprites2[i + 1] = (int)(Math.random() * (Gdx.graphics.getHeight() - 32)); sprites2[i + 2] = 0; sprites2[i + 3] = 0; sprites2[i + 4] = 32; sprites2[i + 5] = 32; } for (int i = 0; i < SPRITES * 2; i++) { int x = (int)(Math.random() * (Gdx.graphics.getWidth() - 32)); int y = (int)(Math.random() * (Gdx.graphics.getHeight() - 32)); if (i >= SPRITES) sprites3[i] = new Sprite(texture2, 32, 32); else sprites3[i] = new Sprite(texture, 32, 32); sprites3[i].setPosition(x, y); sprites3[i].setOrigin(16, 16); } float scale = 1; float angle = 15; spriteCache.beginCache(); for (int i = 0; i < sprites2.length; i += 6) spriteCache.add(texture2, sprites2[i], sprites2[i + 1], 16, 16, 32, 32, scale, scale, angle, 0, 0, 32, 32, false, false); for (int i = 0; i < sprites.length; i += 6) spriteCache.add(texture, sprites[i], sprites[i + 1], 16, 16, 32, 32, scale, scale, angle, 0, 0, 32, 32, false, false); normalCacheID = spriteCache.endCache(); angle = -15; spriteCache.beginCache(); for (int i = SPRITES; i < SPRITES << 1; i++) { sprites3[i].setRotation(angle); sprites3[i].setScale(scale); spriteCache.add(sprites3[i]); } for (int i = 0; i < SPRITES; i++) { sprites3[i].setRotation(angle); sprites3[i].setScale(scale); spriteCache.add(sprites3[i]); } spriteCacheID = spriteCache.endCache(); Gdx.input.setInputProcessor(this); }
@Override public void render(SpriteBatch spriteBatch, SpriteCache spriteCache, Color renderTintColor) { tmpVector.set(worldPosition); if (selectedResizeHandle == ResizeHandle.BOTTOM) { bottomSprite.setColor(Color.CYAN); } else { bottomSprite.setColor(renderColor); } bottomSprite.setPosition(tmpVector.x, tmpVector.y); bottomSprite.draw(spriteBatch); Sprite shaftToRender; if (drawShaft && !(InputSystem.instance().getCurrentTool() instanceof PlacementTool)) { shaftToRender = shaftSprite; } else { shaftToRender = emptyShaftSprite; } tmpVector.add(0, scaledGridUnit()); shaftToRender.setColor(renderColor); shaftToRender.setPosition(tmpVector.x, tmpVector.y); shaftToRender.setSize(worldSize.x, worldSize.y - scaledGridUnit()); setWrap(shaftToRender); shaftToRender.draw(spriteBatch); floorLabelCache.setColor(1, 1, 1, 0.5f); floorLabelCache.draw(spriteBatch, renderColor.a); if (isPlaced() && selectedResizeHandle == null && !(InputSystem.instance().getCurrentTool() instanceof PlacementTool)) { for (ElevatorCar elevatorCar : elevatorCars) { elevatorCar.setColor(renderColor); elevatorCar.draw(spriteBatch); } } if (selectedResizeHandle == TOP) { topSprite.setColor(Color.CYAN); } else { topSprite.setColor(renderColor); } topSprite.setPosition(getWorldPosition().x, getWorldTop().y - scaledGridUnit()); topSprite.draw(spriteBatch); }
@Override public void render(SpriteBatch spriteBatch, SpriteCache spriteCache, Color renderTintColor) { super.render(spriteBatch, spriteCache, renderTintColor); // drawEndCaps(spriteBatch); }
@Override public void render(SpriteBatch spriteBatch, SpriteCache spriteCache, Color renderTintColor) { super.render(spriteBatch, spriteCache, renderTintColor); renderDecals(spriteBatch); }
public void fillSpriteCache(SpriteCache spriteCache, Texture ...textures) { for(Texture texture : textures){ spriteCache.add(texture, 0, 0); } }
public void subtick() { while (Gdx.graphics == null) { Thread.yield(); } if (spriteBatch == null) { Gdx.gl.glDisable(GL20.GL_DEPTH_TEST); ShaderProgram.pedantic = false; ShaderProgram defaultShader = ShaderHelper.loadShader("shaders/default"); ShaderHelper.addShader(defaultShader); spriteBatch = new SpriteBatch(4096); spriteCache = new SpriteCache(4096, true); ShaderHelper.resetCurrentShader(); Images.loadBasic(); //Init controller helper here as JGLFW needs a window before doing controller stuff controllerHelper = new ControllerHelper(); //At this point it's safe to assume that most stuff needeed for a backend setup is set up. BackendHelper.setUp(); playerInfo = BackendHelper.backend.newPlayerInfo(); playerInfo.setSessionID(getSecureRandomBytes(512)); System.out.println("Username: "+playerInfo.getUserName()); System.out.println("UUID: "+playerInfo.getUserID()); //Init the first loading screen (InitLoadLevel) LoadingLevel loadinglevel = new InitLoadingLevel(); level = loadinglevel; loadinglevel.start(); //Gdx.gl.glClearColor(0.1f, 0.1f, 0.1f, 1f); //Gdx.gl.glClear(GL10.GL_COLOR_BUFFER_BIT); //cam.render(); } }
@Override public void drawSpriteCache(SpriteCache spriteCache, int cacheId) { }
private int addBlock(int[][] paramArrayOfInt, int paramInt1, int paramInt2, boolean paramBoolean) { this.cache.beginCache(); int i = paramInt2 * this.tilesPerBlockX; int j = paramInt1 * this.tilesPerBlockY; int k = i + this.tilesPerBlockX; int m = j + this.tilesPerBlockY; for (int n = j; (n < m) && (n < paramArrayOfInt.length); n++) { int i1 = i; if ((i1 < k) && (i1 < paramArrayOfInt[n].length)) { int i2 = paramArrayOfInt[n][i1]; TextureRegion localTextureRegion; float f9; if ((i2 != 0) && (paramBoolean == this.blendedTiles.contains(i2))) { localTextureRegion = this.atlas.getRegion(i2); if (localTextureRegion != null) { if (this.isSimpleTileAtlas) break label294; TextureAtlas.AtlasRegion localAtlasRegion = (TextureAtlas.AtlasRegion)localTextureRegion; SpriteCache localSpriteCache = this.cache; float f1 = i1 * this.unitsPerTileX; float f2 = (-1 + (paramArrayOfInt.length - n)) * this.unitsPerTileY; float f3 = localAtlasRegion.offsetX * this.unitsPerTileX / this.tileWidth; float f4 = localAtlasRegion.offsetY * this.unitsPerTileY / this.tileHeight; float f5 = localAtlasRegion.packedWidth; float f6 = localAtlasRegion.packedHeight; float f7 = this.unitsPerTileX / this.tileWidth; float f8 = this.unitsPerTileY / this.tileHeight; if (!localAtlasRegion.rotate) break label288; f9 = 90.0F; label257: localSpriteCache.add(localAtlasRegion, f1, f2, f3, f4, f5, f6, f7, f8, f9); } } while (true) { i1++; break; label288: f9 = 0.0F; break label257; label294: this.cache.add(localTextureRegion, i1 * this.unitsPerTileX, (-1 + (paramArrayOfInt.length - n)) * this.unitsPerTileY, 0.0F, 0.0F, localTextureRegion.getRegionWidth(), localTextureRegion.getRegionHeight(), this.unitsPerTileX / this.tileWidth, this.unitsPerTileY / this.tileHeight, 0.0F); } } } return this.cache.endCache(); }
private void init(int[][][] paramArrayOfInt, TileAtlas paramTileAtlas, int paramInt1, int paramInt2, float paramFloat1, float paramFloat2, IntArray paramIntArray, int paramInt3, int paramInt4, ShaderProgram paramShaderProgram) { this.atlas = paramTileAtlas; this.tileWidth = paramInt1; this.tileHeight = paramInt2; this.unitsPerTileX = paramFloat1; this.unitsPerTileY = paramFloat2; this.blendedTiles = paramIntArray; this.tilesPerBlockX = paramInt3; this.tilesPerBlockY = paramInt4; this.unitsPerBlockX = (paramFloat1 * paramInt3); this.unitsPerBlockY = (paramFloat2 * paramInt4); this.isSimpleTileAtlas = (paramTileAtlas instanceof SimpleTileAtlas); this.allLayers = new int[paramArrayOfInt.length]; int i = 0; int j = 0; int k = 0; for (int m = 0; m < paramArrayOfInt.length; m++) { this.allLayers[m] = m; if (paramArrayOfInt[m].length > j) j = paramArrayOfInt[m].length; for (int i3 = 0; i3 < paramArrayOfInt[m].length; i3++) { if (paramArrayOfInt[m][i3].length > k) k = paramArrayOfInt[m][i3].length; for (int i4 = 0; i4 < paramArrayOfInt[m][i3].length; i4++) if (paramArrayOfInt[m][i3][i4] != 0) i++; } } this.mapHeightUnits = ((int)(paramFloat2 * j)); this.mapWidthUnits = ((int)(paramFloat1 * k)); if (paramShaderProgram == null) { this.cache = new SpriteCache(i, false); this.normalCacheId = new int[paramArrayOfInt.length][][]; this.blendedCacheId = new int[paramArrayOfInt.length][][]; } label403: label538: for (int n = 0; ; n++) { if (n >= paramArrayOfInt.length) return; this.normalCacheId[n] = new int[MathUtils.ceil(paramArrayOfInt[n].length / paramInt4)][]; this.blendedCacheId[n] = new int[MathUtils.ceil(paramArrayOfInt[n].length / paramInt4)][]; for (int i1 = 0; ; i1++) { if (i1 >= this.normalCacheId[n].length) break label538; this.normalCacheId[n][i1] = new int[MathUtils.ceil(paramArrayOfInt[n][i1].length / paramInt3)]; this.blendedCacheId[n][i1] = new int[MathUtils.ceil(paramArrayOfInt[n][i1].length / paramInt3)]; int i2 = 0; if (i2 < this.normalCacheId[n][i1].length) { if (this.isSimpleTileAtlas) this.blendedCacheId[n][i1][i2] = addBlock(paramArrayOfInt[n], i1, i2, false); while (true) { i2++; break label403; this.cache = new SpriteCache(i, paramShaderProgram, false); break; this.normalCacheId[n][i1][i2] = addBlock(paramArrayOfInt[n], i1, i2, false); this.blendedCacheId[n][i1][i2] = addBlock(paramArrayOfInt[n], i1, i2, true); } } } } }
/** * Draws a {@link SpriteCache} * * @param spriteCache * The {@link SpriteCache} to draw * @param cacheId * The cacheId to draw */ public void drawSpriteCache(SpriteCache spriteCache, int cacheId);
public void onCommand(SpriteCache cache);