jellyfication
jellyfication

Reputation: 1605

LibGDX - Using android libs

I have three projects

  1. Game - Java Project
  2. GameAndroid - Android
  3. GameDesktop - Java Project

I want to access android.graphics.Color, but I'm in my Game project which is java, so i can't do that. When I try to access Java.awt.Color insted, i'll get java.lang.NoClassDefFoundError insted.

Is there a way to access any of these libraries ?

for example i would like to use this method:

Color.getHSBColor();

Upvotes: 2

Views: 1248

Answers (1)

mikołak
mikołak

Reputation: 9705

I generally recommend using com.badlogic.gdx.graphics.Color instead.

It has the advantage of being platform-agnostic - but do note the implementation differences between the analogues.

For example, compare Android's implementation (AWT's works in the same fashion) :

public static int argb(int alpha, int red, int green, int blue) {
    return (alpha << 24) | (red << 16) | (green << 8) | blue;
}

and the libgdx implementation:

public static int toIntBits (int r, int g, int b, int a) {
     return (a << 24) | (b << 16) | (g << 8) | r;
}

As you can see, the ordering in the encoding is different. Here's the source code for reference.

If you're looking for stuff such as HSB->RGB conversion, this can be implemented "manually". See this answer, for example - but remember to use the libgdx implementation to generate the actual int from the RGB components!

Upvotes: 4

Related Questions