Unterschiede
Hier werden die Unterschiede zwischen zwei Versionen angezeigt.
| Beide Seiten der vorigen Revision Vorhergehende Überarbeitung Nächste Überarbeitung | Vorhergehende Überarbeitung | ||
| tutorial:umaipixel-2dplatformer [2023/07/04 21:04] – [Character animation] 185.38.49.0 | tutorial:umaipixel-2dplatformer [2023/07/04 21:06] (aktuell) – [Character animation] 185.38.49.0 | ||
|---|---|---|---|
| Zeile 14: | Zeile 14: | ||
| * KinematicBody2D | * KinematicBody2D | ||
| * Sprite\\ Sprite Reimport mit Preset 2D Pixel\\ Sprite Einstellungen für CharacterMap | * Sprite\\ Sprite Reimport mit Preset 2D Pixel\\ Sprite Einstellungen für CharacterMap | ||
| + | * [[https:// | ||
| * CollisionsShape2D | * CollisionsShape2D | ||
| * Group Selected Nodes\\ {{ : | * Group Selected Nodes\\ {{ : | ||
| Zeile 155: | Zeile 156: | ||
| * run 5 Bilder | * run 5 Bilder | ||
| * [[https:// | * [[https:// | ||
| + | <codedoc code: | ||
| + | extends KinematicBody2D | ||
| + | |||
| + | const SPEED = 60 | ||
| + | const GRAVITY = 10 | ||
| + | const JUMP_POWER = -250 | ||
| + | const UP_DIR = Vector2(0, -1) | ||
| + | |||
| + | var velocity = Vector2() | ||
| + | var on_ground = false | ||
| + | |||
| + | func _physics_process(delta): | ||
| + | if Input.is_action_pressed(" | ||
| + | velocity.x = SPEED | ||
| + | $AnimatedSprite.play(" | ||
| + | $AnimatedSprite.flip_h = false | ||
| + | elif Input.is_action_pressed(" | ||
| + | velocity.x = -SPEED | ||
| + | $AnimatedSprite.play(" | ||
| + | $AnimatedSprite.flip_h = true | ||
| + | else: | ||
| + | velocity.x = 0 | ||
| + | if on_ground: | ||
| + | $AnimatedSprite.play(" | ||
| + | |||
| + | if Input.is_action_pressed(" | ||
| + | if on_ground == true: | ||
| + | velocity.y = JUMP_POWER | ||
| + | on_ground = false | ||
| + | $AnimatedSprite.play(" | ||
| + | |||
| + | # velocity.y = velocity.y + GRAVITY | ||
| + | velocity.y += GRAVITY | ||
| + | |||
| + | if is_on_floor(): | ||
| + | on_ground = true | ||
| + | else: | ||
| + | on_ground = false | ||
| + | if velocity.y < 0: | ||
| + | $AnimatedSprite.play(" | ||
| + | else: | ||
| + | $AnimatedSprite.play(" | ||
| + | |||
| + | velocity = move_and_slide(velocity, | ||
| + | </ | ||
| ===== Fireball alright! ===== | ===== Fireball alright! ===== | ||
| ===== Fireball alright and left ===== | ===== Fireball alright and left ===== | ||