在(桌面)屏幕上绘制形状变化的对象
我目前正在开发一个程序来在桌面屏幕上显示和控制动画精灵。我现在的问题是将它们实际绘制到屏幕上。只要精灵不阻碍用户,用户就应该仍然能够访问其他应用程序。
我的尝试如下,我希望有人能指出我正确的方向。我并不关心需要使用哪个库,只要性能对于 20-30 个动画精灵来说足够好即可。
到目前为止我的尝试:
我的第一次尝试是使用 Qt。我使用了带有 QLabel 的 QWidget 来显示对象的像素图。 pixmap 本身有一个 Alpha 通道,我使用 QWidget 的“setMask(pixmap.mask()”方法来删除我不想显示的任何内容。但是此方法不能用于快速移动的形状,例如移动的生物如果在 50-100ms 内调用 setMask 将掩码更改为下一个运动阶段,那么 CPU 负载就会很高,并且有很多生物同时移动。
- 每个生物调用一次。这样可以移动更多生物,但屏幕会像地狱一样闪烁。将鼠标指针移到生物上时。
我的第三次尝试是使用 Xlib 中的 XShape 函数来改变每个生物的形状,但性能并不比 setMask 好多少。
我尝试了 Qt 中的透明度,但如果我在整个屏幕上使用 QWidget,则移动鼠标时 X 的 cpu 负载会变得非常高。我不知道,我是否可以在这里做得更好。
I'm currently developing a program to show and control animated sprites on the desktopscreen. My problem is now to actually draw them onto the screen. The user should still be able to access other applications, as long as the sprite does not obstruct it.
My attempts are below and I hope, someone can point me in the right direction. I don't really care which library I need to use, as long as the performance is good enough for something around 20-30 animated sprites.
My attempts so far:
My first attempt was with Qt. I used a QWidget with a QLabel in it to show the pixmap of an object. The pixmap itself had an alpha channel and I used the "setMask(pixmap.mask()" method of QWidget to remove anything I don't want to show. But this method can't be used for rapidly shifting shapes, like moving creatures. If setMask is called all 50-100ms to change the mask to the next movementphase, then the cpu load gets to high with a lot of creatures moving at the same time.
My second attempt was to use one QWidget for all creatures. This way setMask ist called only one time and not once for every creature. It's possible to move more creatures this way, but the screen is flickering like hell when moving the mouse pointer over the creatures.
My third attempt were the XShape functions from Xlib to change the shape of each creature, but the performance is not much better then setMask.
I tried the transparency in Qt but if I use a QWidget over the whole screen the cpu load of X gets really high while moving the mouse. I don't know, if I can do something better here.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
创建一个 QGLWidget 并学习使用 OpenGL API 在其中绘制精灵,即使只使用 glDrawPixels 而不是纹理对象。
绘制几十个精灵肯定不会有任何问题,如果您将来渴望做更复杂的图形事情,那么花在学习 OpenGL 上的时间将是一项很好的投资。
Create a QGLWidget and learn to use the OpenGL API to draw sprites within it, even if only using glDrawPixels rather than texture objects.
You certainly won't have any problems drawing a few tens of sprites, and the time spent learning OpenGL will be a good investment if you aspire to do more complex graphical things in future.
不确定这是否是您的语言,但 ESheep 位于 GitHub 上,可以帮助您入门:https://github.com /Adrianotiger/desktopPet
Not sure if this is your language but the ESheep is on GitHub, could get you started: https://github.com/Adrianotiger/desktopPet