首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >为什么会出现一个空画布而不是我的图像?

为什么会出现一个空画布而不是我的图像?
EN

Stack Overflow用户
提问于 2013-09-29 00:07:11
回答 2查看 83关注 0票数 0

我正在编写一个游戏,我希望在进入游戏本身之前,有大约3-5秒的公司标志。下面是我的代码:

代码语言:javascript
复制
Graphics gfx = buffer.getDrawGraphics();
    gfx.setColor(new Color(146, 17, 189));
    gfx.fillRect(0, 0, this.getWidth(), this.getHeight());
    // Draw stuffs between here...
    gfx.drawImage(icon.getImage(), 0, 0, this.getWidth(), this.getHeight(), null);
    int timer = 0;
    while (timer <= 4) {
        try {
            Thread.sleep(1000);
        } catch (InterruptedException exc) {
            exc.printStackTrace();
            System.out.println("Could not put thread to sleep! :(");
        }
        timer++;
    }
    gfx.drawImage(image, 0, 0, this.getWidth(), this.getHeight(), null);
    if (key.showFPS == true) {
        //Set it up so that it still works with the "per second" rule.
        key.showPerSeconds(buffer, FPS, TPS);
    }
    // and here.
    gfx.dispose();
    buffer.show();
}

我的主要问题是出现一个空白的JFrame,然后在4秒后,游戏本身就会出现。我的代码出了什么问题?是不是有什么我现在不应该做的事情?

EN

回答 2

Stack Overflow用户

发布于 2013-09-29 00:08:38

绘制完整的JFrame需要4秒,因为您在代码中有4秒的休眠时间:

代码语言:javascript
复制
while (timer <= 4) {
        try {
            Thread.sleep(1000);
票数 0
EN

Stack Overflow用户

发布于 2013-09-29 00:10:58

这个问题可能存在于Thread.sleep的while循环之后的图像变量中。

代码语言:javascript
复制
gfx.drawImage(image, 0, 0, this.getWidth(), this.getHeight(), null); 

此图像使您的框架空白。

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/19068873

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档