flump icon indicating copy to clipboard operation
flump copied to clipboard

Subclassing Starling Image and Sprite

Open chichilatte opened this issue 11 years ago • 6 comments

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?

chichilatte avatar Jul 19 '14 10:07 chichilatte

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.

thejustinwalsh avatar Jul 19 '14 23:07 thejustinwalsh

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

chichilatte avatar Jul 21 '14 11:07 chichilatte

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/

roguenet avatar Jul 21 '14 18:07 roguenet

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.

chichilatte avatar Jul 22 '14 09:07 chichilatte

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.

roguenet avatar Jul 22 '14 23:07 roguenet

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

Thanks

BenoitFreslon avatar Mar 15 '15 12:03 BenoitFreslon