Java Code Examples for com.badlogic.gdx.graphics.g2d.Sprite#setPosition()
The following examples show how to use
com.badlogic.gdx.graphics.g2d.Sprite#setPosition() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: SpriteAccessor.java From xibalba with MIT License | 6 votes |
@Override public void setValues(Sprite target, int tweenType, float[] newValues) { switch (tweenType) { case ALPHA: target.setAlpha(newValues[0]); break; case XY: target.setPosition(newValues[0], newValues[1]); break; case COLOR: target.setColor(newValues[0], newValues[1], newValues[2], target.getColor().a); break; case SCALE: target.setScale(newValues[0], newValues[1]); break; default: break; } }
Example 2
Source File: PanzerTankSprite.java From seventh with GNU General Public License v2.0 | 6 votes |
@Override protected void renderTurret(float rx, float ry, float turretAngle, Canvas canvas, Camera camera, float alpha) { // rx += 35f; // ry += 25f; rx += 15f; ry -= 25f; rx += 43f; ry += 25f; float originX = 89f; Sprite turretSprite = isDestroyed() ? tankTurretDamaged : tankTurret; float originY = 65f;//turretSprite.getRegionHeight()/2f; turretSprite.setRotation(turretAngle); turretSprite.setOrigin(originX, originY); turretSprite.setPosition(rx,ry); canvas.drawSprite(turretSprite); }
Example 3
Source File: TankSprite.java From seventh with GNU General Public License v2.0 | 6 votes |
/** * Allow the implementing tank to adjust some of the rendering properties * * @param rx * @param ry * @param turretAngle * @param canvas * @param camera * @param alpha */ protected void renderTurret(float rx, float ry, float turretAngle, Canvas canvas, Camera camera, float alpha) { rx += 0f; ry -= 15f; rx += 70f; ry += 15f; float originX = 62f; Sprite turretSprite = isDestroyed ? tankTurretDamaged : tankTurret; float originY = turretSprite.getRegionHeight()/2f; turretSprite.setRotation(turretAngle); turretSprite.setOrigin(originX, originY); turretSprite.setPosition(rx,ry); canvas.drawSprite(turretSprite); }
Example 4
Source File: BlendingSpriteParticleRenderer.java From seventh with GNU General Public License v2.0 | 6 votes |
@Override public void render(Canvas canvas, Camera camera, float alpha, ParticleData particles) { int src = canvas.getSrcBlendFunction(); int dst = canvas.getDstBlendFunction(); //canvas.setBlendFunction(GL20.GL_SRC_ALPHA, GL20.GL_FUNC_ADD); canvas.setBlendFunction(GL20.GL_SRC_ALPHA, GL20.GL_ONE); Gdx.gl20.glBlendEquation(GL20.GL_FUNC_ADD); Vector2f cameraPos = camera.getRenderPosition(alpha); for(int i = 0; i < particles.numberOfAliveParticles; i++) { Sprite sprite = particles.sprite[i]; Vector2f pos = particles.pos[i]; sprite.setPosition(pos.x - cameraPos.x, pos.y - cameraPos.y); sprite.setScale(particles.scale[i]); sprite.setColor(particles.color[i]); sprite.setRotation(particles.rotation[i]); canvas.drawRawSprite(sprite); } canvas.setBlendFunction(src, dst); }
Example 5
Source File: ClientBomb.java From killingspree with MIT License | 6 votes |
public ClientBomb(short id, float x, float y, WorldRenderer renderer) { super(id, x, y, renderer); markForDispose = false; sprite = new Sprite(AssetLoader.instance.getTexture("sprites/bomb.png")); sprite.setSize(ServerBomb.RADIUS + 5, ServerBomb.RADIUS + 5); sprite.setOrigin(sprite.getWidth() / 2, sprite.getHeight() / 2); sprite.setPosition(x - sprite.getWidth() / 2, y - sprite.getHeight() / 2); deadTimer = 0f; Texture explodeTexture = AssetLoader.instance. getTexture("sprites/explosion.png"); explode = new Animation(0.03f, TextureRegion.split(explodeTexture, explodeTexture.getWidth()/7, explodeTexture.getHeight())[0]); }
Example 6
Source File: ClientEntity.java From killingspree with MIT License | 6 votes |
public void drawAll(Sprite sprite, SpriteBatch batch, float x, float y) { sprite.setPosition(x, y); sprite.draw(batch); if (x > WorldRenderer.VIEWPORT_WIDTH / 2) { sprite.setPosition(x - WorldRenderer.VIEWPORT_WIDTH, y); } else { sprite.setPosition(x + WorldRenderer.VIEWPORT_WIDTH, y); } sprite.draw(batch); if (position.y > WorldRenderer.VIEWPORT_HEIGHT / 2) { sprite.setPosition(x, y - WorldRenderer.VIEWPORT_HEIGHT); } else { sprite.setPosition(x, y + WorldRenderer.VIEWPORT_HEIGHT); } sprite.draw(batch); }
Example 7
Source File: EntityView.java From RuinsOfRevenge with MIT License | 5 votes |
public void draw(SpriteBatch batch, Entity e, Sprite sprite, float width, float xoffset, float yoffset) { Body body = e.getBody(); // Super-Duper important Box2D-Magic code: // This should be / is in almost every Box2D project // It takes the Body and the associated sprite and // renders the sprite properly, using the body's // position, rotation and origin. final float worldToSprite = sprite.getWidth() / width; final float spriteToWorld = width / sprite.getWidth(); // Get body position: final float bodyX = e.getX(); final float bodyY = e.getY(); // Get body center: final Vector2 center = body.getLocalCenter(); final Vector2 massCenter = body.getMassData().center; center.sub(massCenter).add(xoffset, yoffset); // Compute sprite-space center: final Vector2 spriteCenter = new Vector2(sprite.getWidth()/2, sprite.getHeight()/2).sub((center.cpy().scl(worldToSprite))); // Upload to sprite: sprite.setScale(1f * spriteToWorld); sprite.setRotation(e.getRotation() * MathUtils.radiansToDegrees); sprite.setOrigin(spriteCenter.x, spriteCenter.y); sprite.setPosition( bodyX - spriteCenter.x, bodyY - spriteCenter.y); // Draw Sprite: sprite.draw(batch); }
Example 8
Source File: SpriteParticleRenderer.java From seventh with GNU General Public License v2.0 | 5 votes |
@Override public void render(Canvas canvas, Camera camera, float alpha, ParticleData particles) { Vector2f cameraPos = camera.getRenderPosition(alpha); for(int i = 0; i < particles.numberOfAliveParticles; i++) { Sprite sprite = particles.sprite[i]; Vector2f pos = particles.pos[i]; sprite.setPosition(pos.x - cameraPos.x, pos.y - cameraPos.y); sprite.setScale(particles.scale[i]); sprite.setColor(particles.color[i]); sprite.setRotation(particles.rotation[i]); canvas.drawRawSprite(sprite); } }
Example 9
Source File: GdxCanvas.java From seventh with GNU General Public License v2.0 | 5 votes |
@Override public void drawSprite(Sprite sprite, float x, float y, Integer color) { if(!isBegun) batch.begin(); if(color!=null) { Color c = setTempColor(color); sprite.setColor(c); } else sprite.setColor(1,1,1, this.compositeAlpha); sprite.setPosition(x, y); sprite.draw(batch); if(!isBegun) batch.end(); }
Example 10
Source File: GdxCanvas.java From seventh with GNU General Public License v2.0 | 5 votes |
@Override public void drawSprite(Sprite sprite, int x, int y, Integer color) { if(!isBegun) batch.begin(); if(color!=null) { Color c = setTempColor(color); sprite.setColor(c); } else sprite.setColor(1,1,1, this.compositeAlpha); sprite.setPosition(x, y); sprite.draw(batch); if(!isBegun) batch.end(); }
Example 11
Source File: ClientArrow.java From killingspree with MIT License | 5 votes |
public ClientArrow(short id, float x, float y, WorldRenderer renderer) { super(id, x, y, renderer); markForDispose = false; sprite = new Sprite(AssetLoader.instance.getTexture("sprites/arrow.png")); sprite.setSize(ServerArrow.RADIUS * 10 , ServerArrow.RADIUS * 2.5f); sprite.setOrigin(sprite.getWidth() / 2, sprite.getHeight() / 2); sprite.setPosition(x - sprite.getWidth() / 2, y - sprite.getHeight() / 2); }
Example 12
Source File: ClientBullet.java From killingspree with MIT License | 5 votes |
public ClientBullet(short id, float x, float y, WorldRenderer renderer) { super(id, x, y, renderer); markForDispose = false; sprite = new Sprite(AssetLoader.instance.getTexture("sprites/bullet.png")); sprite.setSize(ServerArrow.RADIUS * 4 , ServerArrow.RADIUS * 1.5f); sprite.setOrigin(sprite.getWidth() / 2, sprite.getHeight() / 2); sprite.setPosition(x - sprite.getWidth() / 2, y - sprite.getHeight() / 2); renderer.audioPlayer.shoot(); }
Example 13
Source File: FadingSprite.java From TerraLegion with MIT License | 5 votes |
public FadingSprite(Sprite sprite, float x, float y, float minAmount, float maxAmount, float subAmount, float speed, float alpha) { super(x, y); this.sprite = sprite; this.alpha = alpha; sprite.setAlpha(alpha); sprite.setPosition(x, y); this.minAmount = minAmount; this.maxAmount = maxAmount; this.subAmount = subAmount; this.speed = speed; }
Example 14
Source File: FadingSprite.java From TerraLegion with MIT License | 5 votes |
public FadingSprite(Sprite sprite, float x, float y, float minAmount, float maxAmount, float subAmount, float speed) { super(x, y); this.sprite = sprite; alpha = 1f; sprite.setPosition(x, y); sprite.setAlpha(alpha); this.minAmount = minAmount; this.maxAmount = maxAmount; this.subAmount = subAmount; this.speed = speed; }
Example 15
Source File: SpritesSample.java From Codelabs with MIT License | 4 votes |
@Override public void render(float delta) { /* Clear screen with a black background */ Gdx.gl.glClearColor(1, 1, 1, 1); Gdx.gl.glClear(GL20.GL_COLOR_BUFFER_BIT); /* Render all graphics before do physics step */ debugRenderer.render(world, camera.combined); /* * Set projection matrix to camera.combined, the same way we did with * the debug renderer. */ batch.setProjectionMatrix(camera.combined); batch.begin(); /* Get word bodies */ world.getBodies(worldBodies); /* * For each body in the world we have to check if it has user data * associated and if it is an Sprite. In that case, we draw it in the * screen. */ for (Body body : worldBodies) { if (body.getUserData() instanceof Sprite) { Sprite sprite = (Sprite) body.getUserData(); /* * Set body position equals to box position. We also need to * center it in the box (measures are relative to body center). */ Vector2 position = body.getPosition(); sprite.setPosition(position.x - sprite.getWidth() / 2, position.y - sprite.getWidth() / 2); /* Set sprite rotation equals to body rotation */ sprite.setRotation(body.getAngle() * MathUtils.radiansToDegrees); /* Draw the sprite on screen */ sprite.draw(batch); } } batch.end(); /* Step the simulation with a fixed time step of 1/60 of a second */ world.step(1 / 60f, 6, 2); }
Example 16
Source File: FactorySelector.java From libgdx-demo-pax-britannica with MIT License | 4 votes |
public FactorySelector(Vector2 position, int id) { super(); this.position = position; this.setPosition(position.x, position.y); switch (id) { case 1: this.set(Resources.getInstance().factoryP1); break; case 2: this.set(Resources.getInstance().factoryP2); break; case 3: this.set(Resources.getInstance().factoryP3); break; default: this.set(Resources.getInstance().factoryP4); break; } setRotation(90); this.setPosition(position.x, position.y); this.setColor(0, 0, 0, 1); button = new Sprite(Resources.getInstance().aButton); button.setPosition(position.x+70f,position.y + 35.f); aCpuButton = new Sprite(Resources.getInstance().aCpuButton); aCpuButton.setPosition(position.x+70f,position.y + 35.f); aPlayerButton = new Sprite(Resources.getInstance().aPlayerButton); aPlayerButton.setPosition(position.x+70f,position.y + 35.f); cpuButton = new Sprite(Resources.getInstance().cpuButton); cpuButton.setPosition(position.x+30f,position.y -0.f); playerButton = new Sprite(Resources.getInstance().playerButton); playerButton.setPosition(position.x+30f,position.y + 70.f); float pulse = (1 + MathUtils.cos((pulse_time/180.f)*2.f*MathUtils.PI))/2.f; float color = fade * pulse + 1 * (1-pulse); this.setColor(color, color, color, 1); button.setColor(color, color, color, 1); cpuButton.setColor(color, color, color, 1); }
Example 17
Source File: SpriteElement.java From TerraLegion with MIT License | 4 votes |
public SpriteElement(Sprite sprite, float x, float y) { super(x, y); this.sprite = sprite; sprite.setPosition(x, y); }
Example 18
Source File: ImageButtonView.java From seventh with GNU General Public License v2.0 | 4 votes |
@Override public void render(Canvas renderer, Camera camera, float alpha) { Button button = getButton(); if ( button.isVisible() ) { Vector2f position = button.getScreenPosition(); boolean makeBig = false; Rectangle bounds = button.getBounds(); if(button.hasBorder()) { if(button.isHovering()) { renderer.drawRect((int)position.x, (int)position.y, bounds.width, bounds.height, 0xffffffff); } else { renderer.drawRect((int)position.x, (int)position.y, bounds.width, bounds.height, 0xff000000); } } else { makeBig = button.isHovering(); } int color = button.getForegroundColor(); if ( this.buttonImage != null ) { if(this.buttonImage instanceof Sprite) { Sprite sprite = (Sprite)this.buttonImage; sprite.setPosition(position.x, position.y); renderer.drawRawSprite( sprite ); } else { // center the button icon int uw = this.buttonUpImage.getRegionWidth(); int uh = this.buttonUpImage.getRegionHeight(); int w = (uw / 2) - (this.buttonImage.getRegionWidth() / 2) + 1; int h = (uh / 2) - (this.buttonImage.getRegionHeight() / 2) + 1;// + 5; if ( button.isPressed() ) { if ( this.buttonDownImage != null) { renderer.drawScaledImage(this.buttonDownImage, (int)position.x, (int)position.y, uw, uh, color); } renderer.drawScaledImage(this.buttonImage, (int)position.x + w, (int)position.y + h + 5, this.buttonImage.getRegionWidth(), this.buttonImage.getRegionHeight(), color); } else { //renderer.drawImage(this.buttonUpImage, (int)position.x, (int)position.y, color); renderer.drawScaledImage(this.buttonImage, (int)position.x + w, (int)position.y + h, this.buttonImage.getRegionWidth(), this.buttonImage.getRegionHeight(), color); } } } else { Rectangle r = button.getBounds(); if ( button.isPressed() ) { if ( this.buttonDownImage != null) { renderer.drawScaledImage(this.buttonDownImage, (int)position.x, (int)position.y, r.width, r.height, color); } else { renderer.drawScaledImage(this.buttonUpImage, (int)position.x, (int)position.y + 5, r.width, r.height, color); } } else { if(makeBig) { renderer.drawScaledImage(this.buttonUpImage, (int)position.x, (int)position.y, r.width + 5, r.height + 5, color); } else { renderer.drawScaledImage(this.buttonUpImage, (int)position.x, (int)position.y, r.width, r.height, color); } } } super.render(renderer, camera, alpha); } }
Example 19
Source File: Map.java From xibalba with MIT License | 4 votes |
private void createWater() { hasWater = true; flooded = new MapCell.Type[width][height]; for (MapCell.Type[] row : flooded) { Arrays.fill(row, MapCell.Type.WALL); } int floodStartX; int floodStartY; do { floodStartX = MathUtils.random(0, width - 1); floodStartY = MathUtils.random(0, height - 1); } while (!map[floodStartX][floodStartY].isFloor()); flood(floodStartX, floodStartY); for (int x = 0; x < flooded.length; x++) { for (int y = 0; y < flooded[0].length; y++) { if (flooded[x][y] == MapCell.Type.FLOOR) { Sprite water = Main.asciiAtlas.createSprite("0715"); water.setPosition(x * Main.SPRITE_WIDTH, y * Main.SPRITE_HEIGHT); MapCell.Type waterType; Color lightColor; Color darkColor; if (getGroundNeighbours(x, y) < 8) { waterType = MapCell.Type.SHALLOW_WATER; lightColor = Colors.get( Objects.equals(type, "forest") ? "waterShallowLightBlue" : "waterShallowLightGreen" ); darkColor = Colors.get( Objects.equals(type, "forest") ? "waterShallowDarkBlue" : "waterShallowDarkGreen" ); } else { waterType = MapCell.Type.DEEP_WATER; lightColor = Colors.get( Objects.equals(type, "forest") ? "waterDeepLightBlue" : "waterDeepLightGreen" ); darkColor = Colors.get( Objects.equals(type, "forest") ? "waterDeepDarkBlue" : "waterDeepDarkGreen" ); } water.setColor(lightColor); Tween tween = Tween.to(water, SpriteAccessor.COLOR, .5f).target( darkColor.r, darkColor.g, darkColor.b ).repeatYoyo(Tween.INFINITY, MathUtils.random()); map[x][y] = new MapCell(water, waterType, "water", tween); } } } }