Discussion Board

Results 1 to 2 of 2
  1. #1
    Registered User
    Join Date
    Mar 2003

    comparing colors

    i i've just started using nokia's extensions for midp, and there are some things that i'm not getting.
    for example the DirectGraphics, in my paint method i have something like this, in the very end

    public void paint(Graphics g){
    offScreen = DirectUtils.getDirectGraphics(g);
    then later on my have one of the most requested methods in the whole app

    public boolean hasHit(int posX, posY){
    int[] pixels = new int[20];
    int format = offScreen.getNativePixelFormat();
    offScreen.getPixels(pixels, 0,0,posX,posY,1,20, format);
    for(int i = 0; i < pixels.length; i++){
    if(pixels[i] != GAME_BLUE){
    hasHit = true;

    and this is simply not working, more likely because of something i'm doing wrong, but just can't see what.
    my intention is to get a heigth 20 verical line with 1 width, and to check the values in it.
    but i when i look into the array, i only see zero's.
    and another thing, how do i transform 0x05143F into TYPE_USHORT_4444_ARGB;
    thanks in advance for your time

  2. #2
    Regular Contributor
    Join Date
    Mar 2003

    RE: comparing colors


    I dont think you should do you collision detecion this way, i think it will be to slow.

    But also, the getPixels needs to have a scanlength which you should set to 1 as you are get'ing a 1 pixel wide area from the screen.

    so offScreen.getPixels( pixels, 0, 1, posX, posY, 1, 20, format); might help.

    but it think it would be best to do the collision detection by not checking the pixels.

    to "transform 0x05143F" to the TYPE_USHORT_4444_ARGB format you can do the following;
    int blue = 0x05143F & 0x0000FF;
    int green = (0x05143F & 0x00FF00)>>8;
    int red = (0x05143F & 0xFF0000)>>16;
    int newShort = 0xF000 | ((red>>4)<<8) | ((greeb>>4)<<4) | (blue>>4);

    something like that

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts