Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixes to make the preloader work on HTML5 #1846

Closed
wants to merge 9 commits into from

Conversation

Nallebeorn
Copy link

This modifies FlxPreloader and FlxBasePreloader to work on the HTML5 target. Because blend modes don't work on html5, the default preloader doesn't look quite as good as in Flash... but it runs. More importantly, FlxBasePreloader works fine, so custom preloaders can be made (which don't use blend modes :))
There are some quirks to be aware of with regard to embedded BitmapData and TextFields with custom fonts (and probably other things I haven't encountered yet) – this is documented to some extent in the comments in FlxPreloader.hx. Unfortunately, it inevitably leads to somewhat messier code, but I've tried to keep it as clean as possible.

Fixes #1804.

@Gama11 Gama11 added this to the 4.1.0 milestone May 10, 2016
…mapdata. This allows for much cleaner code, without even requiring any conditional compilation in child preloaders.
* @param onLoad Executed once the bitmap data is finished loading in HTML5, and immediately in Flash. The new BitmapData instance is passed as an argument.
* @return The BitmapData instance that was created.
*/
private function loadBitmapData(bitmapDataClass:Class<BitmapData>, onLoad:BitmapData->Void):BitmapData
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This function doesn't even seem to be used?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It isn't used in the default preloader, but I included it for the benefit of those writing custom preloaders, in case anyone wants to load an embedded bitmapdata without immediately creating a Bitmap object using it.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Either way, the implementation is completely redundant. This method should be used in the preloader, wrapping the BitmapData in a Bitmap can easily be done there.

Also not sure this is really the right place for a utility method like this...

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

FlxAssets would probably be a better place for it (as getEmbeddedBitmapData() maybe)?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Although "embedded" is a bit ambigious, there's also the option of embedding assets included via the project.xml...

Copy link
Member

@Gama11 Gama11 May 14, 2016

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That's correct. We already do that in the debugger (although all buttons are 11x11, so not that hard to get right), so at least it's a consistent workaround... And getting rid of the callback awkwardness counts for something too I guess?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, the callback system is pretty messy... But remember that it's not only about the default FlxPreloader, many people write custom preloaders. And having to manually supply all images' size (and keep it up to date whenever I switch images!) feels, at least to me, like it'd been even more awkward than the callback system.
But I dunno... I guess there isn't any good solution.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The good solution would be a fix at OpenFL level.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

True. Although it's not obvious what a good solution on that level would be, either.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Lars' solution seemed quite sensible to me:

On export, have the tools
inspect all the bitmapdata objects for size and write that data out, so that we can
have an additional Assets.getSize() command that gives you the width/height
of a bitmapdata without actually loading it.

@Gama11
Copy link
Member

Gama11 commented May 13, 2016

Do you know what's responsible for the textfield being resized like this after a few frames?

@Nallebeorn
Copy link
Author

No, I'm not sure what is causing that. Well, it's obviously because there's a delay until it starts using the correct font, but I don't know why that is. My guess is it's similar to the bitmap loading issues, i.e. it takes a while until the specified font has actually been loaded... But that's purely a guess.

@Gama11
Copy link
Member

Gama11 commented May 14, 2016

Are you seeing the same effect / have you looked into possible fixes?

@Nallebeorn
Copy link
Author

Nallebeorn commented May 14, 2016

I've seen that effect, yes... But for me, it has always resized so quickly I don't really notice it unless looking for it, and I've never seen it as that big a problem.
Actually, it's probably most noticeably in games that load really quickly, because the preloader often freezes a short while before starting the game – and that will be before the TextField had changed.
I haven't really looked much into it, no. But I'll do some research.

@Gama11 Gama11 modified the milestones: 4.1.0, 4.2.0 Jul 10, 2016
@Gama11 Gama11 closed this in 00c0e20 Aug 21, 2016
@Gama11
Copy link
Member

Gama11 commented Aug 21, 2016

Thanks for your contribution! :) I merged the changes manually in 00c0e20 since there were merge conflicts by now.

Aurel300 pushed a commit to larsiusprime/haxeflixel that referenced this pull request Apr 18, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants