【发布时间】:2014-04-04 22:33:02
【问题描述】:
我想从 //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 中创建的,看起来很好(没有红色下划线)。
【问题讨论】: