2017-06-17 69 views
0

嗨,我是編程新手,雖然我試圖做一個練習,這個錯誤加劇了,我不知道它是什麼意思,以及如何解決它。 這是processing.js庫中的一個例子,在我嘗試複製之後並沒有那麼順利。該方法的返回類型缺少processing.js

Mover mover; 

    void setup(){ 
     size (600,600); 
     mover = new Mover(); 
    } 

    void draw(){ 
     mover.update(); 
     mover.display(); 
     mover.checkEdges(); 

    } 
    class Mover { 

    // position, velocity, and acceleration 
    PVector position; 
    PVector velocity; 
    PVector acceleration; 

    // Mass is tied to size 
    float mass; 

    Mover(float m, float x, float y) { //<<<the error occurs here 
    mass = m; 
    position = new PVector(x, y); 
    velocity = new PVector(0, 0); 
    acceleration = new PVector(0, 0); 
    } 

    // Newton's 2nd law: F = M * A 
    // or A = F/M 
    void applyForce(PVector force) { 
    // Divide by mass 
    PVector f = PVector.div(force, mass); 
    // Accumulate all forces in acceleration 
    acceleration.add(f); 
    } 

    void update() { 

    // Velocity changes according to acceleration 
    velocity.add(acceleration); 
    // position changes by velocity 
    position.add(velocity); 
    // We must clear acceleration each frame 
    acceleration.mult(0); 
    } 

    // Draw Mover 
    void display() { 
    stroke(255); 
    strokeWeight(2); 
    fill(255, 200); 
    ellipse(position.x, position.y, mass*16, mass*16); 
    } 

    // Bounce off bottom of window 
    void checkEdges() { 
    if (position.y > height) { 
     velocity.y *= -0.9; // A little dampening when hitting the bottom 
     position.y = height; 
    } 
    } 
} 

回答

0

我在你的代碼中看到的唯一的問題是,你的Mover構造函數有三個參數,但你不給它任何在這一行:

mover = new Mover(); 

所以我修復在任何其他事情之前的錯誤如果您仍然遇到問題,請更具體地瞭解您如何編譯和運行此代碼。你在使用Processing編輯器嗎?哪個版本?在哪一步你會得到一個錯誤?