java - Changing color of a moving image without lowering the fps -
i added option game makes enemies have random color clothes instead of regular blue. use code draw rectangles on shirt of enemy.
bufferedimage image = new bufferedimage(z.getwidth(), z.getheight(), bufferedimage.type_4byte_abgr); try{ image = imageio.read(new file("c:\\program files (x86)\\zombiegame\\ zombie.png")); }catch (ioexception ex) { } int j, k, red, green, blue; for(j = 0; j < z.getwidth(); j++){ for(k = 0; k < z.getheight(); k++){ color c = new color(image.getrgb(j, k)); red = c.getred(); green = c.getgreen(); blue = c.getblue(); if(red == 0 && green == 0 && blue == 178){ g2d.setcolor(color.red); rectangle r = new rectangle(j,k, 1, 1); path2d.double rect = new path2d.double(r, at); g2d.fill(rect); } } }
the thing when apply game run twice slow (before added code got solid 80 fps fast added got around 30 fps). question if there better way in change color of specific parts of image without lowering fps drastically?
perhaps, shouldn't iterate on every pixel. can see, have 2 disadvantages:
- if have pixels, don't want change within same image;
- it's slow.
as first argument, lets assume wouldn't happen, long image (apparently) contains single item.
and second question, in fact main question - can suggest looking applied answer in this question , comments it. contains description on how achieve task faster, iterating, , comment has link example - here is
Comments
Post a Comment