本文介绍了OpenGL的2D游戏的问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我希望做一个游戏在2D蠕虫般的破坏地形,使用OpenGL。

I want to make a game with Worms-like destructible terrain in 2D, using OpenGL.

  • 什么是我们的最佳方法呢?
    • 在画每个像素的像素? (嗯,不是很好吗?)
    • 拥有世界作为纹理和操纵它(这可能吗?)
    • What is the best approach for this?
      • Draw pixel per pixel? (Uh, not good?)
      • Have the world as a texture and manipulate it (is that possible?)

      在此先感谢

      推荐答案

      思考方式蠕虫地形看,我想出了这个主意。但我不知道你将如何实现它在OpenGL。它更多的是一种分层的2D绘图方式。我张贴的主意。我模拟使用Paint.NET的办法。

      Thinking about the way Worms terrain looked, I came up with this idea. But I'm not sure how you would implement it in OpenGL. It's more of a layered 2D drawing approach. I'm posting the idea anyway. I've emulated the approach using Paint.NET.

      首先,你有一个背景天空层。

      First, you have a background sky layer.

      和你有一个地形图层。

      地形层被掩蔽所以顶端部分未被绘制。画在天空层之上的地形层,形成了现场。

      The terrain layer is masked so the top portion isn't drawn. Draw the terrain layer on top of the sky layer to form the scene.

      现在的主要思想。任何时间有爆炸或其他地形变形事件,绘制地形层上的圆形或其它形状,使用地形层本身作为图画掩模(以便重叠现有地形圆的仅一部分被画),消灭地形的一部分。使用透明/面具的颜色刷填充和一些颜色相似地形的粗笔。

      Now for the main idea. Any time there is an explosion or other terrain-deforming event, you draw a circle or other shape on the terrain layer, using the terrain layer itself as a drawing mask (so only the part of the circle that overlaps existing terrain is drawn), to wipe out part of the terrain. Use a transparent/mask-color brush for the fill and some color similar to the terrain for the thick pen.

      您可以重复此过程,添加更多的变形。你可以保留此层在内存中,因为它们发生增加变形或你甚至可以使它们在内存中每一帧如果没有太多的变形来呈现。

      You can repeat this process to add more deformations. You could keep this layer in memory and add deformations as they occur or you could even render them in memory each frame if there aren't too many deformations to render.

      这篇关于OpenGL的2D游戏的问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

05-24 06:10