Notice
Recent Posts
Recent Comments
| 일 | 월 | 화 | 수 | 목 | 금 | 토 |
|---|---|---|---|---|---|---|
| 1 | 2 | 3 | ||||
| 4 | 5 | 6 | 7 | 8 | 9 | 10 |
| 11 | 12 | 13 | 14 | 15 | 16 | 17 |
| 18 | 19 | 20 | 21 | 22 | 23 | 24 |
| 25 | 26 | 27 | 28 | 29 | 30 | 31 |
Tags
- C
- rubymine
- boj
- gnuplot
- ruby
- Spring
- Python
- Godot
- IntelliJ
- Baekjoon
- GitHub
- maven
- plugin
- 개발노트
- JS
- 루비
- RaspberryPi
- Android
- CPP
- Vane
- OAuth
- gradle
- Shell
- jetbrains
- kotlin
- ruby2d
- Java
- OTLanguage
- error
- react
Archives
- Today
- Total
PersesTitan(페르) 기술블로그
[GDScript] 캐릭터 이동 구현 본문
첫 프로젝트 생성
Area2D 추가 -> Area2D 이름 변경(Player) -> AnimatedSprite, CollisionShape2D를 추가


Script
Player -> 인스팩터 -> Script -> 새 스크립트
extends Area2D
export var speed: int
var screensize
func _ready():
screensize = get_viewport_rect().size
pass
func _process(delta):
var p = Vector2()
if Input.is_action_pressed("ui_right"):
p.x += 1
if Input.is_action_pressed("ui_left"):
p.x -= 1
if Input.is_action_pressed("ui_down"):
p.y += 1
if Input.is_action_pressed("ui_up"):
p.y -= 1
if p.length() > 0:
p = p.normalized() * speed
$AnimatedSprite.play()
else:
$AnimatedSprite.stop()
position += p * delta
position.x = clamp(position.x, 0, screensize.x)
position.y = clamp(position.y, 0, screensize.y)
동작

'Language > GDScript' 카테고리의 다른 글
| [GDScript] clamp() 메소드 (0) | 2023.04.19 |
|---|