Show Posts
|
|
Pages: [1]
|
|
2
|
Java Game APIs & Engines / JOGL Development / Re: Need help splitting PNG images
|
on: 2004-10-05 03:30:04
|
I found the reason!!! I didn't create raster for each frame, but use one raster object for all frames. now it works, the right code is pasted below. 1 2 3 4 5 6 7 8 9 10 11
| if (bufferedImage.getColorModel().hasAlpha()) { for(int i= 0; i < totalFrame; i ++){ raster = Raster.createInterleavedRaster(DataBuffer.TYPE_BYTE,width, height,4,null); frames[i] = new BufferedImage(glAlphaColorModel,raster,false,new Hashtable()); } } else { for(int i= 0; i < totalFrame; i ++){ raster = Raster.createInterleavedRaster(DataBuffer.TYPE_BYTE,width, height,3,null); frames[i] = new BufferedImage(glColorModel,raster,false,new Hashtable()); } } |
|
|
|
|
|
3
|
Java Game APIs & Engines / JOGL Development / Re: Need help splitting PNG images
|
on: 2004-10-03 16:05:37
|
I am learning the example of lwjgl 0.92, the spaceinvaders.I try to combine 3 alien sprite images into one png file.It's very useful, isn't it? the code is listed below. my problem is:the first frame is correct, and the second is wrong, it's actually a mixture of the first and the second sprite. the third is wrong either. it's a mixture of all sprite. if I add a statement like g.clearRect(...)(see the code below), it works, the animate can play correctly, but transparent lost. does anybody can tell me why, and how to solve this problem. thanks. 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54
| public Texture getFrameTexture(String resourceName, int width, int height, int frame) throws IOException { Texture tex = (Texture) table.get(resourceName+frame);
if (tex != null) { return tex; }
BufferedImage bufferedImage = loadImage(resourceName); int totalFrame = bufferedImage.getWidth()/width;
if(frame >= totalFrame){ frame = 0; tex = (Texture) table.get(resourceName+frame); if (tex != null) { return tex; } }
WritableRaster raster; BufferedImage[] frames = new BufferedImage[totalFrame];
if (bufferedImage.getColorModel().hasAlpha()) { raster = Raster.createInterleavedRaster(DataBuffer.TYPE_BYTE,width, height,4,null); for(int i= 0; i < totalFrame; i ++){ frames[i] = new BufferedImage(glAlphaColorModel,raster,false,new Hashtable()); } } else { raster = Raster.createInterleavedRaster(DataBuffer.TYPE_BYTE,width, height,3,null); for(int i= 0; i < totalFrame; i ++){ frames[i] = new BufferedImage(glColorModel,raster,false,new Hashtable()); } }
Graphics g=null; for(int i = 0; i < totalFrame; i ++){ g = frames[i].getGraphics(); g.drawImage(bufferedImage, -i*width, 0, null);
tex = getTexture(frames[i], GL11.GL_TEXTURE_2D, GL11.GL_RGBA, GL11.GL_LINEAR, GL11.GL_LINEAR);
table.put(resourceName+i,tex); } return (Texture) table.get(resourceName+frame); } |
|
|
|
|
|
9
|
Java Game APIs & Engines / J2ME / Re: Transparent PNGs in MIDP1.0
|
on: 2003-06-04 06:13:12
|
|
in midp1.0, png32 or png24 transparent is supported. In photoshop ImageReady7.0, create a transparent image, and save the image as png24 or png32 format, and transparent is supported. I have finish a game like this.
|
|
|
|
|