原作者为 nikles,本文由 highway★负责翻译。

在玩过 Environmental Station Alpha之后,我也想实现 Hempuli(上句那个游戏的开发者)在他的游戏做出的效果。我不知道该如何实现,所有我不得不从头开始,思考不同的方法。

我对 shader(译注:着色器,如果你是初学者,还是敬而远之,对美术基础和数学还有编程的要求挺高的)一窍不通,所以只能用 surface 了。我写了一些代码,然后立刻撞墙……我有点儿懵逼,就去yoyogames 的论坛上求助,看了其他人的评论之后,我终于想出一个相当不错的解决办法。

none.gif
实际代码

在你的游戏控制 object(起名随意,比如 oGame、oCont 之类的)的 create 事件中,写下面的这些东西。

代码:
 

  1. // 名字缩写,方便后面用,要不然代码太长,看着费劲
  2. dw = display_get_width()
  3. dh = display_get_height()
  4.  
  5. tearings_surface = surface_create(dw, dh) // 我们要把这个绘制到 surface
  6. tearings_y = 0
  7. band_num = 16 // 屏幕上要出现多少个横条
  8. band_height = dh / band_num
  9. tearings_x_offset = 32 //你要怎样水平移动横条
  10. tearing_speed = 4 // 修改这里可以加速/减速

复制代码
I place the following code inside a draw_post event of my controller。下面这些东西写在刚才那个 object 的 draw_post 事件中。

代码(已修正):

 

 

  1. // 如果 surface 不存在便创建它
  2. if !surface_exists(tearings_surface)
  3. tearings_surface = surface_create(display_get_width(), display_get_height())
  4.  
  5. // 给 surface 设置目标
  6. surface_set_target(tearings_surface)
  7.  
  8. draw_clear_alpha(c_black, 0)
  9.  
  10. // 我们将部分应用 surface 绘制在撕裂 surface 上
  11. for (var current_band = 0; current_band < band_num * 2; current_band++)
  12. {
  13. draw_surface_part(application_surface, 0, band_height * current_band - tearings_y, dw, band_height, sin( (degtorad(360) / band_num ) * current_band) * tearings_x_offset , band_height * current_band - tearings_y)
  14. }
  15.  
  16. // 始终重置目标 surface
  17. surface_reset_target()
  18. // 绘制实际 surface
  19. draw_surface_stretched(tearings_surface, -tearings_x_offset, 0, dw + tearings_x_offset * 2, dh)
  20. // 移动撕裂
  21. tearings_y = (tearings_y + tearing_speed) % (band_height * band_num)
复制代码
我的做法就是这样~我还会再弄一个垂直撕裂的类似版本出来(水下关卡?没准儿~)希望这篇小文章对你有帮助。

关于 surface 的使用要注意:如果你不用的时候,请记住一定要释放 surface,否则会引起内存泄漏越来越卡或者可能崩溃。

via:indienova


锐亚教育

锐亚教育,游戏开发论坛|游戏制作人|游戏策划|游戏开发|独立游戏|游戏产业|游戏研发|游戏运营| unity|unity3d|unity3d官网|unity3d 教程|金融帝国3|8k8k8k|mcafee8.5i|游戏蛮牛|蛮牛 unity|蛮牛