Novice learning 'Starling' discussion

I think I should premise this, with expressing that I think it is important that you develop your own style and approach to coding.

I offer you my thoughts, sometimes with a degree of persuasiveness, but I believe it’s important that you pick and choose and weigh up what is also going to work well for you, and what makes sense to you. So what I offer here now is merely something to consider, and is not intended as “the way you should be doing it”.

You’re right, that one approach is to use a loop to switch off all MovieClips before activating the new one. I don’t think that will incur much overhead, but for argument sake, let’s say that was a problem, and some more precise logic is needed.

(I’ve not tested the below code, I just wrote it in notepad, so treat it as something like psuedocode, expressing the idea)

public var currentMC:MovieClip;

public function goState(state:String):Void {
    if (currentMC != null) {
        currentMC.stop();
        currentMC.visible = false;
        Starling.current.juggler.remove(currentMC);
    }
    
    switch(state) {
        case "walk":
            currentMC = walkMC;
        case "jump":
            currentMC = jumpMC;
        default:
            currentMC = idleMC;
    }
    
    Starling.current.juggler.add(currentMC);
    currentMC.visible = true;
    currentMC.play();
}

The above method selectively works only with the active MovieClip (disabling it), then playing the MovieClip to be activated. It assumes you have a state mechanism of some sort set up so the correct movieClip plays at the appropriate time.

如果使用一个“mc”来制作动画,需要自己实现播放某一段动画的逻辑,如果使用多个“mc”视乎方便一些。嗯,好吧!那就使用多个“mc”动画吧。

关于“ATF”纹理,我是使用“TexturePackerGUI”导出的啊,你之前介绍我使用的工具。
我使用“TexturePackerGUI”导出了“ATF”纹理,但是发布目标后,没有显示任何的内容,我不知道是不是我导出的问题,还是“ATF”纹理不支持全部的目标?

我想问一下,关于文字,我玩过一些手机端游戏,发现这些游戏界面的字体很小,非常小的文字,但是显示的很清晰,是怎么做到的?

“starling”会把文字转成纹理,这样缩小的文字是不是在清晰度和精致上不如矢量图文字效果好?

我希望显示很小的文字也显示非常清晰和精致

对了,您上次反馈的“TexturePackerGUI”,不支持锚点注册点的问题,“TexturePackerGUI”方面是否同意会在后续版本为“starling”添加锚点注册点的支持?

几天前,我看到“vscode”上的“as3”插件更新了,这很好啊,虽然我目前使用“openfl”但是偶尔我也使用“as3”制作一些工具。

1 Like

Ok, I had some success translating this using deepl.com. I suspect the font used on the forum doesn’t support the Chinese characters, so it’s not rendering here.


The settings you used in TexturePacker are important, as well as the target you’re using with OpenFL, and the platform / computer / device / browser you’re running it in. Knowing these things will hopefully provide some pointers for troubleshooting.


Vector text in OpenFL / Flash / AIR, is rasterised and displayed. So whilst the source is vector, it is ultimately displayed as raster.

With Starling, the text is essentially pre-rasterised which has significant performance benefits for text that is updated frequently.

I anticipate you have quite a number of options here, still. Understanding what you’re trying to do, like some visual mock-ups, might help us hone in on some of those. For example:

  • You can export size specific bitmap fonts, so you don’t need to scale them.
  • You can use distance field fonts, that scale better.
  • You can use OpenFL textfields (vector!), as this will display on top of Starling, just be aware of performance implications if you’re updating that text a lot.

I have had very positive communications with the TexturePacker team, and we currently have two likely outcomes:

  • They are entertaining the idea of officially adding pivot point support to the Sparrow / Starling exporter.
  • I have also produced a custom Sparrow / Starling exporter for TexturePacker that has pivot point support, but I still need to test and refine this more before sharing.

I would add as a caveat, as this would be for use with the latest version of TexturePacker, I’m leveraging the KTX format, not ATF, but I have that working in all my testing with new KTX code I’m working on. I’m still refining the code structure of that, to bring it inline with OpenFL paradigms and future-proofing considerations, before offering it as a pull request.

The main goal is “html5”, where text is placed in the container UI. “html5” adapts to the scaling of the screen container UI, and text inside the container will also be scaled

The text of ‘starling’ will be converted into a texture image, and scaling will cause blurring

In order to display the text clearly, I initially set the text size to 50 and then scaled it to 0.2, scale=0.2

As can be seen, the small text at the bottom of this picture is still very clear and exquisite

Adapt to the screen in “html5”,
Element scaling is inevitable.

I just want the text to be clear and exquisite, whether it’s zooming in or out, is there a better way

That’s a great example @785597448, thank you!

Can I clarify, will the small text require any of the previously mentioned filters, or will it simply be solid white as shown in that example?

I like to add strokes, which make the text look more beautiful, but sometimes I can also skip them. Adults don’t have to make a choice, I want everything

The picture above is the UI interface of a game I have played before

This type of UI interface is common in games

In the game, there is also an exquisite UI interface where the text is very clear and refined, even for small words

The text of “as3” and “openfl” seems to be vector graphics, and no matter how they are scaled, they are still very clear and exquisite. I don’t need to consider this issue, but now I am using “starling” and I am looking for a solution. Thank you

This option uses the OpenFL TextField within Starling, but added to the a special Starling.current.nativeOverlay Sprite, so it’s controlled from within the Starling context, but is rendered outside of it.

Be mindful, to achieve the stroke effect, I’ve layered two GlowFilters here. These are expensive performance wise.

		var textField = new openfl.text.TextField();
		var font = Assets.getFont("fonts/someFont.ttf");
		textField.defaultTextFormat = new openfl.text.TextFormat(font.fontName, 100, 0xFF0000);
		textField.autoSize = openfl.text.TextFieldAutoSize.LEFT;
		textField.text = "This is VECTOR text!";		
		textField.filters = [
            new openfl.filters.GlowFilter(
                0x000000, // Outline color (black)
                1.0,      // Alpha
                3, 3,     // Blur X, Blur Y (pixels)
                10,       // Strength
                false,    // inner
                false     // knockout
            ),
			new openfl.filters.GlowFilter(
                0x000000, // Outline color (black)
                1.0,      // Alpha
                3, 3,     // Blur X, Blur Y (pixels)
                10,       // Strength
                false,    // inner
                false     // knockout
            )
        ];
		Starling.current.nativeOverlay.addChild(textField);

Make sure you change the font path ("fonts/someFont.ttf") to a legitimate font file. In the below screenshot, the OpenFL vector text is sitting on top of the Starling Stage3D backdrop.

Why not just set the transparency to 4 in the above code, but overlay two filters instead

Set the transparency to 4
Hard edges can also be achieved

Overlay filter and transparency set to 4
Which one consumes more?

Do you often use ‘nativeOverlay’ in your project as well?

The elements in ‘nativeOverlay’ seem unable to exchange hierarchical depth with ‘starling’ elements

How to synchronize the text size in ‘nativeOverlay’ with the size of my interface and change it accordingly

位图字体文字缩放会“失真”么?

Will text scaling in bitmap fonts cause distortion?

嗯!我感觉,“nativeOverlay”不适合我的项目。

因为,我需要把文字放入“starling”容器中,比如游戏角色头上显示角色的等级和名称。
我一般会把这文字和角色动画放一个容器里面。

2d动作游戏,且和其他游戏角色或者技能特效需要进行层级交换深度遮挡关系。

我感觉文字效果应该放入“starling”容器中,所以我感觉 “nativeOverlay”不适合我的项目。

我希望找到在“starling”中解决的方法

我目前是初始化文字大小设置50,然后缩小到0.2 scale=0.2 我不知道这样是否会“失真”
或者导致其他问题,我看不出来 所以我在积极交流 希望找到解决方法

我问过“ai”

“ai”说大图缩小不会模糊或者导致其他问题

但是“starling”在缩小是进行“采样什么的”导致了模糊?

Before now, I had never used this feature, so it was interesting to play with it. Feel free to adjust it as you see necessary, The code I’ve provided is an example or idea at most.

When using Starling, I approach text natively in Starling, as most of my projects are built for very specific hardware and resolutions. The dynamic scaling you’re wrestling with isn’t an issue in the context of my projects.

When I’ve built for HTML5, I have tended away from Starling, using OpenFL + SVG. But in those cases, I’m not developing games.

Yes, that will be a limitation. Stage3D will render to the bottom most layer, therefore causing OpenFL display objects to always appear on top of that.

The example you provided was small static white text that would not be covered at all. The Starling.current.nativeOverlay method may yet have use there.

I do agree with its shortcomings as far as tracking with characters in-game and such. I would not recommend that method for text that is updating frequently, such as character stats anyway.

Have you tried using distance field fonts? I’ve mentioned them a number of times.

The AI in this case, I’d suggest, got it wrong. Of course scaling down bitmaps has an impact on clarity.

啊?
小图放大确实会导致模糊。
但是大图缩小也会模糊么?大图不是有足够的像素么?
“ai”说大图缩小不会导致模糊?

您使用过“createjs”么?

在使用“createjs”时,我经常使用“位图字体”,我通常给文字使用“发光滤镜”描边。
当我缩小位图字体时,显示的文字“描边“变得好小…即使我的原位图描边很大,
不知道是什么情况