简体   繁体   English

栅格vs油漆(g),paintComponent(g)

[英]Raster vs paint(g) , paintComponent(g)

I'm a novice programmer and recently I came across many methods of animation: 我是一个新手程序员,最近我遇到了许多动画方法:

  1. Using BufferedImages , ie. 使用BufferedImages ,即。 draw to image and display using double buffering or triple buffering methods . 使用双缓冲或三缓冲方法绘制图像并显示。
  2. Making my sprites components by extending Component or Button . 通过扩展Component或Button使我的精灵组件成为组件。 and repainting by repaint(g) . 然后通过repaint(g)进行repaint(g)
  3. Rastering, using rasters and integer arrays, bitmaps and the like. 使用栅格和整数数组,位图等进行栅格化。

I realise that method 1 and 2 are similar as they use paint() methods , however Rastering involves self-made functions , eg. 我意识到方法1和2相似,因为它们使用paint()方法,但是光栅化涉及到一些自制函数,例如。 creating functions that set background by traversing the whole array representing each pixel and setting colour to desired colour . 通过遍历代表每个像素的整个数组并将颜色设置为所需颜色来创建设置背景的函数。

I've seen many folks online use raster methods even though 1 & 2 seem simpler . 我已经看到许多人在网上使用栅格方法, 即使 1&2看起来更简单。

Please help me out here guys and tell me what path i should follow and why . 请在这里帮助我,告诉我我应该走什么路,为什么。

The first and second methods are very similar and would come down to the context of the problem. 第一种和第二种方法非常相似,并且可以归结为问题所在。

The third option would, for the most part come down to providing a flexible API which was independent of the toolkit or framework which was to be used to dipslay it. 在大多数情况下,第三个选择是提供一种灵活的API,该API与用于浸渍的工具箱或框架无关。 One could argue that there is a speed increase, but with Swing and JavaFX working more directly with the DirectX and OpenGL pipelines, this is less of an issue. 有人可能会说速度有所提高,但是随着Swing和JavaFX更直接地与DirectX和OpenGL管道一起工作,这不再是问题。

Unless your planning on dong some seriously low level functionality or interfacing to a non-standard API I wouldn't worry to much about it (some effects painting might be faster done this way, but it's all about context) 除非您计划使用一些严重的低级功能或与非标准API接口,否则我不会对此担心很多(用这种方法可以更快地完成某些效果绘制,但这全都取决于上下文)

Personally, it would focus on developing an understanding of the basics and principles involved and how they might be implemented using the first two options as it allows you to focus on those concepts with a relatively easy API 就个人而言,它将着重于对所涉及的基本原理和原理的理解,以及如何使用前两个选项来实现它们,因为它使您可以使用相对简单的API来专注于这些概念。

As time progress or you come across a situation that can't be resolved using these techniques, then it might be time to consider playing with the rastering approach. 随着时间的推移,或者您遇到无法使用这些技术解决的情况,那么可能是时候考虑使用栅格化方法了。

Remember though, you still need to get that byte array into a format that the API wants which in of itself, will add overheads 不过请记住,您仍然需要将该字节数组转换为API想要的格式,该格式本身会增加开销

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

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