flixel icon indicating copy to clipboard operation
flixel copied to clipboard

Can't stamp() FlxBitmapText to FlxSprite [HTML5, HXCPP]

Open hqkirkland opened this issue 7 years ago • 5 comments

  • Haxe version: 3.4.7
  • Flixel version: 4.5.1
  • OpenFL version: 8.4.1
  • Lime version: 7.0.0
  • Affected targets: HTML5, HXCPP

Code snippet reproducing the issue:

package;

import flixel.FlxSprite;
import flixel.graphics.frames.FlxBitmapFont;
import flixel.text.FlxBitmapText;
import openfl.Assets;

/**
 * ...
 * @author Hunter
 */
class ChatBubbleTest extends FlxSprite
{
    private static var chatFont:FlxBitmapFont;
	
    public function new():Void
    {
        super();
        var fontData:String = Assets.getText(AssetPaths.arialBitmap_Size14px__fnt);
        chatFont = FlxBitmapFont.fromAngelCode(AssetPaths.arialBitmap_Size14px_0__png, Xml.parse(fontData));
        generate();
    }
	
    public function generate():Void
    {
        makeGraphic(100, 100, 0xFFFFFFFF);
	var chatText:FlxBitmapText = new FlxBitmapText(chatFont);
	chatText.text ="bleh bleh bleh";
	chatText.multiLine = true;
	chatText.color = 0xFF000000;
	chatText.lineSpacing = -1;
        stamp(chatText);
    }
}

Create a new instance of this class and try adding it in the FlxState.


Observed behavior: On Flash, the text is properly displayed. On HTML5 and HXCPP, this error message appears:

HTML5: js__$Boot_HaxeError: message: "Cannot stamp to or from a FlxSprite with no graphics."

Expected behavior: Text should display on all platforms.

@Geokureli explained this to me:

Flash draws letters to a bitmap on text updates and blits that bitmap every draw call, where HTML/CPP renders each letter each draw call

But I still feel there should be a method to stamp text onto FlxSprite.

hqkirkland avatar Sep 16 '18 20:09 hqkirkland

Use case for stamping texts:

Without stamp, I have to write code to have chat bubbles follow their individual user every frame. This feels like an unnecessarily-complicated solution, since the size of the whole "BubbleSet" will vary.

hqkirkland avatar Sep 18 '18 18:09 hqkirkland

@Beeblerox @Gama11 I created a Gist that overrides the FlxG.renderTile / FlxG.renderBlit conditional tests:

https://gist.github.com/hqkirkland/f016d2e1790f415f35d672fae45de3ac

The text is rendered perfectly and is easily-stamped.

Unless there's another reason (and I'd be curious to know), I think that the rendering should be unified to prefer blitting.

hqkirkland avatar Sep 19 '18 05:09 hqkirkland

The inconsistency is annoying and finding a way to unify the interface while maintaining the performance would be nice.

However, I thought I would offer a workaround for now, which is to skip FlxText altogether and draw TextFields onto your sprites' BitmapDatas. For an example, see makePlaceholderGraphic in https://github.com/JoeCreates/Lycan/blob/master/lycan/util/GraphicUtil.hx.

On Wed, 19 Sep 2018, 06:26 hqkirkland, [email protected] wrote:

@Beeblerox https://github.com/Beeblerox @Gama11 https://github.com/Gama11 I created a Gist that overrides the FlxG.renderTile / FlxG.renderBlit conditional tests:

https://gist.github.com/hqkirkland/f016d2e1790f415f35d672fae45de3ac

The text is rendered perfectly and is easily-stamped.

Unless there's another reason (and I'd be curious to know), I think that the rendering should be unified to prefer blitting.

— You are receiving this because you are subscribed to this thread. Reply to this email directly, view it on GitHub https://github.com/HaxeFlixel/flixel/issues/2172#issuecomment-422657951, or mute the thread https://github.com/notifications/unsubscribe-auth/ACbEvIb-QoODD8T681te-g1uqqCSAgMpks5ucdWEgaJpZM4WrBeL .

JoeCreates avatar Sep 20 '18 04:09 JoeCreates

So that's a good suggestion, and one I considered as well, but I don't think TextField supports Bitmap fonts. I'm having to get Arial 7.5 exactly, so I created it in AngelCode.

hqkirkland avatar Sep 20 '18 13:09 hqkirkland

Oh sorry, I somehow missed this was about flxbitmaptext specifically.

I have another workaround suggestion which isn't particularly optimal but it gets the job done in a very easy way. I made it for precisely this kind of situation where you want complex graphics made out of many smaller graphics but still want to treat the product as a single graphic on native (e.g. for nice scale/alpha tweening of ui panels full of components).

It's also in lycan.util called CameraSprite: https://github.com/JoeCreates/Lycan/blob/master/lycan/util/CameraSprite.hx

It's a FlxSprite with a group which you can add things such as your bitmap text to. These get rendered to a flxcamera which then gets drawn onto the flxsprite. In your case you would have one of these and just add your bitmaptexts to the group.

JoeCreates avatar Sep 20 '18 13:09 JoeCreates