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:04] – [Getting started] 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\\ {{ : | ||
| - | | + | ==== First Script |
| + | Version 1.0 | ||
| <codedoc code: | <codedoc code: | ||
| extends KinematicBody2D | extends KinematicBody2D | ||
| Zeile 22: | Zeile 24: | ||
| var velocity = Vector2() | var velocity = Vector2() | ||
| + | func _physics_process(delta): | ||
| + | if Input.is_action_pressed(" | ||
| + | velocity.x = 30 | ||
| + | |||
| + | move_and_slide(velocity) | ||
| + | </ | ||
| + | Version 1.1 | ||
| + | <codedoc code: | ||
| + | extends KinematicBody2D | ||
| + | var velocity = Vector2() | ||
| + | |||
| func _physics_process(delta): | func _physics_process(delta): | ||
| if Input.is_action_pressed(" | if Input.is_action_pressed(" | ||
| velocity.x = 30 | velocity.x = 30 | ||
| + | elif Input.is_action_pressed(" | ||
| + | velocity.x = -30 | ||
| + | else: | ||
| + | velocity.x = 0 | ||
| + | |||
| + | move_and_slide(velocity) | ||
| + | </ | ||
| + | Version 1.2 - links, rechts, stop | ||
| + | <codedoc code: | ||
| + | extends KinematicBody2D | ||
| + | |||
| + | var velocity = Vector2() | ||
| + | |||
| + | func _physics_process(delta): | ||
| + | if Input.is_action_pressed(" | ||
| + | velocity.x = 30 | ||
| + | elif Input.is_action_pressed(" | ||
| + | velocity.x = -30 | ||
| + | else: | ||
| + | velocity.x = 0 | ||
| + | |||
| + | move_and_slide(velocity) | ||
| + | </ | ||
| + | Version 1.3 - alle Richtungen | ||
| + | <codedoc code: | ||
| + | extends KinematicBody2D | ||
| + | |||
| + | var velocity = Vector2() | ||
| + | |||
| + | func _physics_process(delta): | ||
| + | if Input.is_action_pressed(" | ||
| + | velocity.x = 30 | ||
| + | elif Input.is_action_pressed(" | ||
| + | velocity.x = -30 | ||
| + | else: | ||
| + | velocity.x = 0 | ||
| + | |||
| + | if Input.is_action_pressed(" | ||
| + | velocity.y = -30 | ||
| + | elif Input.is_action_pressed(" | ||
| + | velocity.y = 30 | ||
| + | else: | ||
| + | velocity.y = 0 | ||
| move_and_slide(velocity) | move_and_slide(velocity) | ||
| </ | </ | ||
| ===== Jumping and gravity ===== | ===== Jumping and gravity ===== | ||
| + | {{youtube> | ||
| + | Version 2.0 - Gravitation und Springen | ||
| + | <codedoc code: | ||
| + | extends KinematicBody2D | ||
| + | |||
| + | const SPEED = 60 | ||
| + | const GRAVITY = 10 | ||
| + | const JUMP_POWER = -250 | ||
| + | const UP_DIR = Vector2(0, -1) | ||
| + | |||
| + | var velocity = Vector2() | ||
| + | |||
| + | 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(" | ||
| + | velocity.y = JUMP_POWER | ||
| + | |||
| + | # velocity.y = velocity.y + GRAVITY | ||
| + | velocity.y += GRAVITY | ||
| + | |||
| + | 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 ===== | ||