2014-12-30 4 views
0

계속 오류가 계속 발생합니다. "함수 display()이 존재하지 않습니다. 난 그냥 미리 그려진 타원 대신에 내 자신의 이미지를 넣으려고합니다. 여기 내 코드는 다음과 같습니다.함수 display()가 존재하지 않습니다.

import processing.serial.*; 
import cc.arduino.*; 
import com.tinkerkit.*; 

Arduino arduino; 

//declare the button 
TKButton but; 
TKButton but1; 

{ 
    arduino = new Arduino(this, Arduino.list()[2], 57600); 
} 

PFont myFont; 

PImage ball1; 

int pScore; 

// don't touch em! 

int gameState; //0= pre game 1= in game 2= game over 

//setting up perimeter to contain ball character 
int width = 600; 
int height = 600; 

void setup() { 
    size(width, height); 
    smooth(); 

    //myFont = loadFont("MyFutura.vlw"); 
    //textFont(myFont); 
    gameState = 0; 
    ball1 = loadImage("ball.gif"); 
    pScore = 0; 
} 

{ 
    but = new TKButton(arduino, TK.I0); 

    but1 = new TKButton(arduino, TK.I1); 
} 

void draw() { 
    background(0); 

    if (gameState==0) { 
    fill(255, 255, 255, 70); 
    rect(-10, 30, 370, 70, 7); 

    fill(255, 255, 255, 70); 
    rect(-10, 120, 330, 50, 7); 

    fill(255); 
    textSize(60); 

    text("Ball Game", 30, 85); 
    textSize(40); 

    text("Press B to Start", 30, 157); 
    if (keyPressed && key == 'b') { 
     gameState = 1; 
    } 

    } 

    if (gameState == 2) { 
    fill(255, 255, 255, 70); 
    rect(-10, 30, 370, 70, 7); 

    fill(255, 255, 255, 70); 
    rect(-10, 120, 250, 50, 7); 
    fill(255, 255, 255, 70); 
    rect(-10, 190, 330, 50, 7); 

    fill(255); 
    textSize(50); 
    text("Final Score:", 20, 85); 
    text(pScore, 280, 85); 

    textSize(30); 
    text("Play Again?", 30, 157); 
    textSize(30); 
    text("Press R to Restart", 30, 225); 

    if (keyPressed && key == 'r') { 
     gameState = 0; 
     setup(); 
    } 

    } 

    ball1.display(); 
    ball1.keyPressed(); 
} 

void display() { 
    fill(255); 
    noStroke(); 
} 

void reset() { 
    ... 
} 

class ball1 { 
    float x; 
    float y; 
    float speed; 
    float r; //radius 
    color c = color(255, 20, 245); 

    ball1(float tempX, float tempY, float tempR) { 
    x = tempX; 
    y = tempY; 
    r = tempR; 
    speed = 0; 
    } 

    void change() { 
    c = color(random(255), random(220), random(245)); 
    } 

    void display() { 
    fill (c); 
    noStroke(); 
    ellipse(x, y, r, r); 
    } 

    //key commands 
    //ball flies off page in response to key command 
    void keyPressed() { 

    if (key == CODED) { 
    } 

    if (but.read()== TK.HIGH) { 
     x = x+5; 
     if (x >= width - 25) { 
     x = width - 25; 
     } 

     println(but.read()); 
    } else if (but1.read() == TK.HIGH) { 
     x = x-5; 
     if (x <= 25) { 
     x = 25; 
     } 

     println(but1.read()); 
    } 
    } 
} 

답변

0

귀하의 ball1 변수는 타입 PImage이다.

는 PImage 클래스는 표시() 메소드를 가지고 있지 않습니다. 그래서, 이름을 바꾸면

아마 당신의 ball1 변수는?를 ball1 클래스 내에서해야 당신의 Ball과 같은 무언가에 대한 수업 (다른 말로하면, st andard 명명 규칙을 사용하고 클래스와 변수에 동일한 이름을 사용하지 마십시오. 그런 다음 ball1 변수의 이름을 ballImage와 같이 정상적으로 변경하십시오. 그런 다음 Ball 클래스의 display() 함수에서 image (ballImage, x, y) 또는 다른 image() 함수 중 하나를 호출합니다.

추천 도서 :

https://processing.org/reference/PImage.html

https://processing.org/reference/image_.html

관련 문제