good day, guys.
Sorry for my bad english, i am beginner yet. :-
i have one doubt.
I decided create a shooter game like “Mushihime-Sama”, not really identic that this but similar, the problem is in the test of paint elements in canvas, paint bullets in a continuous manner causes the player to move slow.
I use bufferstrategy for the level and bufferimage for the elements how the player, background, bullets and enemies. This problem only pass in ubuntu. In windows, the processor work much.
When i painted much elements in canvas, the player will move most slow?
what is the right way to paint In This Case?
PD. sorry if this doubt is already repeated.
CODE:
paint bullets:
public void paintBullets(Graphics2D g){
if(bullets.size()>0){
for(int q=0; q<bullets.size(); q++){
bullets.get(q).paint(g);
}
}
}
public void paint(Graphics2D g){
if(life>0){
g.drawImage(img.get(num)[currentFrame], x,y, null);
}
}
load img
public void setSpriteNames(String[] names) {
spriteNames = names;
height = 0;
width = 0;
colecImg= new BufferedImage[names.length];
for (int i = 0; i < names.length; i++ ) {
BufferedImage image = cargador.getSprite(spriteNames[i]);
height = Math.max(height,image.getHeight());
width = Math.max(width,image.getWidth());
colecImg[i]=image;
}
img.add(colecImg);
}
CARGADOR
protected Object loadResource(URL url) {
try {
return ImageIO.read(url);
} catch (Exception e) {
System.out.println(" "+url);
System.out.println("Error"+e.getClass().getName()+" "+e.getMessage());
System.exit(0);
return null;
}
}
public BufferedImage createCompatible(int width, int height, int transparency) {
GraphicsConfiguration gc = GraphicsEnvironment.getLocalGraphicsEnvironment().getDefaultScreenDevice().getDefaultConfiguration();
BufferedImage compatible = gc.createCompatibleImage(width,height,transparency);
return compatible;
}
public BufferedImage getSprite(String name) {
BufferedImage loaded = (BufferedImage)getResource(name);
BufferedImage compatible = createCompatible(loaded.getWidth(),loaded.getHeight(),Transparency.BITMASK);
Graphics g = compatible.getGraphics();
g.drawImage(loaded,0,0,this);
return compatible;
}