Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- override fun render(delta: Float) {
- Gdx.gl.glClear(GL20.GL_COLOR_BUFFER_BIT)
- actorManager.addNewActors(stage)
- viewPort.camera.update()
- stage.act(delta)
- stage.draw()
- world.step(delta, 8, 3)
- debugger.render(world, viewPort.camera.combined)
- }
- fun markToAdd(actor: BaseActor<*>) {
- toAdd.add(actor)
- }
- fun addNewActors(stage: Stage) {
- toAdd.forEach { actor: BaseActor<*> ->
- stage.addActor(actor)
- actor.addToWorld(worldService.getWorld())
- Gdx.app.log("afterAdd", (++charactersOnStage).toString())
- }
- toAdd.clear()
- }
- override fun draw(batch: Batch, parentAlpha: Float) {
- super.draw(batch, parentAlpha)
- if (isMoving) {
- frameStateTime += Gdx.graphics.deltaTime
- }
- // DRAW TEXTURE
- val frame = animationManager.getFrameAndChangeSpeed(AnimationType.KNIGHT_WALK_RIGHT, frameStateTime, getSpeed())
- val frameX: Float = position.x - (size.width / 2)
- val frameY: Float = position.y - (size.height / 2)
- batch.draw(frame, frameX, frameY, size.width, size.height)
- // END DRAW
- }
- override fun draw(batch: Batch, parentAlpha: Float) {
- super.draw(batch, parentAlpha)
- if (isMoving) {
- frameStateTime += Gdx.graphics.deltaTime
- }
- // DRAW TEXTURE
- val frame = animationManager.getFrameAndChangeSpeed(AnimationType.RAT_WALK_LEFT, frameStateTime, getSpeed())
- val frameX: Float = position.x - (size.width / 2)
- val frameY: Float = position.y - (size.height / 2)
- batch.draw(frame, frameX, frameY, size.width, size.height)
- // END DRAW
- }
- fun getAnimation(animationType: AnimationType): Animation<TextureRegion> {
- return AssetsManager.loadSprite(animationType.spriteFile, animationType.alias).getAnimationForSprite(animationType.alias, animationType.width, animationType.height)
- }
- fun getFrameAndChangeSpeed(animationType: AnimationType, stateTime: Float, speed: Float, looping: Boolean = true): TextureRegion {
- val animation = getAnimation(animationType)
- animation.frameDuration = 1 / speed
- return animation.getKeyFrame(stateTime, looping)
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement