So, I create a side scroller, and I'm trying to make the image at the point of another image.
I have a background image that is 5000 x 500, and lets say that I want to draw an image that is 25x25 by 500, 50 of the background image. How can I do it?
So far I have tried:
Coins c = new Coins(img.getWidth(this) - 4500, img.getHeight(this) - 250);
But it just draws it at 500, 50 frames, so it "moves" in the image when I scroll to the right. I want, after scrolling once to the right, the image of the coin for drawing on the 500.50 image is still 495, 50 frames.
I could also use getGraphics for the background image and draw a smaller image on it, but I think, because I found that this is what it paints when creating the object, I cannot do this.
The symbol does not move, except up and down, only background scrolls, so I want the coin to move in the background.
PICTURES: (cannot insert it because I do not have 10 replica points) http://dl.dropbox.com/u/47632315/char.png http://dl.dropbox.com/u/47632315/coin. png http://dl.dropbox.com/u/47632315/sideScrollerBG.png
And SSCCE:
import java.awt.*; import java.awt.event.*; import javax.swing.*; import java.net.*; import java.awt.image.ImageObserver; import java.io.IOException; import javax.imageio.ImageIO; public class SideScroller extends JPanel implements KeyListener { public static void main(String args[]) throws Exception { SideScroller f = new SideScroller("Side Scroller"); } JFrame f = new JFrame(); int x = 0; int y = 0; int k = 10; int j = 50; int characterY = 351; boolean canJump = true; boolean keyPressed[] = new boolean[3]; Image img; Image character; Coins c = new Coins(x + 500, y + 350); public SideScroller(String s) throws MalformedURLException, IOException { img = ImageIO.read(new URL("http://dl.dropbox.com/u/47632315/sideScrollerBG.png")); character = ImageIO.read(new URL("http://dl.dropbox.com/u/47632315/char.png")); f.setTitle(s);
source share