Love2dCS
Love2dCS copied to clipboard
having trouble with graphics.push() and graphics.pop()
so I am having weird issues where graphics.push() and graphics.pop() doesn't seem to be working quite right.
it seems that the popping may not be working.
it might be a oversight on my end but I am getting this..
here is a example of my code..
public class Widget
{
//Child Widgets
protected Widget Parent { get; private set; }
protected Dictionary<string, Widget> Children { get; private set; } = new Dictionary<string, Widget>();
//Properties
public bool Visable { get; set; } = true;
public string Name { get; set; } = "";
public int X { get; set; } = 0;
public int Y { get; set; } = 0;
public int W { get; set; } = 0;
public int H { get; set; } = 0;
//Callers
public Widget()
{
OnCreate();
}
public void Update()
{
OnUpdate();
foreach (var c in Children.Values)
{
c.Update();
}
}
public void Render()
{
OnRender();
Graphics.Push();
Graphics.Translate(X, Y);
Graphics.SetScissor(X, Y, W, H);
foreach (var c in Children.Values)
{
c.Render();
}
Graphics.Pop();
}
//Events
protected virtual void OnCreate()
{
W = Love.Graphics.GetWidth();
H = Love.Graphics.GetHeight();
}
protected virtual void OnUpdate()
{
W = Love.Graphics.GetWidth();
H = Love.Graphics.GetHeight();
}
protected virtual void OnRender()
{
Graphics.Clear(0, 0, 0);
}
here is a example of my project https://drive.google.com/open?id=1fpy0Q-E3aKibt7ffaRt7CxL1LHsMQ2LO
currently solution is add Graphics.SetScissor()
before your call Graphics.Pop()
, it just like :
{
OnRender();
Graphics.Push();
Graphics.Translate(X, Y);
Graphics.SetScissor(X, Y, W, H);
foreach (var c in Children.Values)
{
c.Render();
}
Graphics.SetScissor(); // disable scissor here !
Graphics.Pop();
}
it was work fine now (i try add another winow in MainWindow
, real Interesting widget)
At present, I am not sure whether the scissor should be disable with pop or should be called manually. I think I have to write an example with the official version.
ok thankyou so much! I was looking at the lua love2d wiki and it used push() before the graphics state changes.