Godot:CanvasItem
Base class of anything 2D.
GDScript Methods
void | |
void | |
float | |
void | |
void | |
void | |
void | |
void | |
void | |
void | |
void | |
void | |
void | |
void | |
void | |
void | |
void | |
void | |
void | |
void | |
void | |
void | |
void | |
RID | |
RID | |
Transform2D | |
| |
Transform2D | |
Transform2D | |
| |
Transform2D | |
Rect2 | |
Transform2D | |
World2D | |
void | |
bool | |
bool | |
bool | |
bool | |
| |
| |
void | |
void | |
void | |
void | |
void | |
draw_string
그려질 텍스트의 영역 계산 방법
Godot:Font#get_string_size 함수를 사용하면 된다.
draw_polyline
WARNING |
작동 방식으로 인해 내장된 앤티앨리어싱은 반투명 폴리곤에 대해 올바르게 보이지 않으며 특정 플랫폼에서 작동하지 않을 수 있습니다. 이 문제를 해결하려면 Antialiased Line2D 추가 기능을 설치한 다음 AntialiasedPolygon2D 노드를 만드십시오. 해당 노드는 앤티앨리어싱을 수행하기 위해 사용자 정의 밉맵이 있는 텍스처에 의존합니다. |
Line Connection 이슈
문서의 설명상으론 라인이 연결되어 있다 하지만 그렇지 않더라... 그래서 발생되는 Line Connection 이슈가 있다.
Hexagon 을 그릴 시 다음과 같이 그린다.
float COS30 = (float)Math.Sqrt(3f) / 2f;
float SIN30 = 0.5f;
var r = radius;
var x = COS30 * radius;
var y = SIN30 * radius;
var cx = center.x;
var cy = center.y;
var points = new List<Vector2>();
points.Add(new Vector2(cx + 0, cy - r)); // 12시
points.Add(new Vector2(cx + x, cy - y)); // 1시30분
points.Add(new Vector2(cx + x, cy + y)); // 4시30분
points.Add(new Vector2(cx + 0, cy + r)); // 6시
points.Add(new Vector2(cx - x, cy + y)); // 7시30분
points.Add(new Vector2(cx - x, cy - y)); // 10시30분
points.Add(new Vector2(cx + 0, cy - r)); // 12시
이 때, 선의 너비를 1보다 크게 하면 다음 그림과 같이 연결된 선이 부자연스럽게 보여진다. (12시 방향 꼭지점 연결 부분이 파여져 있는게 보일 것이다)
Godot_draw_polyline_lineWidth_issue_01.png
그래서 12시 방향 꼭지점 이후, 1시30분 방향 꼭지점 까지 추가 선을 연결하면
points.Add(new Vector2(cx + 0, cy - r)); // 12시
points.Add(new Vector2(cx + x, cy - y)); // 1시30분
points.Add(new Vector2(cx + x, cy + y)); // 4시30분
points.Add(new Vector2(cx + 0, cy + r)); // 6시
points.Add(new Vector2(cx - x, cy + y)); // 7시30분
points.Add(new Vector2(cx - x, cy - y)); // 10시30분
points.Add(new Vector2(cx + 0, cy - r)); // 12시
points.Add(new Vector2(cx + x, cy - y)); // 1시30분
다음과 같이 보인다:
Godot_draw_polyline_lineWidth_issue_02.png
얼핏 보면 잘 그려진듯 하지만 확대하면 이상한 점을 볼 수 있다.
Godot_draw_polyline_lineWidth_issue_03.png
1시30분 방향 꼭지점 부터 그려도 동일한 현상이 나타난다.
points.Add(new Vector2(cx + x, cy - y)); // 1시30분
points.Add(new Vector2(cx + x, cy + y)); // 4시30분
points.Add(new Vector2(cx + 0, cy + r)); // 6시
points.Add(new Vector2(cx - x, cy + y)); // 7시30분
points.Add(new Vector2(cx - x, cy - y)); // 10시30분
points.Add(new Vector2(cx + 0, cy - r)); // 12시
points.Add(new Vector2(cx + x, cy - y)); // 1시30분
Godot_draw_polyline_lineWidth_issue_04.png
이 현상은 1 초과의 선 두께를 "사각형 도형"의 연결로 표현해서 발생되는 이슈로 보인다.
Godot_draw_polyline_lineWidth_issue_06.png
따라서 두께 변화가 없는 직선 구간, 즉 3시 방향에 점을 추가하여 그린다:
Godot_draw_polyline_lineWidth_issue_05.png
var points = new List<Vector2>();
// points.Add(new Vector2(cx + 0, cy - r)); // 12시
// points.Add(new Vector2(cx + x, cy - y)); // 1시30분
points.Add(new Vector2(cx + x, cy)); // 3시
points.Add(new Vector2(cx + x, cy + y)); // 4시30분
points.Add(new Vector2(cx + 0, cy + r)); // 6시
points.Add(new Vector2(cx - x, cy + y)); // 7시30분
points.Add(new Vector2(cx - x, cy - y)); // 10시30분
points.Add(new Vector2(cx + 0, cy - r)); // 12시
points.Add(new Vector2(cx + x, cy - y)); // 1시30분
points.Add(new Vector2(cx + x, cy)); // 3시
See also
- Godot
- Godot:CustomDrawing
- Hexagon#Godot - Godot 의 커스텀 드로잉으로 정육면체 그리는 방법 설명.