Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // in show method:
- Sprite sprite = new Sprite(animation.getKeyFrame(0)); // creates it with the first frame, not important
- sprite.setSize(shape.getRadius() * 2, shape.getRadius() * 2); // set the size to the shape size (it's a CircleShape, don't just use the radius for other shapes!)
- sprite.setOrigin(sprite.getWidth() / 2, sprite.getHeight() / 2); // recalculate the origin
- ballBody.setUserData(new Object[] {sprite, animation}); // not really the best way to store the things. better make a class for them
- // in render method:
- animationTime += delta; // accumulate animation state time
- batch.begin();
- for(Body body : tmpBodies)
- if(body.getUserData() instanceof Object[]) {
- // get the Sprite and Animation from the Object array
- Sprite sprite = (Sprite) ((Object[]) body.getUserData())[0];
- Animation animation = (Animation) ((Object[]) body.getUserData())[1];
- sprite.setPosition(body.getPosition().x - sprite.getWidth() / 2, body.getPosition().y - sprite.getHeight() / 2);
- sprite.setRotation(body.getAngle() * MathUtils.radDeg);
- sprite.setRegion(animation.getKeyFrame(animationTime)); // update the sprite's region with the frame from the animation (does not influence position or size)
- sprite.draw(batch);
- }
- batch.end();
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement