Sprite setTexture not working - java

I'm new to libgdx and I don't know yet how the Sprite class works, so I run into a bit of a problem with Sprite.setTexture() not woking(I need this for animations). Long story short(as an example):
sprite = new Sprite (imgb); //work flawlessly
sprite2 = new Sprite ();
sprite2.setTexture (imgb); //doesn't do anything
Is there a problem with the way I did things or there is something else?
Original code My Player class:
package com.triodefender.game;
import java.util.Vector;
import com.badlogic.gdx.graphics.Texture;
import com.badlogic.gdx.graphics.g2d.Sprite;
import com.badlogic.gdx.graphics.g2d.SpriteBatch;
import com.badlogic.gdx.graphics.g2d.TextureRegion;
import jdk.nashorn.internal.runtime.Debug;
public class Player {
SpriteBatch batch = new SpriteBatch ();
Sprite sprite = new Sprite ();
//Animator animator;
float cx, cy;
float hp;
Texture img = new Texture ("bullet.png"), imgp = new Texture("turret.png");
Vector<Bullet> bullets = new Vector<Bullet>();
void Debug () {
Sprite debug = new Sprite (new Texture("debug.png"), 0, 0, 15, 15);
debug.setPosition (sprite.getX(), sprite.getY());
batch.begin ();
debug.draw (batch);
batch.end ();
debug.setPosition (cx, cy);
batch.begin ();
debug.draw (batch);
batch.end();
}
Player (com.badlogic.gdx.graphics.Color color) {
//animator = new Animator(a);
//sprite = new Sprite (imgp); //this works
sprite = new Sprite ();
sprite.setTexture(imgp); //this doesn't work
sprite.setOriginCenter();
sprite.setColor(color);
hp = 100f;
}
void Update (float ox, float oy, float rotation, boolean shoot) {
cx = ox; cy = oy;
sprite.setPosition(ox - sprite.getWidth()/2, oy - sprite.getHeight()/2);
sprite.setRotation(-rotation);
if (shoot) {
AddBullet();
//animator.lockRow(0, 1, 5);
}
UpdateBullets();
}
void AddBullet () {
float l = sprite.getWidth()/2f;
float sn = (float) Math.sin(Math.toRadians(-sprite.getRotation()));
float cs = (float)Math.cos(Math.toRadians( -sprite.getRotation() ));
float newpx = cx + (float)(l+16f)*sn;
float newpy = cy + (float)(l+16f)*cs;
bullets.add(new Bullet(new Sprite(img), newpx, newpy, -sprite.getRotation(), 10f, sprite.getColor()));
}
void UpdateBullets () {
for (int i = 0; i < bullets.size(); i++)
if (bullets.elementAt(i).Update() == false) {
bullets.remove(i);
i--;
}
}
void DrawBullets () {
for (int i = 0; i < bullets.size(); i++)
bullets.elementAt(i).Draw();
}
float getRotation () {
return sprite.getRotation();
}
void Draw () {
//Debug ();
batch.begin();
sprite.draw(batch);
batch.end();
DrawBullets ();
}
}

You should consult the Sprite source code:
/** Creates an uninitialized sprite. The sprite will need a texture region and bounds set before it can be drawn. */
public Sprite () {
setColor(1, 1, 1, 1);
}
/** Creates a sprite with width, height, and texture region equal to the size of the texture. */
public Sprite (Texture texture) {
this(texture, 0, 0, texture.getWidth(), texture.getHeight());
}
As you can see the second constructor initializes the sprite's texture and bounds (by calling another Sprite constructor). The first constructor only sets its color.
To get the first constructor up to speed with the second you need to define the texture region and bounds before drawing. You set the texture but you still need to define the bounds. Try adding sprite2.setBounds(0, 0, imgb.getWidth(), imgb.getHeight());

I thinks you need
sprite.setRegion(..And select you need);

Related

Java LibGDX how to check if sprite stands on specific tile e.g. door?

I want to change the map (method changeMapToWinter()) when sprite stands on specific tile of specific map. I have no layers on map.
Currently I do something like that if(sprite.getX() > 100 && sprite.getX() < 200 && sprite.getY() > 100 && sprite.getY() < 200) but of course it works only on one map and do not look too good and I guess there is a better solution for that.
Texture img;
TiledMap tiledMap;
OrthographicCamera camera;
TiledMapRenderer tiledMapRenderer;
SpriteBatch sb;
Texture texture;
Sprite sprite;
private ShapeRenderer shapeRenderer;
private TiledMapTileLayer tileLayer;
private TiledMap winterMap;
#Override
public void create() {
float w = Gdx.graphics.getWidth();
float h = Gdx.graphics.getHeight();
camera = new OrthographicCamera();
camera.setToOrtho(false, w, h);
camera.update();
tiledMap = new TmxMapLoader().load("untitled.tmx");
winterMap = new TmxMapLoader().load("untitled2.tmx");
tiledMapRenderer = new OrthogonalTiledMapRenderer(tiledMap);
Gdx.input.setInputProcessor(this);
sb = new SpriteBatch();
texture = new Texture(Gdx.files.internal("bold_brown_blue-1.png"));
sprite = new Sprite(texture);
}
void changeMapToWinter() {
tiledMap.dispose();
winterMap = new TmxMapLoader().load("untitled2.tmx");
tiledMapRenderer = new OrthogonalTiledMapRenderer(winterMap);
}
#Override
public void render() {
Gdx.gl.glClearColor(1, 0, 0, 1);
Gdx.gl.glBlendFunc(GL20.GL_SRC_ALPHA, GL20.GL_ONE_MINUS_SRC_ALPHA);
Gdx.gl.glClear(GL20.GL_COLOR_BUFFER_BIT);
camera.update();
tiledMapRenderer.setView(camera);
tiledMapRenderer.render();
sb.begin();
sb.draw(sprite, (int) (Gdx.app.getGraphics().getWidth() / 2) - (sprite.getWidth()), (int) (Gdx.app.getGraphics().getHeight() / 2) - (sprite.getHeight() / 2));
sb.end();
Vector3 click = new Vector3(Gdx.input.getX(), Gdx.input.getY(), 0);
TiledMapTileLayer layer = (TiledMapTileLayer)tiledMap.getLayers().get(0);
// WANT TO CHANGE IT
if(sprite.getX() > 100 && sprite.getX() < 200 && sprite.getY() > 100 && sprite.getY() < 200)
changeMapToWinter();
}
Solution you might use can be something like this:
Rectangle changePosition = new Rectangle(100,100,100,100);
if(sprite.getBoundingRectangle().overlaps(changePosition)) ...
Constructor for rectangle have this format Rectangle(float x, float y, float width, float height).
Also this will behave a bit differently from your code as you weren't taking into account size of the sprite, but this code does.
Btw LibGDX have usefull class for problems like this if you wouldn't be able to find appropriate function in Rectangle class or whatever shape you are using. It is called Intersector.

libGDX Strange Rendering Bug

I've recently started my first libGDX game, and it is all going well, everything renders fine but after about a minute nothing renders, the rendering calls are still made and the spritebatch works fine, I'm just left with a black screen, I have even changed the 'glClearColor()' to but I'm still left with a black screen. I've have no idea what this could be.
My main class:
#Override
public void create() {
Gdx.graphics.setDisplayMode(Settings.screenWidth, Settings.screenHeight, Settings.fullscreen);
Gdx.graphics.setVSync(Settings.VSync);
Gdx.graphics.setTitle("Trench Warfare");
batch = new SpriteBatch(1000);
previous = System.currentTimeMillis();
currentMap = new Map(this, 0);
currentMap.addObject(new ColourMapObject(this, 0));
}
private void update() {Settings.screenHeight, Settings.fullscreen);
Gdx.graphics.setVSync(Settings.VSync);
batch.setColor(new Color(Settings.brightness, Settings.brightness, Settings.brightness, 1.0f));
float delta = ((float)(System.currentTimeMillis() - previous)) / 1000.0f;
previous = System.currentTimeMillis();
currentMap.update(delta);
}
#Override
public void render() { //Always called
update();
Gdx.gl.glClearColor(1, 0, 0, 1); //Red colour still black screen.
Gdx.gl.glClear(GL20.GL_COLOR_BUFFER_BIT);
batch.begin();
currentMap.render(batch); //Basicly list of textures to be rendered, they never stop rendering (Being called) despite black screen.
batch.end();
batch.flush();
}
EDIT:
We've determined that after some time SpriteBatch render a black screen over the red clear colour, It also stops rendering the texture.
I've also determined that the SpriteBatch's tint or colour stays white even during the black screen.
EDIT, this code takes in a texture and then turns into a different texture with different colours:
public class ColourMapObject extends MapObject {
public enum Type {
Dirt,
Water,
Trench,
}
private Texture terrainMap;
private Texture trenchMap;
private Texture soldierMap;
private Texture buildingMap;
private Texture shipMap;
private int levelId;
private Texture finalTexture;
private Type[][] types;
public ColourMapObject(TrenchMain main, int levelId) {
super(main);
this.levelId = levelId;
//finalTexture = new Texture("/map" + String.valueOf(levelId) + "/terrainMap.png");
finalTexture = new Texture("black.png");
finalTexture.getTextureData().prepare();
loadMap(levelId);
}
private void loadMap(int levelId) {
//terrainMap = new Texture("/map" + String.valueOf(levelId) + "/terrainMap.png");
terrainMap = new Texture("terrainMap.png");
types = new Type[terrainMap.getWidth()][terrainMap.getHeight()];
terrainMap.getTextureData().prepare();
Pixmap pixmap = terrainMap.getTextureData().consumePixmap();
for(int x = 0; x < terrainMap.getWidth(); x++) {
for(int y = 0; y < terrainMap.getHeight(); y++) {
types[x][y] = RandomMapColour.getType(new Color(pixmap.getPixel(x, y)));
if(types[x][y] == null) types[x][y] = Type.Dirt;
}
}
// trenchMap = new Texture("/map" + String.valueOf(levelId) + "/trenchMap.png");
//
//
// soldierMap = new Texture("/map" + String.valueOf(levelId) + "/soldierMap.png");
//
//
// buildingMap = new Texture("/map" + String.valueOf(levelId) + "/buildingMap.png");
//
//
// shipMap = new Texture("/map" + String.valueOf(levelId) + "/shipMap.png");
}
#Override
public void update(float delta) {
super.update(delta);
Pixmap draw = new Pixmap(Settings.screenWidth, Settings.screenHeight, Format.RGB888);
float pX = (float)terrainMap.getWidth() / (float)draw.getWidth();
float pY = (float)terrainMap.getHeight() / (float)draw.getHeight();
for(int x = 0; x < draw.getWidth(); x++) {
for(int y = 0; y < draw.getHeight(); y++) {
switch(types[(int)((float)x * pX)][(int)((float)y * pY)]) {
case Dirt:
draw.drawPixel(x, y, RandomMapColour.getDirtColour());
break;
case Trench:
draw.drawPixel(x, y, RandomMapColour.getTrenchColour());
break;
case Water:
draw.drawPixel(x, y, RandomMapColour.getWaterColour());
break;
}
}
}
finalTexture = new Texture(draw);
}
#Override
public void render(SpriteBatch batch) {
super.render(batch);
float sx = ((float)TrenchMain.getScreenWidth()) / ((float)finalTexture.getWidth());
float sy = ((float)TrenchMain.getScreenHeight()) / ((float)finalTexture.getHeight());
batch.draw(finalTexture, 0, 0, 0, 0, finalTexture.getWidth(), finalTexture.getHeight(), sx, sy, 0, 0, 0, finalTexture.getWidth(), finalTexture.getHeight(), false, false);
}
I finally figuired it out, for those who are wonder, what I was doing was creating a new finalTexture every update with disposing of the old one.
Simply dispose of the texture.
finalTexture.dispose();

LibGDX TiledMap - don't detect Collisions

first of all, sorry, because of my rusty English. Since i learnt German i forgot the English.
I'm doing tests with libGDX and my code doesn't detect any collisions.
In my Screen:
public Pantalla(SpriteBatch batch_1) {
batch = batch_1;
screenWidth = Gdx.graphics.getWidth();
screenHeight = Gdx.graphics.getHeight();
stage = new Stage(new StretchViewport(Gdx.graphics.getWidth(), Gdx.graphics.getHeight()),batch);
Gdx.input.setInputProcessor(stage);
camera = new OrthographicCamera();
camera.setToOrtho(false, 1000, 840);
camera.update();
mapas = new Mapas(camera);
// ACTORS
indiana_actor = new indiana_Actor();
//Here comes TOUCHPAD with Skin blaBlaBla...
if (touchpad.isTouched()) {
if (touchpad.getKnobX() > 120) {
indiana_actor.moveBy(32,0);
camera.translate(32, 0);
return; }
}
stage.addActor(indiana_actor);
stage.addActor(touchpad);
Gdx.input.setInputProcessor(stage);
}
public void render(float delta) {//TODO RENDER
Gdx.gl.glClearColor(0, 0, 0, 1);
Gdx.gl.glClear(GL20.GL_COLOR_BUFFER_BIT);
mapas.MapasRender(camera,indiana_actor);
batch.begin();
batch.end();
stage.act(Gdx.graphics.getDeltaTime());
stage.draw();
}
indiana_actor Class:
public indiana_Actor() {
W=Gdx.graphics.getWidth(); H=Gdx.graphics.getHeight();
bounds=new Rectangle((int)getX(), (int)getY(), (int)getWidth(), (int)getHeight());
}
Animation anim_temp;
#Override
public void draw(Batch batch, float parentAlpha) {
stateTime += Gdx.graphics.getDeltaTime();
batch.setColor(getColor());
batch.draw(Assets.indiana_stop_arriba, (W/2), (H/2), 110, 160);
bounds=new Rectangle((int)getX(), (int)getY(), (int)getWidth(), (int)getHeight());
}
and Mapas Class.
In these class i get the Objects in the "objetos" TiledLayer, and triying to check collisions with a for(...) in the renderer.
public Mapas(OrthographicCamera camera2){
map = new TmxMapLoader().load("terrain/prueba.tmx");
renderer = new OrthogonalTiledMapRenderer(map, 10);//ESCALA
renderer.setView(camera2);
collisionObjects = map.getLayers().get("objetos").getObjects();
collisionRects = new Array<Rectangle>();
collisionRects_total=collisionObjects.getCount();
int tileWidth = 32; // whatever your tile width is
int tileHeight = 32; // whatever your tile height is
for (int i = 0; i < collisionObjects.getCount(); i++) {
RectangleMapObject obj = (RectangleMapObject) collisionObjects.get(i);
Rectangle rect = obj.getRectangle();
collisionRects.add(new Rectangle(rect.x / tileWidth, rect.y / tileHeight, rect.width / tileWidth, rect.height / tileHeight));
}
}
public void MapasRender(OrthographicCamera camera2,indiana_Actor indi){
camera2.update();
renderer.setView(camera2);
renderer.render();
for (int i = 0; i < collisionRects_total; i++) {
Rectangle rect = collisionRects.get(i);
if (indi.bounds.overlaps(rect)){
Gdx.app.log("EVENTO", "MAPAS RENDER - COLISION!");
}if (rect.overlaps(indi.bounds)){
Gdx.app.log("EVENTO", "MAPAS RENDER - COLISION!");
}
}
}
I know (Through the logcat) that the
" for (int i = 0; i < collisionRects_total; i++) {
Rectangle rect = collisionRects.get(i); "
get always the objectsRectangle , but in the next line find any overlaps.
Is that a problem with the actor bounds-rectangle?A problem when moving actor through the map??....
Thanks in advance!!
Why dont U at first check if your rectangle for collision draw correctly on position. You can do that by calling
shapeRenderer.begin(ShapeType.Line);
shapeRenderer.setColor(Color.NAVY);
shapeRenderer.rect(object.getrect().x,
object.getrect().y,object.getrect().width,
object.getrect().height);
may be you draw collision rectangles at wrong position so collision will never occur.

Drawing a CatmullRomSpline in libgdx with an endpoint and startpoint

So my goal is to draw a spline similar to this one (where the line goes through each point):
But the spline loops around (from the end point 2 back to the start point):
I tried changing the "continuous" boolean in the catmullromspline, but that resulted in only a dot being drawn in the center of the screen.
I also ended the line drawing when it hit the last point, but the result was ugly because the line was still curving at the start and end points.
I looked everywhere in the source code, and could not find a function that could prevent it from looping.
And as far as i know, bezier splines don't go through all the points (they only pass near them).
So what should I do?
Here's my code:
...
public class GameScreen implements Screen {
final game game;
float w=800;
float h=480;
OrthographicCamera camera;
long startTime;
Texture baseTexture=new Texture(Gdx.files.internal("white.png"));
public GameScreen(final game gam) {
this.game = gam;
startTime = TimeUtils.millis();
camera = new OrthographicCamera();
camera.setToOrtho(false, w, h);
setup();
}
//https://github.com/libgdx/libgdx/wiki/Path-interface-&-Splines
int k = 10000; //increase k for more fidelity to the spline
Vector2[] points = new Vector2[k];
Vector2 cp[] = new Vector2[]{
new Vector2(w/2, h), new Vector2(w/2, h/2),new Vector2(50, 50)
};
ShapeRenderer rope=new ShapeRenderer();
public void setup(){
CatmullRomSpline<Vector2> myCatmull = new CatmullRomSpline<Vector2>( cp, true);
for(int i = 0; i < k; ++i)
{
points[i] = new Vector2();
myCatmull.valueAt(points[i], ((float)i)/((float)k-1));
}
}
#Override
public void render(float delta) {
Gdx.gl.glClear(GL20.GL_COLOR_BUFFER_BIT);
Gdx.gl20.glLineWidth(50);
game.batch.begin();
rope.setAutoShapeType(true);
rope.begin();
for(int i = 0; i < k-1; ++i)
{
//rope.line(points[i], points[i+1]);
//shaper.line(myCatmull.valueAt(points[i], ((float)i)/((float)k-1)), myCatmull.valueAt(points[i+1], ((float)i)/((float)k-1)));
game.batch.draw(baseTexture, points[i].x, points[i].y, 5, 5);
}
rope.end();
for(int i=0;i<cp.length;i++){//draw the location of each point
game.font.draw(game.batch, "point "+i, cp[i].x, cp[i].y);
}
//logging systems
for(int i=0;i<20;i++){
if(Gdx.input.isTouched(i))
game.font.draw(game.batch, "x:"+Gdx.input.getX(i)+" y:"+Gdx.input.getY(i), 0, (game.font.getCapHeight()+10)*(i+1));
}
game.font.draw(game.batch, "fps:"+Gdx.graphics.getFramesPerSecond()+" log:"+log, 0, h-game.font.getCapHeight());
game.batch.end();
}
...

libgdx won't draw sprite or animation

it seems as though i cannot get the draw method to work???
it seems as though the bullet.draw(batcher)
does not work and i cannot understand why as the bullet is a sprite.
i have made a Sprite[] and added them as animation.
could that be it?
i tried
batcher.draw(AssetLoader.bulletAnimation.getKeyFrame(runTime), bullet.getX(), bullet.getY(), bullet.getOriginX() / 2, bullet.getOriginY() / 2, bullet.getWidth(), bullet.getHeight(), 1, 1, bullet.getRotation());
but that dont work, the only way it draws is this
batcher.draw(AssetLoader.bulletAnimation.getKeyFrame(runTime), bullet.getX(), bullet.getY());
below is the code.
// this is in a Asset Class
texture = new Texture(Gdx.files.internal("SpriteN1.png"));
texture.setFilter(TextureFilter.Nearest, TextureFilter.Nearest);
bullet1 = new Sprite(texture, 380, 350, 45, 20);
bullet1.flip(false, true);
bullet2 = new Sprite(texture, 425, 350, 45, 20);
bullet2.flip(false, true);
Sprite[] bullets = { bullet1, bullet2 };
bulletAnimation = new Animation(0.06f, bullets);
bulletAnimation.setPlayMode(Animation.PlayMode.LOOP);
// this is the GameRender class
public class GameRender() {
private Bullet bullet;
private Ball ball;
public GameRenderer(GameWorld world) {
myWorld = world;
cam = new OrthographicCamera();
cam.setToOrtho(true, 480, 320);
batcher = new SpriteBatch();
// Attach batcher to camera
batcher.setProjectionMatrix(cam.combined);
shapeRenderer = new ShapeRenderer();
shapeRenderer.setProjectionMatrix(cam.combined);
// Call helper methods to initialize instance variables
initGameObjects();
initAssets();
}
private void initGameObjects() {
ball = GameWorld.getBall();
bullet = myWorld.getBullet();
scroller = myWorld.getScroller();
}
private void initAssets() {
ballAnimation = AssetLoader.ballAnimation;
bulletAnimation = AssetLoader.bulletAnimation;
}
public void render(float runTime) {
Gdx.gl.glClearColor(0, 0, 0, 1);
Gdx.gl.glClear(GL30.GL_COLOR_BUFFER_BIT);
batcher.begin();
// Disable transparency
// This is good for performance when drawing images that do not require
// transparency.
batcher.disableBlending();
// The ball needs transparency, so we enable that again.
batcher.enableBlending();
batcher.draw(AssetLoader.ballAnimation.getKeyFrame(runTime), ball.getX(), ball.getY(), ball.getWidth(), ball.getHeight());
batcher.draw(AssetLoader.bulletAnimation.getKeyFrame(runTime), bullet.getX(), bullet.getY());
// End SpriteBatch
batcher.end();
}
}
// this is the gameworld class
public class GameWorld {
public static Ball ball;
private Bullet bullet;
private ScrollHandler scroller;
public GameWorld() {
ball = new Ball(480, 273, 32, 32);
bullet = new Bullet(10, 10);
scroller = new ScrollHandler(0);
}
public void update(float delta) {
ball.update(delta);
bullet.update(delta);
scroller.update(delta);
}
public static Ball getBall() {
return ball;
}
public ScrollHandler getScroller() {
return scroller;
}
public Bullet getBullet() {
return bullet;
}
}
is there anyway so make the sprite work?
i am adding the bullet class to see if there could be something wrong there.
public class Bullet extends Sprite {
public static final float BULLET_HOMING = 6000;
public static final float BULLET_SPEED = 300;
private Vector2 velocity;
private float lifetime;
public Bullet(float x, float y) {
velocity = new Vector2(0, 0);
setPosition(x, y);
}
public void update(float delta) {
float targetX = GameWorld.getBall().getX();
float targetY = GameWorld.getBall().getY();
float dx = targetX - getX();
float dy = targetY - getY();
float distToTarget = (float) Math.sqrt(dx * dx + dy * dy);
dx /= distToTarget;
dy /= distToTarget;
dx *= BULLET_HOMING;
dy *= BULLET_HOMING;
velocity.x += dx * delta;
velocity.y += dy * delta;
float vMag = (float) Math.sqrt(velocity.x * velocity.x + velocity.y * velocity.y);
velocity.x /= vMag;
velocity.y /= vMag;
velocity.x *= BULLET_SPEED;
velocity.y *= BULLET_SPEED;
Vector2 v = velocity.cpy().scl(delta);
setPosition(getX() + v.x, getY() + v.y);
setOriginCenter();
setRotation(velocity.angle());
lifetime += delta;
setRegion(AssetLoader.bulletAnimation.getKeyFrame(lifetime));
}
}
Your keyframes are kept in an array called bullets, but when you call the Animation constructor you pass something called 'aims' as the second argument. You should try instead passing 'bullets', as in:
bulletAnimation = new Animation(0.06f,bullets);
You shouldn't have a problem with using a Sprite[] as the Sprite class extends TextureRegion I think.
------ OP fixed the typo and still didn't work------
I think the problem will be with the origin arguments of the batcher.draw()call. The position of the Sprite is relative to the origin of the SpriteBatch's co-ordinate system, and the origin of the Sprite is relative to this position (i.e. the bottom-left corner of the Sprite rectangle). To get an origin in the center of the Sprite, i think originX should be width/2 and originY should be height/2. So try:
batcher.draw(AssetLoader.bulletAnimation.getKeyFrame(runTime),bullet.getX(),bullet.getY(), bullet.getWidth()/2,bullet.getHeight()/2,bullet.getWidth(),bullet.getHeight(),1,1,bullet.getRotation());
Because if your getOriginX/Y methods return origins relative to the SpriteBatcher's co-ordinate system(the screen co-ordinates), then your Sprites could be rotating and scaling around some ridiculous origin and end up being drawn off-screen.
I hope I'm right and it's problem solved.
----- OP posted further code, the 'bullet' class-----
When you call bullet.getWidth() and bullet.getHeight() in your draw method, these will return 0.0f because you haven't specified values for them. Remember the Sprites you are actually drawing are bullet1 and bullet2 from your AssetLoader class. Try setting bullet's width and height with:
setSize(AssetLoader.bullet1.getWidth(), AssetLoader.bullet1.getHeight());
in your bullet constructor.
I don't think you need to use setRegion() in your bullet class either, again, because the Sprites you're actually drawing are bullet1 and 2.
fingers crossed.
try and change the update method to this
Vector2 target = new Vector2(GameWorld.getBall().getX(), GameWorld.getBall().getY());
target.sub(getX(), getY());
target.nor().scl(BULLET_HOMING);
velocity.add(target.scl(delta));
velocity.nor().scl(BULLET_SPEED);
Vector2 v = velocity.cpy().scl(delta);
translate(v.x, v.y);
setOriginCenter();
setRotation(velocity.angle());
that should clean your code a little

Categories