0

I'm making a simple side scroller game in Java but am having trouble making the camera move with the person. My plan was to create a buffered image that could adjust the region of the image that is displaying and simply have it follow my character. However, I couldn't find any functions in the API to change the region of the buffered image that's displayed, so how could I do this? Thanks for any help provided.

 //The level is created in an 800x400 pixel size, is there any way I can change
 //the region myImage displays?
myImage =  new BufferedImage(400, 400, BufferedImage.TYPE_INT_RGB);

1 Answer 1

2

Well while you will be drawing your image you have a lot of options for example this function can draw any rectangle from your original image on any rectangle of the surface you get Graphics object from.

Sign up to request clarification or add additional context in comments.

2 Comments

@user3050810 Well for example if you'll override paint or paintComponent method you will be getting Graphics g as it's argument, then you can call something like g.drawImage (myImage, 0, 0, 400, 400, x, 0, x + 400, 400, null); it will draw the rectangle 400x400 from myImage with offset x on component you've overridden method from. If you want to draw on some images just get Graphics with createGraphics function and so on.
Hey thanks, I got it all working. I really appreciate the help.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.