added dynamic resolution
This commit is contained in:
@@ -3,12 +3,15 @@ using Godot;
|
||||
|
||||
public partial class Main : Node2D {
|
||||
[Export] public int BrushSize = 5;
|
||||
[Export] public float TextureResolution = 0.5f;
|
||||
|
||||
private TextureRect mLevelDrawer;
|
||||
private Level mLevel;
|
||||
|
||||
public override void _Ready() {
|
||||
mLevel = new Level((int)GetViewportRect().Size.X, (int)GetViewportRect().Size.Y);
|
||||
mLevel = new Level((int)(GetViewportRect().Size.X * TextureResolution),
|
||||
(int)(GetViewportRect().Size.Y * TextureResolution)
|
||||
);
|
||||
mLevelDrawer = GetNode<TextureRect>("CanvasLayer/LevelDrawer");
|
||||
}
|
||||
|
||||
@@ -22,7 +25,11 @@ public partial class Main : Node2D {
|
||||
if (@event is InputEventMouseButton eventMouseButton) {
|
||||
|
||||
Vector2 mouse = GetViewport().GetMousePosition();
|
||||
mLevel.WritePixel((int)mouse.X, (int)mouse.Y, BrushSize);
|
||||
|
||||
float mappedX = mouse.X / GetViewportRect().Size.X * mLevel.SizeX;
|
||||
float mappedY = mouse.Y / GetViewportRect().Size.Y * mLevel.SizeY;
|
||||
|
||||
mLevel.WritePixel((int)mappedX, (int)mappedY, BrushSize);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user