Advertisement
Guest User

Untitled

a guest
Jun 20th, 2019
92
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.08 KB | None | 0 0
  1. override fun render(delta: Float) {
  2. Gdx.gl.glClear(GL20.GL_COLOR_BUFFER_BIT)
  3.  
  4. actorManager.addNewActors(stage)
  5.  
  6. viewPort.camera.update()
  7.  
  8. stage.act(delta)
  9. stage.draw()
  10.  
  11. world.step(delta, 8, 3)
  12. debugger.render(world, viewPort.camera.combined)
  13. }
  14.  
  15. fun markToAdd(actor: BaseActor<*>) {
  16. toAdd.add(actor)
  17. }
  18.  
  19. fun addNewActors(stage: Stage) {
  20. toAdd.forEach { actor: BaseActor<*> ->
  21. stage.addActor(actor)
  22. actor.addToWorld(worldService.getWorld())
  23. Gdx.app.log("afterAdd", (++charactersOnStage).toString())
  24. }
  25. toAdd.clear()
  26. }
  27.  
  28. override fun draw(batch: Batch, parentAlpha: Float) {
  29. super.draw(batch, parentAlpha)
  30.  
  31. if (isMoving) {
  32. frameStateTime += Gdx.graphics.deltaTime
  33. }
  34.  
  35. // DRAW TEXTURE
  36. val frame = animationManager.getFrameAndChangeSpeed(AnimationType.KNIGHT_WALK_RIGHT, frameStateTime, getSpeed())
  37. val frameX: Float = position.x - (size.width / 2)
  38. val frameY: Float = position.y - (size.height / 2)
  39.  
  40. batch.draw(frame, frameX, frameY, size.width, size.height)
  41.  
  42. // END DRAW
  43. }
  44.  
  45. override fun draw(batch: Batch, parentAlpha: Float) {
  46. super.draw(batch, parentAlpha)
  47.  
  48. if (isMoving) {
  49. frameStateTime += Gdx.graphics.deltaTime
  50. }
  51.  
  52. // DRAW TEXTURE
  53. val frame = animationManager.getFrameAndChangeSpeed(AnimationType.RAT_WALK_LEFT, frameStateTime, getSpeed())
  54. val frameX: Float = position.x - (size.width / 2)
  55. val frameY: Float = position.y - (size.height / 2)
  56.  
  57. batch.draw(frame, frameX, frameY, size.width, size.height)
  58.  
  59. // END DRAW
  60. }
  61.  
  62. fun getAnimation(animationType: AnimationType): Animation<TextureRegion> {
  63. return AssetsManager.loadSprite(animationType.spriteFile, animationType.alias).getAnimationForSprite(animationType.alias, animationType.width, animationType.height)
  64. }
  65. fun getFrameAndChangeSpeed(animationType: AnimationType, stateTime: Float, speed: Float, looping: Boolean = true): TextureRegion {
  66. val animation = getAnimation(animationType)
  67. animation.frameDuration = 1 / speed
  68. return animation.getKeyFrame(stateTime, looping)
  69. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement