Java Code Examples for com.badlogic.gdx.graphics.g2d.Sprite#draw()
The following examples show how to use
com.badlogic.gdx.graphics.g2d.Sprite#draw() .
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: 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 2
Source File: GdxCanvas.java From seventh with GNU General Public License v2.0 | 5 votes |
@Override public void drawSprite(Sprite sprite) { if(!isBegun) batch.begin(); sprite.setColor(1,1,1, this.compositeAlpha); sprite.draw(batch); if(!isBegun) batch.end(); }
Example 3
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 4
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 5
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 6
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 7
Source File: GdxCanvas.java From seventh with GNU General Public License v2.0 | 4 votes |
@Override public void drawRawSprite(Sprite sprite) { if(!isBegun) batch.begin(); sprite.draw(batch); if(!isBegun) batch.end(); }