GameMaker Studio 2

创建于:2017-04-19

创建人: dougen

190 信息 1080 成员
游戏开发工具 GameMaker Studio 2 的讨论小组

在GMS2中使用Surfaces实现屏幕撕裂 / 波纹效果

highway★ 2018-03-07

作者:nikles

翻译:highway★

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

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

Image title

实际代码


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


代码:


// 名字缩写,方便后面用,要不然代码太长,看着费劲

dw = display_get_width()

dh = display_get_height()



tearings_surface = surface_create(dw, dh) // 我们要把这个绘制到surface

tearings_y = 0

band_num = 16 // 屏幕上要出现多少个横条

band_height = dh / band_num

tearings_x_offset = 32 //你要怎样水平移动横条

tearing_speed = 4 // 修改这里可以加速/减速





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



代码:

// 如果surface存在便创建它

if !surface_exists(tearings_surface)

tearings_surface = surface_create(display_get_width(), display_get_height())

// 给surface设置目标

surface_set_target(tearings_surface)

draw_clear_alpha(c_black, 0)

// 我们将部分应用surface绘制在撕裂surface上

for (var current_band = 0; current_band < band_num * 2; current_band++)

{

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)

}

// 始终重置目标surface

surface_reset_target()

// 绘制实际surface

draw_surface_stretched(tearings_surface, -tearings_x_offset, 0, dw + tearings_x_offset * 2, dh)

// 移动撕裂

tearings_y = (tearings_y + tearing_speed) % (band_height * band_num)



搞定.


我的做法就是这样~我还会再弄一个垂直撕裂的类似版本出来(水下关卡?没准儿~)希望这篇小文章对你有帮助。

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



(转发自:原日志地址

近期喜欢的会员

 

加入 indienova

  • 建立个人/工作室档案
  • 建立开发中的游戏档案
  • 关注个人/工作室动态
  • 寻找合作伙伴共同开发
  • 寻求线上发行
  • 更多服务……
登录/注册