简体   繁体   English

Pygame的打折顺序和透明度

[英]Pygame Blitting Order and Transparency

Having an issue with blitting order (I think) and transparent bounding boxes showing up during collisions. 碰撞顺序时出现笔迹排序问题(我认为),透明边框出现问题。

Link to the code and the issue is here: https://github.com/CastleSeven/flappy-balloon/issues/1 链接到代码,问题出在这里: https : //github.com/CastleSeven/flappy-balloon/issues/1

Basically, whenever a collision is about to occur, the player model is occluded by a transparent bounding box around the obstacle. 基本上,每当即将发生碰撞时,玩家模型都会被障碍周围的透明边界框所遮挡。 I'm not sure what I need to change so that JUST the non-transparent pixels are reblitted for the background on every loop. 我不确定我需要更改什么,以便仅在每个循环中为背景重新涂上非透明像素。

If I change the code so that the balloon blit comes AFTER the obstacle blit, I get the inverse effect, the balloon's bounding box occludes the obstacle. 如果我更改代码,以使气球blit在障碍物blit之后出现,我得到相反的效果,气球的边界框会遮挡障碍物。

Try using a colorkey, make the background of the textures something ugly like (255, 0, 255) and set the colorkey of the textures the same color. 尝试使用一个colorkey,使纹理的背景像(255,0,255)一样丑陋,然后将纹理的colorkey设置为相同的颜色。 https://www.pygame.org/docs/ref/surface.html#pygame.Surface.set_colorkey https://www.pygame.org/docs/ref/surface.html#pygame.Surface.set_colorkey

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

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