Own charset

Hi,

I would need some hints/links/keywords how to implement my own charset within a game.

g.drawString(…) doesn’t looks professional. :slight_smile:

What exactly do you mean by charset? Do you mean that you would like to use a charset that is not english characters? What do you mean g.drawString looks unprofessional? Please give us more info! :wink:

Are you trying to make your own Font??

You need a bitmap with the letters and numbers that you require for your game,

then you can use something like this:


    String text = "Hello";
    int strPosX = 10;
    int strPosY = 10;
    for(int i = 0; i < text.length(); i++){
      char c = text.charAt(i);
      int charPosX = getPosX(c);
      int charPosY = getPosY(c);
 g.drawImage(fontImage,strPosX,strPosY,strPosX+charWidth,strPosY+charHeight,charPosX,charPosY,charPosX+charWidth,charPosY+charHeight,this);
      strPosX += charWidth; //next char position.
    }

I assume a fixed width Font.

The methods getPosX(char c) and getPosY(char c) are written based on the bitmap with the font.

If your image has the chars this way
ABCD EFGH IJKL
a call to getPosX(‘G’) returns 2charWidth
a call to getPosY(‘G’) returns 1
charHeight

However, if your image is like this
ABCDEFGHIJKL
a call to getPosX(‘G’) returns 6charWidth;
a call to getPosY(‘G’) returns 0
charHeight;

Hope this helps you.

Rafael.-

EDIT: little typo

You can also load your own font (from your jar, with Font.createFont() ) and use it with drawString

O.k. thx. I meant font - not charset ::slight_smile: