First time poster. Just wanted to ask a quick question about sprite animation and clipping. Up until now I've been using
drawImage(Image img, int dx1, int dy1, int dx2, int dy2, int sx1, int sy1, int sx2, int sy2, ImageObserver observer)
to draw the correct part of the sprites image, but I've recently made the transition from int to double when storing my sprites position so it doesn't really work anymore.
Now I've started using CropImageFilter, so when I create a sprite that has more than one frame I split the image into an image array and use this bit of code:
public void draw(Graphics2D g)
if (m_image != null && !m_bHidden)
if (m_iNumFramesX == 1)
g.drawImage(m_image, m_at.getTranslateInstance(m_rcPosition.x, m_rcPosition.y), null);
m_at.getTranslateInstance(m_rcPosition.x, m_rcPosition.y), null);
Now this works but in the game I'm working on right now I change a sprites image based on certain game events and when this happens I create a new image array and crop the appropriate image into it. This works just fine locally but when I play the applet over the web I get a half a second freeze when this happens.
I've been trying to use setClip(...) now to draw just the part of the current image that I want but I just can't seem to figure out just how exactly it works :p so any help would be appreciated (regarding setClip or any better way to get the part I want). Oh and if it is of any interest, the Graphics2D object the sprite's draw method receives is from the volatile image I use as a back buffer.