I'm trying to move a sprite in libGDX by using a method, that is changing its x and y coordinates every time it is called (it's supposed to be an "animation" for a card game).
if (card.isAnimated()) {
card.getSprite().setX(card.getX());
card.getSprite().setY(card.getY());
System.out.println("X: " + card.getSprite().getX());
System.out.println("Y: " + card.getSprite().getY());
card.getSprite().draw(batch); }
The System.out updates perfectly with the new coordinates, yet the position of the card on the screen doesn't change. Another weird thing is: I'm using drag&drop that works basically the same way, and it's doing fine!
if(card.isDragged() == true){
//Card is dragged:
card.getSprite().setX(card.getX());
card.getSprite().setY(card.getY());
card.getSprite().draw(batch); }
Could the render-Function be blocked by the automatic function? It looks similar to this:
public void animateCardsPlayed(ArrayList<Card> cards) {
for(Card card : cards) {
card.setAnimated(true);
float deltaX = card.getX() - CardStack.ACTIVE_X;
float deltaY = card.getY() - CardStack.ACTIVE_Y;
System.out.println("DELTAX: " + deltaX);
System.out.println("DELTAY: " + deltaY);
if (deltaX <= 0) { //Karte links von Stapel
if (deltaY <= 0) { //Karte unter Stapel
while (card.getX() <= CardStack.ACTIVE_X && card.getY() <= CardStack.ACTIVE_Y) {
if (card.getX() <= CardStack.ACTIVE_X) {
float newX = card.getX() - deltaX/1000f;
card.setX(newX);
card.getSprite().setX(card.getX());
}
if (card.getY() <= CardStack.ACTIVE_Y) {
float newY = card.getY() - deltaY/1000f;
card.setY(newY);
card.getSprite().setY(card.getY());
}
System.out.println("1HIER");
screen.render(0); //Maybe that's the problem?
} //...
Does anybody have an idea? I would be utterly thankful.. Best Regards, Sebie
UPDATE: It seems like the whole screen is freezing until the function is done.. Is there any possibility to do something like that without multithreading?