设为首页收藏本站|繁體中文

Project1

 找回密码
 注册会员
搜索
查看: 2244|回复: 9

[有事请教] 有关游戏窗口震动

[复制链接]

Lv3.寻梦者

梦石
0
星屑
2281
在线时间
403 小时
注册时间
2018-11-9
帖子
249
发表于 2019-1-15 16:34:22 | 显示全部楼层 |阅读模式

加入我们,或者,欢迎回来。

您需要 登录 才可以下载或查看,没有帐号?注册会员

x
本帖最后由 Niko_ 于 2019-1-15 16:34 编辑

在隔壁CSDN看到这样一个C程序:
C 代码复制
  1. #include <stdio.h>
  2. #include <windows.h>
  3. int main()
  4. {
  5.     RECT rect;//RECT是一个矩形结构体,相当于保存矩形边框的四个坐标
  6.     HWND hwnd = NULL, oldhwnd = NULL;//两个窗口句柄
  7.     int x, y, width, height;//保存窗口横纵坐标及高度,宽度
  8.     int i;
  9.     for (i = 0; i < 50; i++)
  10.     {
  11.         hwnd = GetForegroundWindow();//获取活动窗口句柄
  12.         if (hwnd != oldhwnd)
  13.         {
  14.             GetWindowRect(hwnd, &rect);//获取指定窗口位置
  15.             x = rect.left;
  16.             y = rect.top;
  17.             width = rect.right - x;
  18.             height = rect.bottom - y;
  19.  
  20.             oldhwnd = hwnd;//把刚刚获取的句柄保存起来
  21.         }
  22.  
  23.         MoveWindow(hwnd, x - 10, y, width, height, TRUE);
  24.         Sleep(5);
  25.         MoveWindow(hwnd, x - 10, y - 10, width, height, TRUE);
  26.         Sleep(5);
  27.         MoveWindow(hwnd, x, y - 10, width, height, TRUE);
  28.         Sleep(5);
  29.         MoveWindow(hwnd, x, y, width, height, TRUE);
  30.         Sleep(5);
  31.  
  32.     }
  33.     system("pause");
  34.     return 0;
  35. }

效果是窗口剧烈震动,震动幅度频率可以在代码里面调。
突然想到,RM有没有类似的插件或脚本,能达到类似游戏窗口而非游戏画面剧烈震动的效果。

附:原帖地址:https://blog.csdn.net/zgege/article/details/79380198
莫把湖面倒影,当作夜空繁星。所以大角鼠yesyes,kaka的力量无人能及!

Lv6.析梦学徒

老鹰

梦石
40
星屑
33382
在线时间
6549 小时
注册时间
2012-5-26
帖子
3178

极短24评委极短23参与极短22参与极短21评委老司机慢点开短篇十吟唱者组别冠军开拓者剧作品鉴家

发表于 2019-1-15 17:36:40 | 显示全部楼层
这代码挺耿直的,所以等大神来详细解释下 MoveWindow 函数的实际作用,是平滑移动窗口从当前位置到目的地,还是直接定位当前窗口到目的地

说起来,其实这和默认里事件的震动画面不是很像吗,只不过那里只修改了x值,是在x轴上的左右摇摆,而这里是做了一个正方形轨迹
回复 支持 反对

使用道具 举报

Lv4.逐梦者 (版主)

无限の剣制

梦石
0
星屑
9941
在线时间
5019 小时
注册时间
2013-2-28
帖子
5030

开拓者贵宾

发表于 2019-1-15 17:45:19 | 显示全部楼层
本帖最后由 VIPArcher 于 2019-1-15 17:55 编辑
  1. class Scene_Map < Scene_Base
  2.   FindWindowEx = Win32API.new('user32', 'FindWindowEx', 'llpp', 'i')
  3.   HWnd = FindWindowEx.call(0, 0, 'RGSS Player', 0)
  4.   SetWindowPos = Win32API.new('user32', 'SetWindowPos', 'liiiiip', 'i')
  5.   GetWindowRect = Win32API.new('user32','GetWindowRect',['l','p'],'i')
  6.   #--------------------------------------------------------------------------
  7.   # ● 更新画面
  8.   #--------------------------------------------------------------------------
  9.   alias _update update
  10.   def update
  11.     _update
  12.     update_shake if Input.trigger?(:A)
  13.   end
  14.   def update_shake
  15.     window_rect = "\0" * 16
  16.     GetWindowRect.call(HWnd, window_rect)
  17.     x,y,wr,wb = window_rect.unpack('llll')
  18.     w = wr - x
  19.     h = wb - y
  20.     time = 0
  21.     while time < 20
  22.       Graphics.update
  23.       time += 1
  24.       case time
  25.       when 0 then SetWindowPos.call(HWnd, 0, x - 10, y, w, h, 0)
  26.       when 5 then SetWindowPos.call(HWnd, 0, x - 10, y - 10, w, h, 0)
  27.       when 10 then SetWindowPos.call(HWnd, 0, x, y - 10, w, h, 0)
  28.       when 15 then SetWindowPos.call(HWnd, 0, x, y, w, h, 0)
  29.       end
  30.     end
  31.   end
  32. end
复制代码
虾鸡罢写一个用SetWindowPos来试试(
地图上按shift进行鬼畜

点评

吴迪  发表于 2019-1-15 18:54

评分

参与人数 1+1 收起 理由
guoxiaomi + 1 塞糖

查看全部评分

回复 支持 反对

使用道具 举报

Lv3.寻梦者

梦石
0
星屑
2281
在线时间
403 小时
注册时间
2018-11-9
帖子
249
 楼主| 发表于 2019-1-15 23:18:33 | 显示全部楼层
百里_飞柳 发表于 2019-1-15 17:36
这代码挺耿直的,所以等大神来详细解释下 MoveWindow 函数的实际作用,是平滑移动窗口从当前位置到目的地, ...

百度了一下:
MoveWindow( HWND hWnd, int X, int Y, int nWidth, int nHeight, BOOL bRepaint )
hWnd指定了窗口的句柄
x指定了CWnd的左边的新位置。
y指定了CWnd的顶部的新位置。
nWidth指定了CWnd的新宽度。
nHeight指定了CWnd的新高度。(这个函数还能改变窗口大小的)
BOOL bRepaint指定了是否要重画Cwnd。我刚刚测试了一下,如果把所有TRUE改成FALSE,就好像能达到直接定位当前窗口到目的地的效果。
————————————————————————————————————————————————————
这个程序思路的确和震动画面很想。只不过这里震动的是窗口,似乎比震动画面更加震撼(?)
莫把湖面倒影,当作夜空繁星。所以大角鼠yesyes,kaka的力量无人能及!
回复 支持 反对

使用道具 举报

Lv4.逐梦者 (版主)

无限の剣制

梦石
0
星屑
9941
在线时间
5019 小时
注册时间
2013-2-28
帖子
5030

开拓者贵宾

发表于 2019-1-16 00:16:53 | 显示全部楼层
本帖最后由 VIPArcher 于 2019-1-16 00:18 编辑
Niko_ 发表于 2019-1-15 23:18
百度了一下:
MoveWindow( HWND hWnd, int X, int Y, int nWidth, int nHeight, BOOL bRepaint )
hWnd指 ...


我看了一下,MoveWindow应该可以这样调用
  1. Win32API.new('user32', 'MoveWindow', 'llllll', 'l')
复制代码

那上面那个脚本里的SetWindowPos可以改成MoveWindow.call(HWnd, x,y,w,h,0)
x,y,w,h还是二楼那样取GetWindowRect

具体的你可以加组群 “API调教”来学学

点评

0.0好吧,我对这东西实在还不了解  发表于 2019-1-16 21:12
这楼只是打个比方呀,你要先MoveWindow=Win32API.new('user32', 'MoveWindow', 'llllll', 'l')  发表于 2019-1-16 19:31
报错:26行,发生NameError。uninitialized constant Scene_Map::MoveWindow  发表于 2019-1-16 17:23
回复 支持 反对

使用道具 举报

Lv3.寻梦者

梦石
0
星屑
2281
在线时间
403 小时
注册时间
2018-11-9
帖子
249
 楼主| 发表于 2019-1-16 17:08:14 | 显示全部楼层
VIPArcher 发表于 2019-1-15 17:45
虾鸡罢写一个用SetWindowPos来试试(
地图上按shift进行鬼畜

下午稍微改了一下:
  1. class Scene_Map < Scene_Base
  2.   FindWindowEx = Win32API.new('user32', 'FindWindowEx', 'llpp', 'i')
  3.   HWnd = FindWindowEx.call(0, 0, 'RGSS Player', 0)
  4.   SetWindowPos = Win32API.new('user32', 'SetWindowPos', 'liiiiip', 'i')
  5.   GetWindowRect = Win32API.new('user32','GetWindowRect',['l','p'],'i')
  6.   #--------------------------------------------------------------------------
  7.   # ● 更新画面
  8.   #--------------------------------------------------------------------------
  9.   alias _update update
  10.   def update
  11.     _update
  12.     update_shake if Input.trigger?(:A)
  13.   end
  14.   def update_shake
  15.     window_rect = "\0" * 16
  16.     GetWindowRect.call(HWnd, window_rect)
  17.     x,y,wr,wb = window_rect.unpack('llll')
  18.     w = wr - x
  19.     h = wb - y
  20.     time = 0
  21.     while time < 34
  22.       Graphics.update
  23.       time += 1
  24.       case time
  25.       when 0 then SetWindowPos.call(HWnd, 0, x - 50, y - 50, w, h, 0)
  26.       when 2 then SetWindowPos.call(HWnd, 0, x, y, w, h, 0)
  27.       when 4 then SetWindowPos.call(HWnd, 0, x , y - 50, w, h, 0)
  28.       when 6 then SetWindowPos.call(HWnd, 0, x, y, w, h, 0)
  29.       when 8 then SetWindowPos.call(HWnd, 0, x + 50, y - 50 , w, h, 0)
  30.       when 10 then SetWindowPos.call(HWnd, 0, x, y, w, h, 0)
  31.       when 12 then SetWindowPos.call(HWnd, 0, x + 50, y, w, h, 0)
  32.       when 14 then SetWindowPos.call(HWnd, 0, x, y, w, h, 0)
  33.       when 16 then SetWindowPos.call(HWnd, 0, x + 50, y + 50, w, h, 0)
  34.       when 20 then SetWindowPos.call(HWnd, 0, x, y, w, h, 0)
  35.       when 22 then SetWindowPos.call(HWnd, 0, x, y + 50, w, h, 0)
  36.       when 24 then SetWindowPos.call(HWnd, 0, x, y, w, h, 0)
  37.       when 26 then SetWindowPos.call(HWnd, 0, x - 50, y + 50, w, h, 0)
  38.       when 28 then SetWindowPos.call(HWnd, 0, x, y, w, h, 0)
  39.       when 30 then SetWindowPos.call(HWnd, 0, x - 50, y, w, h, 0)
  40.       when 32 then SetWindowPos.call(HWnd, 0, x, y, w, h, 0)
  41.       end
  42.     end
  43.   end
  44. end
复制代码

我是不是疯了?
莫把湖面倒影,当作夜空繁星。所以大角鼠yesyes,kaka的力量无人能及!
回复 支持 反对

使用道具 举报

您需要登录后才可以回帖 登录 | 注册会员

本版积分规则

拿上你的纸笔,建造一个属于你的梦想世界,加入吧。
 注册会员
找回密码

站长信箱:[email protected]|手机版|小黑屋|无图版|Project1游戏制作

GMT+8, 2024-4-19 08:10

Powered by Discuz! X3.1

© 2001-2013 Comsenz Inc.

快速回复 返回顶部 返回列表