Blit Textures

Started by Gatobot14, May 29, 2015, 10:28:46 PM

Previous topic - Next topic

Gatobot14

its there a way to flip the image with blit methods??

resize the texture with blit looks almost fine but i think the  texture repites itself
because a black line appears at the top and bottom,could be fix it??
the only workaround i find was to make a bigger image and then blit it. 


Minigame

#1
I'm not sure exactly how on-topic this is but I always used raft's 2 classes to render strings and sprites, instead of the standard jpct functions. http://www.jpct.net/forum2/index.php?topic=1074.0

Here's some crap class I used with them to load and cache sprites;



package com.jpct.twod;

import java.io.File;
import java.io.IOException;

import javax.imageio.ImageIO;

import com.threed.jpct.FrameBuffer;

/*
* TODO : Refine this entire class. It's really old, and generic.. but it does the job for a spontaneous project.
*/
public class TwoD {

private TexturePack texturePack;
private String spriteIndex[];

public TwoD(final String fileStorage) {
try {
this.texturePack = new TexturePack();
this.spriteIndex = getSpriteIndex(fileStorage);
for (int i = 0; i < spriteIndex.length; i++) {
try {
File file = new File(fileStorage + File.separator + spriteIndex[i]);
texturePack.addImage(ImageIO.read(file));
} catch (IOException e) {
e.printStackTrace();
System.err.println("Unable to pack sprite: " + spriteIndex[i]);
System.exit(0);
}
}
if (spriteIndex.length > 0) {
texturePack.pack(true);
}
} catch (Exception e) {
e.printStackTrace();
System.exit(1);
}
}

private int getSpriteId(String sprite) {
sprite = sprite.replaceAll(".png", "");
String cleanSprite;
for (int i = 0; i < spriteIndex.length; i++) {
cleanSprite = spriteIndex[i].replaceAll(".png", "");
if (cleanSprite.equalsIgnoreCase(sprite)) {
return i;
}
}
System.err.println("Sprite '" + sprite + "' does not exist!");
System.exit(1);
return -1;
}

public void drawImage(FrameBuffer frameBuffer, String sprite, int x, int y, boolean transparent) {
try {
texturePack.blit(frameBuffer, getSpriteId(sprite), x, y, transparent);
} catch (Exception e) {
System.err.println("Error drawing sprite: " + sprite);
System.exit(1);
}
}

private String[] getSpriteIndex(final String assetPath) {
String path = assetPath + File.separator;
File file = new File(path);
if (file.isDirectory()) {
File images[] = file.listFiles();
String sprites[] = new String[images.length];
String sprite;
for (int i = 0; i < images.length; i++) {
sprite = images[i].getName();
sprite.replaceAll(".png", "");
sprites[i] = sprite;
}
return sprites;
}
return null;
}

}


Someone else will be a much better help haha but there are other options for drawing textures in a 2d manner :)

EgonOlsen

I'm not sure if this is one or two questions...you should able to flip a texture by giving it a negative width or height in the blit call.
I don't get the question about the black lines...can you post a screen shot of what you mean?

Gatobot14

ok if you can zoom it you should see a line over the sprite, only happens in blit resize,
its no big deal i just mention it.

EgonOlsen

Try setClamping(true) on the textures.