I used to extend my Player/Entity class with Sprite, that way I could create a walking animation using SetRegion and super(stilldown.getKeyFrame(0));
I've recently started porting everything over to Scene2D and I use Actors now. I do not know how to use this way of animation anymore, does anybody have a guess how I could do this?
animationtime += delta;
if(dir == Direction.DOWN){
setRegion(velocity.y == 0 ? stilldown.getKeyFrame(animationtime) : walking.getKeyFrame(animationtime));
}else if (dir == Direction.UP){
setRegion(velocity.y == 0 ? stillup.getKeyFrame(animationtime) : walkingup.getKeyFrame(animationtime));
}else if (dir == Direction.RIGHT){
setRegion(velocity.x == 0 ? stillright.getKeyFrame(animationtime) : walkingright.getKeyFrame(animationtime));
}else if (dir == Direction.LEFT){
setRegion(velocity.x == 0 ? stillleft.getKeyFrame(animationtime) : walkingleft.getKeyFrame(animationtime));
}
This is how I'd initialise the animation
playeratlas = new TextureAtlas("overworld/player/playersheet.pack");
Animation walking;
Animation walkingup;
Animation walkingright;
Animation walkingleft;
Animation stilldown;
Animation stillup;
Animation stillright;
Animation stillleft;
walking = new Animation(1 / 4f, playeratlas.findRegions("walkingdown"));
walkingup = new Animation(1 / 4f, playeratlas.findRegions("walkingup"));
walkingright = new Animation(1 / 4f, playeratlas.findRegions("walkingright"));
walkingleft = new Animation(1 / 4f, playeratlas.findRegions("walkingleft"));
stilldown = new Animation(1 / 4f, playeratlas.findRegions("stilldown"));
stillup = new Animation(1 / 4f, playeratlas.findRegions("stillup"));
stillright = new Animation(1 / 4f, playeratlas.findRegions("stillright"));
stillleft = new Animation(1 / 4f, playeratlas.findRegions("stillleft"));
walking.setPlayMode(Animation.PlayMode.LOOP);
walkingup.setPlayMode(Animation.PlayMode.LOOP);
walkingright.setPlayMode(Animation.PlayMode.LOOP);
walkingleft.setPlayMode(Animation.PlayMode.LOOP);
stilldown.setPlayMode(Animation.PlayMode.LOOP);
stillup.setPlayMode(Animation.PlayMode.LOOP);
stillright.setPlayMode(Animation.PlayMode.LOOP);
stillleft.setPlayMode(Animation.PlayMode.LOOP);
For now I only use a static image for my Actor
Sprite text = new Sprite(new Texture(Gdx.files.internal("overworld/player/placeholder.png")));
Now I draw it like this
public void draw(Batch batch, float ParentAlpha){
text.draw(batch);
}
I would greatly appreciate help, I'm new to Scene2D and I can't find much on it.
Scene2d
for your game objects.Scene2d
is a UI package and is not supposed to be used for anything else. What made you change to Actors? \$\endgroup\$