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 08:53] – [Jumping and gravity] 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 86: | Zeile 87: | ||
| ===== Jumping and gravity ===== | ===== Jumping and gravity ===== | ||
| {{youtube> | {{youtube> | ||
| - | Version 2.0 | + | Version 2.0 - Gravitation und Springen |
| <codedoc code: | <codedoc code: | ||
| extends KinematicBody2D | extends KinematicBody2D | ||
| Zeile 93: | Zeile 94: | ||
| const GRAVITY = 10 | const GRAVITY = 10 | ||
| const JUMP_POWER = -250 | const JUMP_POWER = -250 | ||
| - | const FLOOR = Vector2(0, -1) | + | const UP_DIR |
| var velocity = Vector2() | var velocity = Vector2() | ||
| Zeile 111: | Zeile 112: | ||
| velocity.y += GRAVITY | velocity.y += GRAVITY | ||
| - | velocity = move_and_slide(velocity, | + | velocity = move_and_slide(velocity, |
| + | </ | ||
| + | Version 2.1 - jump on ground | ||
| + | <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 | ||
| + | elif Input.is_action_pressed(" | ||
| + | velocity.x = -SPEED | ||
| + | else: | ||
| + | velocity.x = 0 | ||
| + | |||
| + | if Input.is_action_pressed(" | ||
| + | if on_ground == true: | ||
| + | velocity.y = JUMP_POWER | ||
| + | on_ground = false | ||
| + | |||
| + | # velocity.y = velocity.y + GRAVITY | ||
| + | velocity.y += GRAVITY | ||
| + | |||
| + | if is_on_floor(): | ||
| + | on_ground = true | ||
| + | else: | ||
| + | on_ground = false | ||
| + | |||
| + | velocity = move_and_slide(velocity, | ||
| </ | </ | ||
| ===== Tilsets and Tilemaps ===== | ===== Tilsets and Tilemaps ===== | ||
| ===== Character animation ===== | ===== Character animation ===== | ||
| + | * Sprite durch AnimatedSprite ersetzen | ||
| + | * Animationen anlegen | ||
| + | * fall, idle, jump jweils ein Bild, Speed = 0 FPS, Loop = false | ||
| + | * run 5 Bilder | ||
| + | * [[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 ===== | ||