Java tutorial
/* * To change this license header, choose License Headers in Project Properties. * To change this template file, choose Tools | Templates * and open the template in the editor. */ package com.github.skittishSloth.openSkies.battles.weapons; import com.badlogic.gdx.graphics.Texture; import com.badlogic.gdx.graphics.g2d.Sprite; import com.badlogic.gdx.graphics.g2d.SpriteBatch; import com.badlogic.gdx.math.Vector2; import com.badlogic.gdx.utils.Disposable; /** * * @author mcory01 */ public class Laser implements Disposable { public Laser(final float angle, final Vector2 initialPosition) { texture = new Texture("gfx/weapons/laserGreen.png"); sprite = new Sprite(texture); width = sprite.getWidth(); height = sprite.getHeight(); originX = width / 2; originY = height / 2; this.position = new Vector2(initialPosition.x, initialPosition.y); this.velocity = new Vector2(0, 300); offset = new Vector2(-originX, 0); offset.rotate(angle); position.add(offset); velocity.rotate(angle); sprite.setOrigin(originX, originY); sprite.setRotation(angle); } public void render(final SpriteBatch batch, final float delta) { position.x += velocity.x * delta; position.y += velocity.y * delta; sprite.setPosition(position.x, position.y); sprite.draw(batch); // batch.draw(texture, position.x, position.y, originX, originY, width, height, 1.0f, 1.0f, velocity.angle() + 90, 0, 0, width, height, false, false); } public boolean isAlive() { return alive; } public void setAlive(final boolean alive) { this.alive = alive; } public float getX() { return position.x; } public float getY() { return position.y; } @Override public void dispose() { texture.dispose(); } private boolean alive = true; private final float width, height; private final float originX, originY; private final Vector2 position; private final Vector2 velocity; private final Vector2 offset; private final Texture texture; private final Sprite sprite; }