.. 내가 'Y'에 변수를 추가 일부 스레드를 사용할 필요가 있음을 알고스크롤 배경, JAVA
이미지의 좌표
내가 뭔가를 시도했지만이 ... 모든 배경이 이유를 이해하지 못할 어떤 이유에 줄무늬 얻을 이동하기 시작
사진 : streaking background
public class Background {
private BufferedImage image;
.....
....
public Background(int x, int y) {
this.x = x;
this.y = y;
// Try to open the image file background.png
try {
BufferedImageLoader loader = new BufferedImageLoader();
image = loader.loadImage("/backSpace.png");
}
catch (Exception e) { System.out.println(e); }
}
/**
* Method that draws the image onto the Graphics object passed
* @param window
*/
public void draw(Graphics window) {
// Draw the image onto the Graphics reference
window.drawImage(image, getX(), getY(), image.getWidth(), image.getHeight(), null);
// Move the x position left for next time
this.y +=1 ;
}
public class ScrollingBackground extends Canvas implements Runnable {
// Two copies of the background image to scroll
private Background backOne;
private Background backTwo;
private BufferedImage back;
public ScrollingBackground() {
backOne = new Background();
backTwo = new Background(backOne.getImageWidth(), 0);
new Thread(this).start();
setVisible(true);
}
@Override
public void run() {
try {
while (true) {
Thread.currentThread().sleep(5);
repaint();
}
}
catch (Exception e) {}
}
@Override
public void update(Graphics window) {
paint(window);
}
public void paint(Graphics window) {
Graphics2D twoD = (Graphics2D)window;
if (back == null)
back = (BufferedImage)(createImage(getWidth(), getHeight()));
Graphics buffer = back.createGraphics();
backOne.draw(buffer);
backTwo.draw(buffer);
twoD.drawImage(back, null, 0, 0);
}
내부 사용. 둘째, 그래픽 영역이 지워지지 않기 때문에 줄무늬가 보이는 이유는 수동으로 다시 칠하기를 호출하면 캔버스가 지워지지 않기 때문입니다. 대신 update()를 사용해야합니다. –
을 '줄무늬'할 뜻 .. 당신은 아마 (칠 호출해서는 안 모든 – user2922456
우선)가 그이 정말로 무엇을 의미
–