Java Code Examples for com.badlogic.gdx.graphics.g2d.Sprite#setRotation()

The following examples show how to use com.badlogic.gdx.graphics.g2d.Sprite#setRotation() . 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: BlendingSpriteParticleRenderer.java    From seventh with GNU General Public License v2.0 6 votes vote down vote up
@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 2
Source File: TankSprite.java    From seventh with GNU General Public License v2.0 6 votes vote down vote up
/**
 * 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 3
Source File: PanzerTankSprite.java    From seventh with GNU General Public License v2.0 6 votes vote down vote up
@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 4
Source File: SpriteParticleRenderer.java    From seventh with GNU General Public License v2.0 5 votes vote down vote up
@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 5
Source File: EntityView.java    From RuinsOfRevenge with MIT License 5 votes vote down vote up
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 vote down vote up
@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);
}