0
導入圖像的方法我想創造方法進行//create textures
部分的縮短run()
,但如果我不和//import
部分作爲參數傳遞的圖像,然後調用它像:創建包含從文件
createTextures(texture, texture2,ballTextureImport, greenFlashImport, blueFlashImport);
drawGraphics方法看不到它們。
drawGraphics()
就是反覆add(everyParameter);
這裏的部分代碼裏面run()
:
// import
Image texture = getImage(getCodeBase(), "texture.png");
Image texture2 = getImage(getCodeBase(), "texture2.png");
Image ballTextureImport = getImage(getCodeBase(), "ballTexture.png");
Image greenFlashImport = getImage(getCodeBase(), "greenFlash.png");
Image blueFlashImport = getImage(getCodeBase(), "blueFlash.png");
// create textures
GImage paddleLeftTexture = new GImage(texture);
GImage paddleRightTexture = new GImage(texture2);
GImage ballTexture = new GImage(ballTextureImport);
GImage greenFlash = new GImage(greenFlashImport, -250, 0);
GImage blueFlash = new GImage(blueFlashImport, -250, 0);
paddleLeftTexture.setSize(WIDTH + 1, HEIGHT + 1);
paddleRightTexture.setSize(WIDTH + 1, HEIGHT + 1);
ballTexture.setSize(BALL_SIZE, BALL_SIZE);
greenFlash.setSize(100, 300);
blueFlash.setSize(100, 300);
// make objects
GOval ball = makeBall();
GRect paddleLeft = makePaddle();
GRect paddleRight = makePaddle();
drawGraphics(ball, paddleLeftTexture, paddleRightTexture, ballTexture,
greenFlash, blueFlash, counter, paddleLeft, paddleRight,
aiScore, playerScore);
從drawGraphics()
其餘參數在run()
之前創建和//make objects
,並期待罰款(不帶紅色下劃線)。