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

Subclassing Starling Image and Sprite #121

Open
chichilatte opened this issue Jul 19, 2014 · 6 comments
Open

Subclassing Starling Image and Sprite #121

chichilatte opened this issue Jul 19, 2014 · 6 comments

Comments

@chichilatte
Copy link

Hi, truly loving Flump, thanks to all contributors. I wonder if anyone's thought about how custom DisplayObject subclasses should work with Flump? For example, I might want flump.display.LibraryImpl.createImage() to create an instance of mygame.display.ImageEx which extends starling.display.Image with extra useful functionality.

As far as I can see it's not possible with casting or overriding. Hacking the Flump code works tho! Does (an unhacked) Flump preclude the use of custom DisplayObject subclasses?

@thejustinwalsh
Copy link
Contributor

You would probably want to start your quest here: LibraryLoader.creatorFactory

It looks like you could easily override this property to return a custom implementation of the CreatorFactory that returns your custom implementation of an ImageCreator, all without modifying the original source.

@chichilatte
Copy link
Author

Fabulous. I implemented a custom CreatorFactory and then extended LibraryLoader, ImageCreator, MovieCreator, Movie classes. Thanks for the insight Justin!

@roguenet
Copy link
Contributor

Wish I'd noticed this thread when it was first posted. I've done some flump runtime display class customizing, and implementing CreatorFactory is how I did it as well. In case this is something that you were looking for as well, I wrote a mini tutorial on implementing pixel-level alpha hit detection in Starling/flump: http://codewright.roguenet.org/blog/2013/07/08/alpha-hit-testing/

@chichilatte
Copy link
Author

Wow thanks roguenet, that's actually my next task. Was hoping Pixel Perfect Touch would do the trick, but very useful to see a Flump-specific approach.

@roguenet
Copy link
Contributor

Yeah, you're going to see a tradeoff in performance, using a runtime tool like that pixel perfect touch extension. It's really slow to read through all the pixels in an image at runtime, but if you don't need to read that info for a lot of images, it might be good enough. My own blog post is also presented as a runtime tool, but I point out that it's a good idea to port the algorithm to a pre-process, which is what I ended up doing for my own game assets because in my case I'm working with many large sprite sheets.

@BenoitFreslon
Copy link

@chichilatte Hello,
Can you please share a sample of you code please? :)

Thanks

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

No branches or pull requests

4 participants