Code Monkey home page Code Monkey logo

Comments (6)

IQAndreas avatar IQAndreas commented on July 22, 2024

We can hammer out details on what goes on inside the FlxColor instances later. For example, it would be a better idea to store a color generated with fromHSB with the actual HSB values instead of loosing accuracy by converting it to a uint and storing it that way.

Also, Flixel would probably still continue to use uints when storing colors internally (exhibit A) for performance reasons, but users of the library are more than welcome to use FlxColor instances in their games if performance isn't an issue.

Any thoughts? Would it help make Flixel more logically organized, or just complicate things?

from flixel.

Dovyski avatar Dovyski commented on July 22, 2024

That's great! I would definitely make Flixel more logically organized. My only concern was the performance hit, but if we stick with uint for color internally, there will be no problems.

from flixel.

JoeCreates avatar JoeCreates commented on July 22, 2024

I've actually been working on this is HaxeFlixel, and strangely, it's very much as you have described, except there is no such thing as converting a color, because a FlxColor can automatically pretend to have any rgb/hsb/hsl/cmyk property. HaxeFlixel/flixel#1027

I will be pushing both a completely revamped FlxColor and demo for FlxColor pretty shortly. It includes the ability to get and set any rgb/hsb/hsl value, though precision is lost as the underlying type is an Int (see below). I've added additional features for creating gradients with optional easing functions.

Using a little haxe magic, FlxColor is actually an Int in disguise, so it is interchangeable with Ints/hex literals. For example, you can do:

var myColor:FlxColor = 0xff123456;
trace(myColor.hue);

Basically it provides the convenience of FlxColor methods, without losing the int performance and functionality. I'm not sure how much of it will be portable to as3, but before anyone starts duplicating work, you may want to wait and see how much can be reused. ;)

from flixel.

JoeCreates avatar JoeCreates commented on July 22, 2024

I've made a pull request to HaxeFlixel with instantiable FlxColors: HaxeFlixel/flixel#1113

from flixel.

IQAndreas avatar IQAndreas commented on July 22, 2024

I've actually been working on this is HaxeFlixel, and strangely, it's very much as you have described

Do you mind if I pretty much steal the entire class for AS3 Flixel? That way, the two libraries match which will help both users and tutorial writers.

It includes the ability to get and set any rgb/hsb/hsl value, though precision is lost as the underlying type is an Int (see below).

I'm not a fan of loosing precision unnecessarily, so for the AS3 version, I have a different plan of approach which should work.

Using a little haxe magic, FlxColor is actually an Int in disguise, so it is interchangeable with Ints/hex literals.

That so cool! Haxe has so many cool features, I don't know why I haven't switched over yet. Alas, Flash doesn't have anything like that (well, we could pervert the prototype chain for AS3's uint class, but that's just wrong in my eyes).

from flixel.

JoeCreates avatar JoeCreates commented on July 22, 2024

You are welcome to try to take as much as you can from HaxeFlixel's FlxColor, however, I'm not sure some of it will translate so well to AS3, considering a lot of the implementation ended up being centered around the use of the haxe abstract.

Also, it's possibly worth considering the performance implications of mimicking the behavior. The benefit that comes with the small loss of precision in HaxeFlixel's FlxColor provides the benefit of keeping the performance as if only ints were ever used. There is no data other than a single int, and no complex data type instantiated. In HaxeFlixel, this has meant that FlxColor has replaced everywhere that used to use an int or uint as a color without any loss to performance, whereas in AS3 Flixel, it might be best to use FlxColor only for when conversions are required?

As I say, you are welcome to use of it what you can. The conversion algorithms themselves should port pretty easily. :)

from flixel.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.