Prototype 1 finished

Published May 19, 2012
Advertisement
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
texture.setMagFilter(MagFilter.Nearest);

// 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
image.setFormat(Image.Format.RGBA8);
}
0 likes 1 comments

Comments

O-san
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!
May 25, 2012 07:30 AM
You must log in to join the conversation.
Don't have a GameDev.net account? Sign up!
Advertisement
Advertisement