Java can't show image [CANVAS] -
i making game in java , trying draw image on screen, nothing show ( black screen no errors ) :(
here code import image:
public static bitmap loadbitmap(string filename) { try { bufferedimage img = imageio.read(art.class.getresource(filename)); int w = img.getwidth(); int h = img.getheight(); bitmap result = new bitmap(w, h); img.getrgb(0, 0, w, h, result.pixels, 0, w); (int = 0; < result.pixels.length; i++) { int in = result.pixels[i]; int col = (in & 0xf) >> 2; if (in == 0xffff00ff) col = -1; result.pixels[i] = col; } return result; } catch (exception e) { throw new runtimeexception(e); } }
and bitmap class:
public void draw(bitmap bitmap, int xoffs, int yoffs) { for(int y = 0; y < bitmap.height; y++) { int ypix = y + yoffs; if(ypix < 0 || ypix >= height) continue; for(int x = 0; x < bitmap.width; x++) { int xpix = x + xoffs; if(xpix < 0 || xpix >= width) continue; int alpha = bitmap.pixels[x + y * bitmap.width]; if(alpha > 0) pixels[xpix + ypix * width] = bitmap.pixels[x + y * bitmap.width]; } } }
and draw of :
public void render(game game) { for(int y = 0; y < height; y++) { float yd = ((y + 0.5f) - height / 2.0f) / height; if(yd < 0) yd *= -1; float z = 10 / yd; for(int x = 0; x < width; x++) { float xd = (x - width / 2.0f) / height; xd *= z; int xx = (int) (xd) & 7; int yy = (int) (z + game.time * 0.1f) & 7; pixels[x + y * width] = art.floors.pixels[xx + yy * 64]; } } }
i have no errors! don't understand.. bug caused alpha or something? ho , image.png 64x64 made in paint.net
Comments
Post a Comment