help
Root Question Message
bool shouldDrawBlock = false;
void OnMouseButtonDown() // ur button click handler
{
shouldDrawBlock = true;
}
void Render() // ur render method
{
if (shouldDrawBlock)
{
drawBlock();
}
}
shouldDrawBlock = !shouldDrawBlock;
in the button click handlershouldDrawBlock
is a local variable instead of a member of ur classpublic abstract class GameObject
{
public bool IsVisible { get; set; } = true;
public abstract void Draw();
}
public class Game
{
private readonly List<GameObject> _objects = new(); // fill with some actual objects
public void OnMouseClick()
{
GameObject gameObject = GetGameObjectFromMouseCoordsOrSomething();
gameObject.IsVisible = !gameObject.IsVisible;
}
public void Draw()
{
foreach (var gameObject in _objects)
{
if (gameObject.IsVisible)
{
gameObject.Draw();
}
}
}
}
GameObject
and be stored in Game._objects
GetGameObjectFromMouseCoordsOrSomething();
part is for the obj pos right?Ground
tile u clicked on// update state
if (Raylib.IsMouseButtonPressed(MouseButton.MOUSE_BUTTON_LEFT))
{
var pos = Raylib.GetMousePosition();
foreach (var obj in _objects)
{
if (/*check if pos is inside of the tile boundaries*/)
{
obj.IsVisible = !tile.IsVisible;
break;
}
}
}
// render scene
foreach (var obj in _objects)
{
if (obj.IsVisible)
{
obj.Draw();
}
}
if (Raylib.IsMouseButtonPressed(MouseButton.MOUSE_BUTTON_LEFT))
could cause some flickering, then u would have to write some mechanic to only trigger it on actual changespublic class ObservableValue<T>
{
private T _value;
public ObservableValue(T initialValue)
{
_value = initialValue;
}
public T Value
{
get => _value;
set
{
if (value is null)
{
if (_value is null) return;
}
else if (value.Equals(_value))
{
return;
}
var oldValue = _value;
_value = value;
OnChange?.Invoke(oldValue, value);
}
}
public event Action<T, T>? OnChange;
}
Sign In and Join Server To See
Sign In and Join Server To See
IsVisble
, then ya can simple add the new block to object list before renderingif (Raylib.IsMouseButtonPressed(MouseButton.MOUSE_BUTTON_LEFT))
{
_objects.Add(new Block {
Position = Raylib.GetMousePosition()
});
}
Sign In and Join Server To See
Sign In and Join Server To See
public void Draw()
{
foreach (var gameObject in _objects)
{
gameObject.Draw();
}
}
to draw all ur entities._objects
list, it will be rendered on the next frame