简体   繁体   中英

Eclipse and Processing PApplet Error

Currently I am trying to make a maze game. I am simply trying to load in the sprites and get the program going but it is not working correctly and giving me an error message stating: Usage: PApplet [options] [sketch args] See the Javadoc for PApplet for an explanation. I have read up some answers that have some sort of solution, however I have no idea what they are talking about since I am a 13 year old beginner/intermediate programmer. Here is my code that is giving me the error message:

package MegaPackage;
import java.util.*;
import processing.core.PApplet;
import processing.core.PImage;
//Main method. Insert public variables and entities here.
public class FlatShooter extends PApplet {
PImage background;
PImage squareImage;
PImage life1Image;
PImage life2Image;
PImage life3Image;
PImage redEnemyImage;
public float xSpeedPlayer = 9;
public int score;
public int enemies;
public int lives;
public boolean moving = false;
public boolean moving2 = false;
public Square square;
public void setup(){
    size(900, 900);
    background=loadImage("background.jpeg");
    squareImage=loadImage("player.png");
    life1Image=loadImage("life.png");
    life2Image=loadImage("life.png");
    life3Image=loadImage("life.png");
    square = new Square(squareImage, (width-100)/2, height * 4/5);
}
//Movement for player and other items
public void keyPressed(){
    if( key == 'd' || key == 'D'){
        moving = true;
    }
    if(key == 'a' || key == 'A'){
        moving2 = true;
    }
}
//Stopping movement for players and other items
public void keyReleased(){
    if( key == 'd' || key == 'D'){
        moving = false;
    }
    if(key == 'a' || key == 'A'){
        moving2 = false;
    }
}
public class Square{
    PImage square;
    float xPos;
    float yPos;     
    public Square(PImage squareImage, float startX, float startY){
        square=squareImage;
        xPos=startX;
        yPos=startY;
    }
public void drawSquare(){
    image(square, xPos, yPos);
}
}
public void move(float x, float y){
    if(moving){
        x += xSpeedPlayer;
    }
    if (moving2){
        x-= xSpeedPlayer;
        }
    }
}

If you can give this answer in fairly simple terms and an easy solution please do so. Thank you.

I'm guessing you're working from an outdated tutorial? As of Processing 3, the PApplet class no longer extends the Applet class, so you can't run it as an applet.

Instead, you have to add a main() method that then calls PApplet.runSketch() .

Shameless self-promotion: I wrote a tutorial on using Processing as a Java library available here .

But if you're just starting out, you really might want to spend some time in the Processing editor before jumping to more advanced programming using Eclipse.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM