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

The following examples show how to use com.badlogic.gdx.graphics.g2d.Sprite#setOrigin() . 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: ClientBomb.java    From killingspree with MIT License 6 votes vote down vote up
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 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: WrongWay.java    From uracer-kotd with Apache License 2.0 5 votes vote down vote up
public WrongWay () {
	sign = new Sprite(Art.wrongWay);
	float scale = 0.4f;
	w = Art.wrongWay.getWidth() * scale;
	h = Art.wrongWay.getHeight() * scale;
	offX = w / 2;
	offY = h / 2;

	sign.setSize(w, h);
	sign.setOrigin(offX, offY);
	sign.flip(false, true);
	bfAlpha = new BoxedFloat(0);
	isShown = false;
}
 
Example 5
Source File: ResourceManager.java    From TerraLegion with MIT License 5 votes vote down vote up
public Sprite loadSprite(String id, String file, float scaleX, float scaleY) {
	Sprite sprite = new Sprite(new Texture(Gdx.files.internal(file)));
	sprite.getTexture().setFilter(TextureFilter.Linear, TextureFilter.Nearest);
	sprite.setScale(scaleX, scaleY);
	sprite.setOrigin(0, 0);
	sprites.put(id, sprite);
	return sprite;
}
 
Example 6
Source File: ClientPlayer.java    From killingspree with MIT License 5 votes vote down vote up
public ClientPlayer(short id, float x, float y, WorldRenderer renderer) {
    super(id, x, y, renderer);
    markForDispose = false;
    Texture texture = AssetLoader.instance.getTexture("sprites/player.png");
    sprite = new Sprite(texture);
    gunSprite = new Sprite(AssetLoader.instance.getTexture("sprites/arrow.png"));
    gunSprite.setOrigin(gunSprite.getWidth()/2, gunSprite.getHeight()/2);
    walk = new Animation(0.05f, TextureRegion.split(texture,
            texture.getWidth()/10, texture.getHeight())[0]);
    walk.setPlayMode(Animation.PlayMode.LOOP);
    walkDuration = 0;
    gunSprite.setSize(40, 6);
    gunSprite.setOrigin(gunSprite.getWidth()/2, gunSprite.getHeight()/2);
    gunSprite.setAlpha(0.7f);
}
 
Example 7
Source File: ClientBullet.java    From killingspree with MIT License 5 votes vote down vote up
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 8
Source File: ClientArrow.java    From killingspree with MIT License 5 votes vote down vote up
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 9
Source File: PlayerSprite.java    From seventh with GNU General Public License v2.0 5 votes vote down vote up
private void setTextureRegion(Sprite sprite, TextureRegion region) {
    sprite.setTexture(region.getTexture());
    sprite.setRegion(region);        
    sprite.setSize(region.getRegionWidth(), region.getRegionHeight());
    sprite.setOrigin(region.getRegionWidth()/2f, region.getRegionHeight()/2f);
    sprite.flip(false, true);        
}
 
Example 10
Source File: ClientGrenade.java    From seventh with GNU General Public License v2.0 5 votes vote down vote up
/**
 * 
 */
public ClientGrenade(ClientGame game, Vector2f pos, Type grenadeType) {
    super(game, pos);    
    this.grenadeType = grenadeType;
    
    sprite = new Sprite(grenadeType==Type.SMOKE_GRENADE ? Art.smokeGrenadeImage : Art.fragGrenadeImage);
    sprite.setSize(16, 16);
    sprite.setOrigin(8, 8);
    sprite.flip(false, true);            
}
 
Example 11
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 12
Source File: SpritesSample.java    From Codelabs with MIT License 4 votes vote down vote up
@Override
public void show() {
	/*
	 * This line is found in every sample but is not necessary for the
	 * sample functionality. calls Sample.show() method. That method set the
	 * sample to receive all touch and key input events. Also prevents the
	 * app from be closed whenever the user press back button and instead
	 * returns to main menu.
	 */
	super.show();

	/*
	 * Create world with a common gravity vector (9.81 m/s2 downwards force)
	 * and tell world that we want objects to sleep. This last value
	 * conserves CPU usage.
	 */
	world = new World(new Vector2(0, -9.81f), true);

	/* Create renderer */
	debugRenderer = new Box2DDebugRenderer();

	batch = new SpriteBatch();

	/*
	 * Define camera viewport. Box2D uses meters internally so the camera
	 * must be defined also in meters. We set a desired width and adjust
	 * height to different resolutions.
	 */
	camera = new OrthographicCamera(20,
			20 * (Gdx.graphics.getHeight() / (float) Gdx.graphics
					.getWidth()));

	/*
	 * Next line must remain commented because we do this in its parent (See
	 * Sample class). In case you are not using Sample class, uncomment this
	 * line to set input processor to handle events.
	 */
	// Gdx.input.setInputProcessor(this);

	/* Create the box */
	Shape shape = Box2DFactory.createBoxShape(1.5f, 1.5f,
			new Vector2(0, 0), 0);
	FixtureDef fixtureDef = Box2DFactory.createFixture(shape, 0.3f, 0.5f,
			0.5f, false);
	box = Box2DFactory.createBody(world, BodyType.DynamicBody, fixtureDef,
			new Vector2(0, 0));

	/* Create the walls */
	Box2DFactory.createWalls(world, camera.viewportWidth,
			camera.viewportHeight, 1);

	/* Set box texture */
	sprite = new Sprite(new Texture("data/images/crab.png"));

	/*
	 * Set the size of the sprite. We have to remember that we are not
	 * working in pixels, but with meters. The size of the sprite will be
	 * the same as the size of the box; 2 meter wide, 2 meters tall.
	 */
	sprite.setSize(3, 3);

	/*
	 * Sets the origin in relation to the sprite's position for scaling and
	 * rotation.
	 */
	sprite.setOrigin(sprite.getWidth() / 2, sprite.getHeight() / 2);

	/* Set sprite as a user data of the body to draw it in each render step */
	box.setUserData(sprite);

	/* Instantiate the array of bodies that will be used during render step */
	worldBodies = new Array<Body>();
}