tutorial:umaipixel-2dplatformer

Godot 3 - Platformer Tutorial (UmaiPixel)

  • Projekt erstellen
  • Einstellungen (Project Settings)
    • Rendering | 2D | Use GPU Pixel Snap = on
    • Display | Window | Size (16:9) z.B. 320 x 180
    • Test Width & Height = 1280 x 720 (vier mal Originalgröße)
    • Stretch Mode = 2d
    • Aspect = keep
  • erste Szene erstellen
    • Hauptszene erstellen (Node2D) und speichern
  • Playerszene erstellen
    • KinematicBody2D
    • Sprite
      Sprite Reimport mit Preset 2D Pixel
      Sprite Einstellungen für CharacterMap
    • CollisionsShape2D
    • Group Selected Nodes

Version 1.0

extends KinematicBody2D
 
var velocity = Vector2()
 
func _physics_process(delta):
	if Input.is_action_pressed(„ui_right“):
		velocity.x = 30
 
	move_and_slide(velocity)

Version 1.1

extends KinematicBody2D
 
var velocity = Vector2()
 
func _physics_process(delta):
	if Input.is_action_pressed(„ui_right“):
		velocity.x = 30
	elif Input.is_action_pressed(„ui_left“):
		velocity.x = -30
	else:
		velocity.x = 0
 
	move_and_slide(velocity)

Version 1.2 - links, rechts, stop

extends KinematicBody2D
 
var velocity = Vector2()
 
func _physics_process(delta):
	if Input.is_action_pressed(„ui_right“):
		velocity.x = 30
	elif Input.is_action_pressed(„ui_left“):
		velocity.x = -30
	else:
		velocity.x = 0
 
	move_and_slide(velocity)

Version 1.3 - alle Richtungen

extends KinematicBody2D
 
var velocity = Vector2()
 
func _physics_process(delta):
	if Input.is_action_pressed(„ui_right“):
		velocity.x = 30
	elif Input.is_action_pressed(„ui_left“):
		velocity.x = -30
	else:
		velocity.x = 0
 
	if Input.is_action_pressed(„ui_up“):
		velocity.y = -30
	elif Input.is_action_pressed(„ui_down“):
		velocity.y = 30
	else:
		velocity.y = 0
 
	move_and_slide(velocity)


Version 2.0 - Gravitation und Springen

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(„ui_right“):
		velocity.x = SPEED
	elif Input.is_action_pressed(„ui_left“):
		velocity.x = -SPEED
	else:
		velocity.x = 0
 
	if Input.is_action_pressed(„ui_up“):
		velocity.y = JUMP_POWER
 
	# velocity.y = velocity.y + GRAVITY
	velocity.y += GRAVITY
 
	velocity = move_and_slide(velocity, UP_DIR)

Version 2.1 - jump on ground

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(„ui_right“):
		velocity.x = SPEED
	elif Input.is_action_pressed(„ui_left“):
		velocity.x = -SPEED
	else:
		velocity.x = 0
 
	if Input.is_action_pressed(„ui_up“):
		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, UP_DIR)
  • Sprite durch AnimatedSprite ersetzen
  • Animationen anlegen
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(„ui_right“):
		velocity.x = SPEED
		$AnimatedSprite.play(„run “)
		$AnimatedSprite.flip_h = false
	elif Input.is_action_pressed(„ui_left“):
		velocity.x = -SPEED
		$AnimatedSprite.play(„run “)
		$AnimatedSprite.flip_h = true
	else:
		velocity.x = 0
		if on_ground:
			$AnimatedSprite.play(„idle“)
 
	if Input.is_action_pressed(„ui_up“):
		if on_ground == true:
			velocity.y = JUMP_POWER
			on_ground = false
			$AnimatedSprite.play(„jump“)
 
	# 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(„jump“)
		else:
			$AnimatedSprite.play(„fall“)
 
	velocity = move_and_slide(velocity, UP_DIR)
  • tutorial/umaipixel-2dplatformer.txt
  • Zuletzt geändert: 2023/07/04 21:06
  • von 185.38.49.0