Skip to main content
gamedev.net
🔒 Locked 🎮 Unity

[java] Bomberman problem

Started by royteusink Jan 21, 2008 at 4:21 AM 0 replies 1.7k views
Original Post
royteusink
royteusink
Hi all, We are busy with a bomberman game in java for school. But we have a problem with buffered image animation. When we load bombs with are inherented on our map, it becomes slow. Very Slow! We load our image 1 time (preload), then call addAnimation 1 time in de constructor. How can we solve this problem? and how can i add perfect delay (including calculations with the window drawing time or something like that) between 2 pictures in update()? Thx

package bomberman;

import java.awt.*;
import java.awt.image.*;
import java.io.*;
import java.util.ArrayList;

import javax.imageio.ImageIO;

public class AnimatedSprite {
	protected ArrayList<Animation> animations = new ArrayList<Animation>();
	protected BufferedImage image = null;
	protected Animation currentAnimation = null;
	protected int frameCount = 0;
	protected double currentTime = 0;
	
	public AnimatedSprite(BufferedImage image)	{
		this.image = image;
	}
	
	public void addAnimation(String animationName, int numberOfFrames, int startColumn, int startRow, int stepWidth, int stepHeight) {
		Animation ani = new Animation();
		BufferedImage[] peaces = new BufferedImage[numberOfFrames];
		
		for(int i = 0; i < numberOfFrames; i++)
		{
			int x = (startColumn * stepWidth) + (stepWidth * (i));
			peaces = this.image.getSubimage(x, startRow * stepHeight, stepWidth, stepHeight);
		}
		ani.setAnimationName(animationName);
		ani.setNumberOfFrames(numberOfFrames);
		ani.setStartColumn(startColumn);
		ani.setStartRow(startRow);
		ani.setStepHeight(stepHeight);
		ani.setStepWidth(stepWidth);
		ani.setPeaces(peaces);
		animations.add(ani);
	}
	
	public void setCurrentAnimation(int id) {
		frameCount = 0;
		currentAnimation = animations.get(id);
	}
	
	public BufferedImage getImage()	{
		return currentAnimation.getPeaces()[frameCount];
	}
	
	public void update() {
			if(frameCount >= currentAnimation.getNumberOfFrames()-1)
				frameCount = 0;
			else
				frameCount ++;

	}
}
http://www.vectorstudios.nethttp://engine.vectorstudios.net

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.