Thanks the reply.
My other question is about cropping the skeleton. I'm follow the code from: https://gist.github.com/badlogic/a07a45c977c1d0b737f70c197aef5535 but I'm not sure how to set the size of the cropped region. I use FitViewport and here's my code:
override fun create() {
camera = OrthographicCamera()
viewport = FitViewport(WORLD_WIDTH, WORLD_HEIGHT, camera)
batch = PolygonSpriteBatch()
skin = Skin(Gdx.files.internal("ui/default_skin/uiskin.json"))
stage = Stage(viewport, batch)
Gdx.app.logLevel = Application.LOG_ERROR
Gdx.input.inputProcessor = stage
skeletonRenderer = SkeletonRenderer()
skeletonRenderer.premultipliedAlpha = true
val skeletonAtlas = TextureAtlas(Gdx.files.internal("game/humans/human.atlas"))
val skeletonJson = SkeletonJson(skeletonAtlas)
val skeletonData = skeletonJson.readSkeletonData(Gdx.files.internal("game/humans/human.json"))
skeleton = Skeleton(skeletonData).apply {
setPosition(250f,50f)
}
animationStateData = AnimationStateData(skeletonData)
animationState = AnimationState(animationStateData)
fbo = FrameBuffer(Pixmap.Format.RGBA8888, 512, 512, false)
fboRegion = TextureRegion(fbo.colorBufferTexture)
}
override fun render() {
Gdx.gl.glClearColor(0f, 0f, 0f, 1f)
Gdx.gl.glClear(GL20.GL_COLOR_BUFFER_BIT)
viewport.apply()
stage.act()
stage.draw()
skeleton.updateWorldTransform()
if (Gdx.input.isKeyJustPressed(Input.Keys.SPACE)) {
useFbo = !useFbo;
}
if (useFbo) {
fbo.begin();
Gdx.gl.glClearColor(0f, 0f, 0f, 0f);
Gdx.gl.glClear(GL20.GL_COLOR_BUFFER_BIT);
batch.projectionMatrix = camera.combined
batch.begin()
skeletonRenderer.draw(batch, skeleton)
batch.end()
fbo.end()
// Render FBO color buffer texture to screen
batch.projectionMatrix = camera.combined
batch.begin();
batch.draw(fboRegion, skeleton.x,skeleton.y);
batch.end();
}
else {
batch.begin()
skeletonRenderer.draw(batch, skeleton)
batch.end()
}
}
override fun resize(width: Int, height: Int) {
super.resize(width, height)
viewport.update(width, height, true)
}
When I press SPACE to draw the cropped region, my skeleton changes its width to about half and it moves slightly to the top right for some reason.