English 中文(简体)
Java LWJGL custom texture
原标题:

I m working on a smallish game with a friend and we ran into a really annoying problem with sprite sheets and textures... Right now we re just using Slick2D s textureloader and we even tried their SpriteSheet but no luck. What we really need is just a custom textureloader or whatever you may call it to load a big texture, break it into smaller textures, and save the new smaller textures into maybe an array. If you know a site that could help or maybe just paste your code that would be great, thanks!

问题回答

I had fine luck with the code below in one of my projects. I happen to keep textures in individual files, but it seems to work without issue.

If you want to load one big image, you can do that the same way, and then chop it up into pieces using the subImage method of the Image class. Just note that the documentation mentions that, any sub-image "retains a reference to the [original] image data, so should anything change [in the parent image] it will affect sub-images too."

import org.newdawn.slick.Image;

...whatever code you ve got...

/** Loads the image resources needed for the game.
*
* @throws SlickException if there is a problem loading one of the images
*/
public void loadImageResources() throws SlickException {
  images = new Image[6];

  images[0] = new Image("images/controls/play.png");
  images[1] = new Image("images/controls/pause.png");
  images[2] = new Image("images/tiles/stone.png");
  images[3] = new Image("images/peds/ped.png");
  images[4] = new Image("images/peds/ped_add.png");
  images[5] = new Image("images/peds/ped_remove.png");
}




相关问题
Spring Properties File

Hi have this j2ee web application developed using spring framework. I have a problem with rendering mnessages in nihongo characters from the properties file. I tried converting the file to ascii using ...

Logging a global ID in multiple components

I have a system which contains multiple applications connected together using JMS and Spring Integration. Messages get sent along a chain of applications. [App A] -> [App B] -> [App C] We set a ...

Java Library Size

If I m given two Java Libraries in Jar format, 1 having no bells and whistles, and the other having lots of them that will mostly go unused.... my question is: How will the larger, mostly unused ...

How to get the Array Class for a given Class in Java?

I have a Class variable that holds a certain type and I need to get a variable that holds the corresponding array class. The best I could come up with is this: Class arrayOfFooClass = java.lang....

SQLite , Derby vs file system

I m working on a Java desktop application that reads and writes from/to different files. I think a better solution would be to replace the file system by a SQLite database. How hard is it to migrate ...

热门标签