Full project with assets:
deleted
Just create() and render():
override fun create() {
camera = OrthographicCamera()
viewport = ExtendViewport(WORLD_WIDTH, WORLD_HEIGHT, camera)
batch = SpriteBatch()
skeletonRenderer = SkeletonRenderer()
skeletonRenderer.premultipliedAlpha = true
skeletonRendererDebug = SkeletonRendererDebug()
skeletonRendererDebug.setBoundingBoxes(false);
skeletonRendererDebug.setRegionAttachments(false);
val atlas = TextureAtlas(Gdx.files.internal("knight/spear_knight.atlas"))
// val atlas = TextureAtlas(Gdx.files.internal("spineboy/spineboy-pma.atlas"))
val json = SkeletonJson(atlas)
json.scale = 0.2f
skeletonData = json.readSkeletonData(Gdx.files.internal("knight/spear_knight.json"))
// skeletonData = json.readSkeletonData(Gdx.files.internal("spineboy/spineboy-ess.json"))
skeleton = Skeleton(skeletonData)
skeleton.setPosition(100f, 0f)
animationStateData = AnimationStateData(skeletonData)
animationStateData.setMix("idle", "walk", 0.2f)
animationState = AnimationState(animationStateData)
animationState.timeScale = 1f
animationState.setAnimation(0, "idle", true)
}
override fun render() {
val delta = Gdx.graphics.deltaTime
Gdx.gl.glClearColor(0f, 0f, 0f, 1f)
Gdx.gl.glClear(GL20.GL_COLOR_BUFFER_BIT or GL20.GL_DEPTH_BUFFER_BIT)
if (Gdx.input.isKeyJustPressed(Input.Keys.NUM_1)) {
scale += 0.1f
skeleton.rootBone.setScale(scale)
skeleton.updateWorldTransform()
}
if (Gdx.input.isKeyJustPressed(Input.Keys.NUM_2)) {
scale -= 0.1f
skeleton.rootBone.setScale(scale)
skeleton.updateWorldTransform()
}
if (Gdx.input.isKeyJustPressed(Input.Keys.NUM_3)) {
skeleton.rootBone.rotation += 30f
skeleton.updateWorldTransform()
}
animationState.update(delta)
animationState.apply(skeleton)
skeleton.updateWorldTransform()
batch.projectionMatrix = camera.combined
skeletonRendererDebug.shapeRenderer.projectionMatrix = camera.combined
batch.begin()
skeletonRenderer.draw(batch, skeleton)
batch.end()
// skeletonRendererDebug.draw(skeleton)
}