Advertisement Jump to content
  • Advertisement
  • entries
  • comments
  • views

Prototype 1 finished

Sign in to follow this  
Spencer Bowers


Wow, I forgot how draining a full-time job can be. It's been surprisingly difficult to work on my game after I get home in the afternoon. Of course, the chronic insomnia is probably also a factor. Either way, finally managed to crank out some more code and finish off the first prototype. You can play around with it here. Move with A and D, jump with Space, click to throw a snowball. I'm not doing bounds checking on the edges of the play field, so just don't go out there.

The main cause of trouble I had with this prototype was figuring out how to edit a texture that was loaded from a file in jME3. Google showed me this forum post for how to fill in the texture data from scratch, but I had to figure out how to start with a texture I'd loaded from a .png. Here's the solution I came up with. I'm putting it here in the hopes that it helps someone in the future. I added this function to the class I found in the link above:

// tex is a texture I loaded from a file
public void setTexture(Texture tex)
// store the loaded texture in the class
texture = (Texture2D) tex;

// I don't want any filtering on this texture

// grab the image that actually holds the texture data
image = texture.getImage();

// Image holds a list of ByteBuffers for each mip level
// loop through the buffer to fill out the array
ByteBuffer buffer = image.getData(0);

for (int x = 0; x < width; x++)
for (int y = 0; y < height; y++)
// the texture loaded from PNG in the format BGR8,
// so I have to index into the byte buffer using 3 bytes
// per pixel in BGR order
buffer.position(((y * width) + x) * 3);

// this seems to be the best way to preserve byte
// values when assigning byte to int in Java
// because bytes are signed
int b = (int) buffer.get() & 0xff;
int g = (int) buffer.get() & 0xff;
int r = (int) buffer.get() & 0xff;
Color c = new Color(r, g, b, r);
setPixel(x, y, c);
// set the image format to what you want before creating
// a new when getTexture() gets called
Sign in to follow this  

1 Comment

Recommended Comments

Nice progress =) I played around a bit and noticed that the player seems to float above the snow slightly. Maybe it's possible to offset the player so he walks more closely on the ground? Nice work nevertheless, keep it up!

Share this comment

Link to comment

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Advertisement

Important Information

By using, you agree to our community Guidelines, Terms of Use, and Privacy Policy. is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!