【问题标题】:Eclipse and Processing PApplet ErrorEclipse 和处理 PApplet 错误
【发布时间】:2017-07-23 21:24:49
【问题描述】:

目前我正在尝试制作迷宫游戏。我只是试图加载精灵并让程序运行,但它无法正常工作并给我一条错误消息,说明: 用法:PApplet [选项] [草图参数] 有关说明,请参阅 PApplet 的 Javadoc。 我已经阅读了一些具有某种解决方案的答案,但是我不知道他们在说什么,因为我是一名 13 岁的初学者/中级程序员。这是给我错误消息的代码:

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;
        }
    }
}

如果您可以用相当简单的术语和简单的解决方案给出这个答案,请这样做。谢谢。

【问题讨论】:

    标签: java eclipse processing


    【解决方案1】:

    我猜您正在使用过时的教程?从处理 3 开始,PApplet 类不再扩展 Applet 类,因此您不能将其作为小程序运行。

    相反,您必须添加一个main() 方法,然后调用PApplet.runSketch()

    无耻的自我推销:我写了一篇关于将Processing用作Java库的教程here

    但是,如果您刚刚开始,您可能真的想在处理编辑器中花一些时间,然后再使用 Eclipse 进行更高级的编程。

    【讨论】:

    • 您网站上的代码是否仍然有效?我总是得到C:\Users\Norman\IdeaProjects\ProcessingGame\src\MySketch.java:3:8 java: cannot access android.app.Activity,并且我使用的代码与您网站上的(第一个)代码完全相同。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-08-01
    • 2020-08-04
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多