简体   繁体   English

在Java中的游戏fps刻度中调用Paint方法

[英]Call paint method in the game fps tick in java

How do i call for my paint method to draw everything inside it withing my thick method that runs 60 times per second. 我该如何要求我的paint方法使用每秒运行60次的thick方法来绘制其中的所有内容。

this is the fps calculation : 这是fps的计算:

int FRAMES_PER_SECOND = 60;
    long maxWorkingTimePerFrame = 1000 / FRAMES_PER_SECOND;  //this is optional
    long lastStartTime = System.currentTimeMillis();

    while(true)
    {
        lastStartTime = System.currentTimeMillis();

            Tick();

        long processingTimeForCurrentFrame = System.currentTimeMillis() - lastStartTime;
        if(processingTimeForCurrentFrame  < maxWorkingTimePerFrame)
        {
            try
            {
                Thread.sleep(maxWorkingTimePerFrame - processingTimeForCurrentFrame);
            }
            catch(Exception e)
            {
                System.err.println("TSEngine :: run :: " + e);
            }
        }
    }

so how do i call : 所以我怎么称呼:

public void paint( Graphics g ) {

}

in my Tick method? 用我的勾号方法?

To call the paint() method in your Tick method, you need to call the repaint() method. 要在Tick方法中调用paint()方法,您需要调用repaint()方法。 In your loop, just add repaint() when you want your component to call the paint method that you wrote. 在循环中,当您希望组件调用您编写的paint方法时,只需添加repaint()即可。

Read this article, as it explains a little bit how painting and repainting work. 阅读本文,因为它稍微解释了绘画和重新绘画的工作方式。 http://www.scs.ryerson.ca/~mes/courses/cps530/programs/threads/Repaint/index.html . http://www.scs.ryerson.ca/~mes/courses/cps530/programs/threads/Repaint/index.html

Here is an article demonstrating how to call repaint. 这是一篇演示如何调用重绘的文章。 http://www.scs.ryerson.ca/~mes/courses/cps530/programs/threads/Repaint/RepaintApplet3.java http://www.scs.ryerson.ca/~mes/courses/cps530/programs/threads/Repaint/RepaintApplet3.java

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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