[windows] .graphics issues with lines and removeChild - openFL 8.6.4

Hi, stumbled into this while using stablexui for my game’s UI : it looks perfect on flash but blurry on windows target.

Also on windows there is a similar issue to the one I posted about recently with text disappearing : same thing but with sprite.graphics this time :slight_smile:

I put up a very simple demo, here is how it looks on flash :

and here is the windows one :

on the windows one the line is 2 pixels thick instead of one and looks blurry. It also “adds” with the fill color and with itself on corners.

Here is a zoomed (3x) version of display in flash :

and the same thing for windows :

I don’t know, maybe that’s just how it works when on windows target ? Let me know. I think I can do things differently if I need to.

the graphics disappearing after a removeChild and adding it back is clearly a bug though :slight_smile:

Here is the code to reproduce :

package;

import openfl.display.Sprite;
import openfl.Lib;
import openfl.events.MouseEvent;
import openfl.text.TextField;

/**
 * ...
 * @author Matse
 */
class Main extends Sprite 
{
	private var _container:Sprite;
	
	public function new() 
	{
		super();
		
		// Assets:
		// openfl.Assets.getBitmapData("img/assetname.jpg");
		
		_container = new Sprite();
		addChild(_container);
		
		var sprite:Sprite = new Sprite();
		sprite.graphics.lineStyle(1, 0xa32a23, 1);
		sprite.graphics.drawRect(0, 0, 100, 100);
		sprite.x = 250;
		sprite.y = 150;
		_container.addChild(sprite);
		
		sprite = new Sprite();
		sprite.graphics.beginFill(0x333333, 1);
		sprite.graphics.lineStyle(1, 0xa32a23, 1);
		sprite.graphics.drawRect(0, 0, 100, 100);
		sprite.graphics.endFill();
		sprite.x = 450;
		sprite.y = 150;
		_container.addChild(sprite);
		
		stage.addEventListener(MouseEvent.MOUSE_UP, onClick);
	}
	
	/**
	   
	   @param	evt
	**/
	private function onClick(evt:MouseEvent):Void
	{
		if (_container.parent == null)
		{
			addChild(_container);
		}
		else
		{
			removeChild(_container);
		}
	}

}

Thanks !

There’s some more discussion (and a possible fix) here:

I’m not sure of the exact logic we’d need to make it sharp in the exact right situations, but I think it would mostly consist of adding (or subtracting) 0.5 to coordinates

Thanks, you’re right : I had a few UI elements that were on .5 coords and those displayed sharp lines. Tried with my simple demo too and all lines became sharp.

The explanations make sense too, not sure how openFL could “fix” this for every situation. For now I’ll just try some “#if cpp” in stablexui skins and see if it works for me, I want everything on integer coords so it should work.

I realize my post was confusing now that I read it again : there is another issue, introduced with one of the latest openFL release.

If you have a sprite with .graphics content it displays fine the first time you addChild it, but if you then removeChild it and then addChild it again the .graphics display is gone.

It looks a lot like what I reported about text some time ago that you fixed very quickly.

Is there a way you could try coming up with a small amount of sample code that reproduces the second problem you are experiencing? Also, does using -Dopenfl-always-render fix it?

Using -Dopenfl-always-render fixes the issue yes. I also tried with openFL 8.6.2 and it doesn’t have this issue.

Here is a smaller sample code : just click to removeChild the sprite from stage and click again to addChild it.

package;

import openfl.display.Sprite;
import openfl.events.MouseEvent;

/**
 * ...
 * @author Matse
 */
class Main extends Sprite 
{
	private var _container:Sprite;
	
	public function new() 
	{
		super();
		
		// Assets:
		// openfl.Assets.getBitmapData("img/assetname.jpg");
		
		_container = new Sprite();
		_container.graphics.beginFill(0xa32a23, 1);
		_container.graphics.drawRect(0, 0, 100, 100);
		_container.x = 350;
		_container.y = 150;
		addChild(_container);
		
		stage.addEventListener(MouseEvent.MOUSE_UP, onClick);
	}
	
	/**
	   
	   @param	evt
	**/
	private function onClick(evt:MouseEvent):Void
	{
		if (_container.parent == null)
		{
			addChild(_container);
		}
		else
		{
			removeChild(_container);
		}
	}

}

Thanks for the sample! Yes, this is fixed in the dev branches of OpenFL and Lime, so it should be resolved for the next release :slight_smile:

1 Like