every time i try drawImage(img, dx, dy…), when I move my character it scales the map in and out, up and down, rather than moving that portion of the map.
I want to have a camera that follows the hero, and it works via bufferedimage.subImage, but that is freakishly slow. So in my main loop I have
offscreen.drawImage(map.paint(subImage), 0,0, this)
and my paint method should return a subimage of the big image.
public Image paint(Image subImage)
{ // Set the viewable portion of the canvas to the hero's coords
if (cameraFollow){
clipX=hero.x-320; clipY=hero.y-240; clipWidth=640; clipHeight=480;
if (hero.x-320<=0) clipX=0;
else if (hero.x+320>=width) clipX=width-640;
if (hero.y-240<=0) clipY=0;
else if (hero.y+240>=height) clipY=height-480;
}
canvas.setClip(clipX, clipY, clipWidth, clipHeight);;
canvas.drawImage(chip1,0,0, null);
canvas.drawImage(hero.image,hero.x, hero.y, null);
for (int i=0; i<sprites.size(); i++)
{thisSprite=(Sprite)sprites.get(i);
canvas.drawImage(thisSprite.image,thisSprite.x, thisSprite.y, null);}
canvas.drawImage(chip2, 0,0,null);
canvas.drawImage(subImage, 0,0,appWidth, appHeight, clipX, clipY, clipWidth, clipHeight, applet);
return subImage;
}