Author Topic: Blit Textures  (Read 915 times)

Offline Gatobot14

  • int
  • **
  • Posts: 64
    • View Profile
Blit Textures
« on: May 29, 2015, 10:28:46 pm »
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. 


Offline Minigame

  • int
  • **
  • Posts: 55
    • View Profile
Re: Blit Textures
« Reply #1 on: May 30, 2015, 12:00:39 am »
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;


Code: [Select]
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 :)
« Last Edit: May 30, 2015, 12:03:54 am by Minigame »

Offline EgonOlsen

  • Administrator
  • quad
  • *****
  • Posts: 11745
    • View Profile
    • http://www.jpct.net
Re: Blit Textures
« Reply #2 on: May 30, 2015, 10:06:43 am »
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?

Offline Gatobot14

  • int
  • **
  • Posts: 64
    • View Profile
Re: Blit Textures
« Reply #3 on: May 30, 2015, 05:32:30 pm »
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.

Offline EgonOlsen

  • Administrator
  • quad
  • *****
  • Posts: 11745
    • View Profile
    • http://www.jpct.net
Re: Blit Textures
« Reply #4 on: May 30, 2015, 06:05:41 pm »
Try setClamping(true) on the textures.