Animations and the Tilemap are bugging

:information_source: Attention Topic was automatically imported from the old Question2Answer platform.
:bust_in_silhouette: Asked By mirage

Hello! Im glad to be here!
I’m new to game development and Godot.
Ive never programmed something before. So I did this simple scene, just a ball, with a walking animation, some simple ugly tiles and the possibility to jump.
When playing the game and also in the viewport of Godot the tiles sometimes disappear. The walking animation sometimes runs smooth, but most of the time only the first 3 frames are being played.
Instead of an idle-animation I used $AnimationPlayer.stop(), but when I stop walking (pressing right) sometimes the animation freezes but it doesnt swap back to the first frame. Same when jumping. I hope someone can help me :frowning:

My PlayerScript (Attached is a Camera 2D, an AnimationPlayer, a collisionshape2D (circle), and a sprite Node):

extends KinematicBody2D

const SPEED = 60
const GRAVITY = 400
const JUMP_POWER = 150
const UP_VECTOR = Vector2(0,-1)

var screen_size
var movement = Vector2()



func _ready():
	 screen_size = get_viewport_rect().size



func _process(delta):
	movement.x = 0
	
	
	
	if is_on_ceiling() or is_on_floor():
		movement.y = 0
		
	movement.y += GRAVITY * delta
	
	check_key_input()
	
	move_and_slide(movement, UP_VECTOR)
	
	set_animation()
	
	clampPlayertoScreen()
	

func clampPlayertoScreen():
	position.x = clamp(position.x, 0, screen_size.x)
	position.y = clamp(position.y, 0, screen_size.y)


func check_key_input():
		
	if Input.is_action_pressed("left"):
		movement.x = -1 * SPEED
	
	if Input.is_action_pressed("right"):
		movement.x = 1 * SPEED
		$AnimationPlayer.play("Run")
	
	if Input.is_action_just_pressed("jump") and is_on_floor():
			movement.y = -JUMP_POWER

func set_animation():
	if movement.x < 0:
		$sprite.flip_h = true
		$AnimationPlayer.play("Run")
	if movement.x > 0:
		$AnimationPlayer.play("Run")
		$sprite.flip_h = false
	if movement.x == 0:
		$AnimationPlayer.stop()
	if is_on_floor() == false:
		$AnimationPlayer.stop()