将Canvas和JPanel用于2D游戏引擎(和缓冲?)之间的区别 [英] Difference between using Canvas and JPanel for a 2D game engine (and Buffering?)

查看:111
本文介绍了将Canvas和JPanel用于2D游戏引擎(和缓冲?)之间的区别的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我从各种教程中学到了如何在JFrame上使用Canvas来渲染2D游戏引擎的图像。我必须创建一个BufferStrategy来保持图像平滑等,但是最近我听说使用JPanel来渲染图像。我应该使用JPanel吗?如果是这样,我还是需要创建一个BufferStrategy还是将其集成。我是不是真的误会了我,甚至说得通吗?我是一个初学者,请随时尝试纠正我并指导我-由于某些原因,我对此不知所措:P谢谢。

I learned from various tutorials to use a Canvas on top of a JFrame to render images for a 2D Game Engine. I had to create a BufferStrategy to keep the image smooth and such, but recently I've heard using a JPanel instead to render images. Should I use JPanel? If so, do I still need to create a BufferStrategy or is it integrated. Am I just really misinformed and am I even making sense? I'm a beginner so feel free to try to correct me and guide me- I am very overwhelmed with this for some reason :P Thanks.

推荐答案

BufferedStrategy



使用活动绘画。它使您可以直接控制何时涂漆

BufferedStrategy

Uses "active painting". It gives you direct control over when something gets painted


  • 可以更好地控制帧速率

  • 具有低级别的连接,并且可以访问硬件加速

使用被动绘画。有一个 RepaintManager 可以控制何时以及什么时间绘制内容,将其发布到事件调度线程上,并与所有其他事件一起进行处理。

Uses "passive painting". There is a RepaintManager which is in control of scheduling when and what gets painted, this is posted onto the Event Dispatching Thread and get's processed along with all the other events.


  • 不直接控制绘画系统

  • 可变帧速率

通过同一渲染管道链接,通常是DirectX或OpenGL

Are linked through the same rendering pipeline, typically this is either DirectX or OpenGL

取决于。大多数游戏引擎必须以 Canvas 开头,因为这通常是将Java链接到底层渲染引擎的唯一方法。大多数游戏引擎都是DirectX或OpenGL上的低级本地绑定或轻量包装,使您可以直接(间接)访问这些API。

Depends. Most game engines HAVE to start with a Canvas, as this is generally the only way to link Java to the underlying rendering engine. Most game engines are low level native bindings or light wraps over DirectX or OpenGL, giving you access to those APIs (in)directly

一些引擎可能仍直接使用Swing,但它们会受到限制,并且可能适用于不需要3D或高/一致帧频的情况。

A few engines may still use Swing directly, but they would be limited and may be intended for situations where you don't need 3D or a high/consistent frame rate.

这是个人观点。您需要恒定的帧频吗?您想做3D还是2D够?您是否要执行低级功能(纹理处理等)?

This is a matter of personal opinion. Do you need a constant frame rate? Do you want to do 3D or is 2D enough? Do you want to perform low level functionality (texture manipulation etc)?

  • Passive vs. Active Rendering
  • Painting in AWT and Swing

这篇关于将Canvas和JPanel用于2D游戏引擎(和缓冲?)之间的区别的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆