小编Der*_*rek的帖子

如何生成纹理以适应形状?

我有一个随机生成的EdgeShapes系列,如下所示:

在此输入图像描述

我的问题是,如何用纹理填充底部区域以使其看起来像地面?

textures box2d libgdx

7
推荐指数
1
解决办法
1323
查看次数

对于GWT中的System类型,方法nanoTime()未定义

在eclipse中编译我的libgdx应用程序时,我不断收到此错误:

 [ERROR] Errors in 'file:/C:/Users/Zorfie/Programing/Java/workspace/Libgdx/src/sim/states/BasicBox2DState.java'
      [ERROR] Line 157:  The method nanoTime() is undefined for the type System
      [ERROR] Line 159:  The method nanoTime() is undefined for the type System
      [ERROR] Line 160:  The method nanoTime() is undefined for the type System
      [ERROR] Line 161:  The method nanoTime() is undefined for the type System
   [ERROR] Errors in 'jar:file:/C:/Program%20Files/eclipse/plugins/com.google.gwt.eclipse.sdkbundle_2.4.0.v201203300216-rel-r37/gwt-2.4.0/gwt-user.jar!/com/google/web/bindery/autobean/shared/impl/StringQuoter.java'
      [ERROR] Line 21:  The import org.json cannot be resolved
      [ERROR] Line 69:  JSONObject cannot be resolved
   [ERROR] Errors in 'jar:file:/C:/Program%20Files/eclipse/plugins/com.google.gwt.eclipse.sdkbundle_2.4.0.v201203300216-rel-r37/gwt-2.4.0/gwt-user.jar!/com/google/web/bindery/autobean/vm/impl/JsonSplittable.java'
      [ERROR] Line 23: …
Run Code Online (Sandbox Code Playgroud)

gwt

7
推荐指数
1
解决办法
2038
查看次数

如何在文本字段中等待输入?

我正在将控制台应用程序转换为使用Swing的控制台应用程序.目前我希望我的程序能够做到类似的事情,.nextInt();我怎么能通过使用.getText();或类似的东西来实现这一点?

简而言之;

如何保持程序的执行,直到用户在文本字段中输入内容并按下回车键.

java applet

6
推荐指数
1
解决办法
7005
查看次数

将像素坐标应用于屏幕坐标

我试图让一个物体出现在最后一个人触摸的地方.但是,当我尝试这样做时,它出现在错误的地方.我假设这是因为输入返回的坐标与显示坐标不同,我的代码如下:

public class Core implements ApplicationListener, InputProcessor
          { //Has to be here otherwise the code formatting becomes buggy


private Mesh squareMesh;
private PerspectiveCamera camera;
private Texture texture;
private SpriteBatch spriteBatch;
Sprite sprite;
float moveX = 0;


private final Matrix4 viewMatrix = new Matrix4();
private final Matrix4 transformMatrix = new Matrix4();

@Override
public void create()
{
    Gdx.input.setInputProcessor(this);


    texture = new Texture(Gdx.files.internal("door.png"));

    spriteBatch = new SpriteBatch();
    sprite = new Sprite(texture);
    sprite.setPosition(0, 0);
    viewMatrix.setToOrtho2D(0, 0, 480, 320);

    float x = 0;
    float y …
Run Code Online (Sandbox Code Playgroud)

java libgdx

5
推荐指数
1
解决办法
8593
查看次数

如果在while true循环中有System.out.println(),则线程只能正确运行

基本上,我正在制作一个更新玩家位置的游戏,它使用这个帖子:

@Override
public void run() {
    while(true) {
        System.out.println();
        updatePos(x, y);
    }

}
Run Code Online (Sandbox Code Playgroud)

哪个工作正常,但如果我删除System.out.println(),它就会停止运行.我不知道为什么会这样,全班如下:

public class Player extends Block implements KeyListener, Runnable {

int x;
int y;
int speed;

boolean upPressed; 
boolean downPressed;
boolean rightPressed;
boolean leftPressed;

static Sprite sprite = new Sprite("grass.png");

public Player(int x, int y, int speed) {
    super(x, y, sprite);
    this.x = x;
    this.y = y;
    this.speed = speed;
    Thread playerThread = new Thread(this, "Player Thread");
    playerThread.start();
}

@Override
public void keyPressed(KeyEvent e) {
    if (e.getKeyCode() …
Run Code Online (Sandbox Code Playgroud)

java multithreading

3
推荐指数
1
解决办法
1728
查看次数

如何在谷歌应用引擎上托管小程序?

我已经下载了eclipse的google插件,以及必要的app引擎.现在的问题是,是否可以使用谷歌应用引擎托管预制的小程序,如果是,如何?

java google-app-engine applet

1
推荐指数
1
解决办法
1111
查看次数

在定义变量之前访问变量的问题

我有这个:

public class Sprite

{
    protected float x;
    protected float y;
    protected Image image;
    protected Rectangle boundingBox;


    public Rectangle getBoundingBox()
    {
         boundingBox = new Rectangle(x, y,
                    image.getWidth(), image.getHeight());
        return boundingBox;
    }
Run Code Online (Sandbox Code Playgroud)

但是,当我运行它时,我得到一个空指针异常.类精灵从不单独使用,仅用作超类.

定义图像的唯一方法是通过构造函数:

Sprite(float x, float y, Image image) {
    this.x = x;
    this.y = y;
    this.image = image;
}
Run Code Online (Sandbox Code Playgroud)

java initialization

1
推荐指数
1
解决办法
93
查看次数

可以在openGL中"查看"对象

在此输入图像描述

我不确定为什么会这样,我只渲染一些简单的原始QUADS.红色意味着在黄色的前面.

黄色总是在红色前面,即使它在它后面.

这是一个错误还是只是我错误地看到了立方体?

opengl

1
推荐指数
1
解决办法
3854
查看次数

无法设置列表的元素

我在lisp上很新,我正在尝试制作一个基本的国际象棋游戏,但是我似乎在第一个障碍时失败了.每次我尝试运行该函数时(move... )都会收到错误:

*** - FUNCTION: undefined function (SETF GET-ELEMENT)
Run Code Online (Sandbox Code Playgroud)

这是代码:

(defparameter *board* '(
                       (? ? ? ? ? ? ? ?)
                       (? ? ? ? ? ? ? ?)
                       (? ? ? ? ? ? ? ?)
                       (? ? ? ? ? ? ? ?)
                       (? ? ? ? ? ? ? ?)
                       (? ? ? ? ? ? ? ?)
                       (? ? ? ? ? ? ? ?)
                       (? ? ? ? ? ? ? ?)
                       )) …
Run Code Online (Sandbox Code Playgroud)

common-lisp

1
推荐指数
1
解决办法
270
查看次数

为什么这会导致空指针异常?

我有这个代码:

public class Sprite {
    protected float x;
    protected float y;
    protected Image image;
    protected Rectangle boundingBox;

    Sprite(float x, float y, Image image) {
        this.x = x;
        this.y = y;
        this.image = image;
        boundingBox = new Rectangle(x, y, 
            this.image.getWidth(), this.image.getHeight());
    }
Run Code Online (Sandbox Code Playgroud)

...

public Rectangle getBoundingBox() {
    return boundingBox;
}
Run Code Online (Sandbox Code Playgroud)

但是,一旦定义并初始化了sprite对象,我在另一个类中调用此函数时:

public static boolean collides(Sprite object1, Sprite object2) {
    return object1.getBoundingBox().intersects(object2.getBoundingBox());
}
Run Code Online (Sandbox Code Playgroud)

我得到一个空指针异常,指向包含这个的行:

this.image.getWidth(), this.image.getHeight());
Run Code Online (Sandbox Code Playgroud)

为什么是这样?

java initialization

0
推荐指数
1
解决办法
752
查看次数