Inflearn brand logo image

Inflearn Community Q&A

smart38000171's profile image
smart38000171

asked

Creating a 2D Match Game with Godo Engine

Adjusting the position of the first card

error

Written on

·

16

0

Invalid assignment of property or key 'global_position_x' with value of type 'int' on a base object of type 'Area2D (card.gd)'.

다운 받은 소스를 실행 하면 잘 되는데,

처음부터 한단계씩 입력하다가, create_card() 부분에서 error 가 뜹니다.

func create_card():

for x_pos in COL:

for y_pos in ROW:

#print("%d,%d" % [x_pos,y_pos])

var new_card = card_scene.instantiate()

new_card.global_position_x = x_pos

new_card.global_position_y = y_pos

add_child(new_card)

game-enginegodot-enginegdscriptgame-programming

Answer 2

0

smart38000171님의 프로필 이미지
smart38000171
Questioner

이론,, . 답을 찿았습니다. 제 오타입니다

0

안녕하세요, 인프런 AI 인턴입니다.

andrew님께서 언급하신 오류는 global_position_xglobal_position_y와 관련이 있는 것으로 보입니다. Godot 엔진에서 global_position은 하나의 Vector2 값을 사용하여 처리해야 하며, 개별적으로 global_position_x 또는 global_position_y와 같은 속성을 직접 설정할 수 없습니다. 대신, 전체 global_position에 대해 값을 설정할 수 있습니다.

다음과 같이 수정해 보세요:

func create_card():
    for x_pos in COL:
        for y_pos in ROW:
            var new_card = card_scene.instantiate()
            new_card.global_position = Vector2(x_pos, y_pos)
            add_child(new_card)

이렇게 수정하면 각각의 카드가 global_position 속성을 통해 올바른 위치에 생성됩니다.

관련하여 도움이 될 만한 게시글을 함께 참고하시면 좋겠습니다:
- Godot Engine에서 글로벌 포지션 설정 관련 FAQ

저는 질문자님의 이해를 돕고자 지식공유자님의 기존 답변을 참고하여 유사한 답변 링크를 추천해드리고 있습니다.
현재 베타 기능으로 답변이 만족스럽지 않을 수 있는 점 양해 부탁드립니다. 🙏
추가적으로 궁금한 점이 있으시면, 이어서 질문해 주세요. 곧 지식공유자께서 답변해 주실 것입니다.

smart38000171's profile image
smart38000171

asked

Ask a question