赞 | 2 |
VIP | 143 |
好人卡 | 1 |
积分 | 1 |
经验 | 216792 |
最后登录 | 2019-10-10 |
在线时间 | 24 小时 |
Lv1.梦旅人
- 梦石
- 0
- 星屑
- 61
- 在线时间
- 24 小时
- 注册时间
- 2008-8-5
- 帖子
- 1924
|
你用的是 FantasyDR 那个脚本么? FDR 用的是 MCI,MCI 本身就支持异步播放(默认模式),但是他为了实现同步而加了一个循环和计时机制……至于在某个区域播放,FDR 的脚本本身就支持,只不过只支持原始尺寸,不支持拉伸视频画面。你要在某个区域播放,说明你的视频尺寸没有占据整个窗口,那么直接选一个位置播放就行了
关于异步播放,我厚颜无耻地把 FDR 的脚本改了一下,给 MoviePlayer#play 新加了一个参数 sync,如果是 false 的话就表示异步播放视频,期间游戏继续运行- #==============================================================================
- # ☆★☆ AVI播放器 ☆★☆
- #------------------------------------------------------------------------------
- # - FantasyDR
- # - 2006.3.8
- #------------------------------------------------------------------------------
- # MSN: [email protected]
- #------------------------------------------------------------------------------
- # Note:
- #
- # 1.游戏必须使用游戏样板工程附带的RGSS102J.dll
- #
- # 2.在下方 PROJECT_NAME = 后面填写你的游戏工程名.
- #
- # 3.在游戏中,调用脚本事件播放你的视频文件,如果一行写不下可以在逗号后换行.
- #
- # $MP.play(movie_name, movie_length,
- # skip, fullscr,
- # x, y, width, height)
- #
- # 参数说明:
- #
- # movie_name : 视频文件名(*.avi),必须
- # movie_length : 电影时间,单位是秒,必须
- # skip : 是否可以按A键跳过,true/false,默认是true
- # fullscr : 是否强制为全屏幕播放,true/false,默认是false
- # x,y : 视频播放的左上角坐标,默认是0,0
- # width,height : 视频的宽度,可以任意.默认是640,480
- #
- # 例如:
- # $MP.play("logo.avi",13,false,true)
- #==============================================================================
-
- # ------------------------------------------------------------------------
- # 高精度计时器 by FantasyDR
- # ------------------------------------------------------------------------
- # E-mail: [email protected]
- # ------------------------------------------------------------------------
- # 2005.10.18
- # ------------------------------------------------------------------------
- # 该类已经被定义为全局变量 $sys_timer
- # 如果只需要精确到毫秒,请设置初始化参数为true
- # decimal属性设置返回时间值的小数位数。
- # ------------------------------------------------------------------------
- # 下面是一些有用的方法列表,调用时写:$sys_timer.方法名
- # 例如 $sys_timer.clear()
- # ------------------------------------------------------------------------
- # clear() :计时器清零
- # now() :获取当前经过的时间,单位毫秒
- # now_s() :获取当前经过的时间,单位秒
- # ------------------------------------------------------------------------
- class SystemTimer
- attr_accessor:decimal #小数位数设定,默认为3
-
- def initialize(use_GetTime=false)
- # 初始化,根据系统选择不同精度计时器
- @qpFrequency = Win32API.new("kernel32","QueryPerformanceFrequency",'p','L')
- @qpCounter = Win32API.new("kernel32","QueryPerformanceCounter",'p','L')
- @tGetTime = Win32API.new("winmm","timeGetTime",'','L')
-
- @decimal=3
- @perf_cnt=" " * 8
- @time_start=" " * 8
- @time_now=" " * 8
-
- result = @qpFrequency.call(@perf_cnt)
-
- if use_GetTime
- result = 0
- end
-
- if result!=0
- @perf_flag=true
- else
- @perf_flag=false
- @perf_cnt=[1000,0].pack('LL')
- end
-
- #设置时间比例因数
- @time_scale=@perf_cnt.unpack('LL')
- @time_scale[0] /= 1000.0
- @time_scale[1] /= 1000.0
-
- #起始时间清零
- self.clear()
- end
-
- #-=====================-#
- # 计时器清零
- #-=====================-#
- def clear()
- if @perf_flag
- @qpCounter.call(@time_start)
- else
- @time_start=[@tGetTime.call(),0].pack('LL')
- end
- end
-
- #-==============================-#
- # 获取当前经过的时间,单位毫秒
- #-==============================-#
- def now()
- now_time = 0.0e1
- now_time += self.timer() - self.start()
- now_time /= self.scale()
- return self.debug(now_time)
- end
-
- #-==============================-#
- # 获取当前经过的时间,单位秒
- #-==============================-#
- def now_s()
- now_time = 0.0e1
- now_time += self.timer() - self.start()
- now_time /= (self.scale()*1000)
- return self.debug(now_time)
- end
-
- #-==============================-#
- # 帧错...
- #-==============================-#
- def debug(now_time)
- if @decimal>0
- now_time = (now_time * (10**@decimal)).floor/(10.0**@decimal)
- else
- now_time = now_time.floor
- end
- return now_time
-
- #以下用于debug模式
- if now_time < 0
- p "Timer Wrong!! Clear...",now_time,\
- @perf_flag,@qpCounter,@tGetTime,
- @time_now.unpack('LL')[0],@time_now.unpack('LL')[1],
- @time_start.unpack('LL')[0],@time_start.unpack('LL')[1]
- self.clear()
- return 0.0
- else
- return now_time
- end
- end
-
- #-=====================-#
- # 获取时间比例因数
- #-=====================-#
- def scale()
- return @time_scale[0]+\
- @time_scale[1]*0xffffffff
- end
-
- #-=====================-#
- # 获取起始滴答数
- #-=====================-#
- def start()
- return @time_start.unpack('LL')[0]+\
- @time_start.unpack('LL')[1]*0xffffffff
- end
-
- #-=====================-#
- # 获取当前的嘀哒数
- #-=====================-#
- def timer()
- if @perf_flag
- @qpCounter.call(@time_now)
- else
- @time_now=[@tGetTime.call(),0].pack('LL')
- end
- return @time_now.unpack('LL')[0]+\
- @time_now.unpack('LL')[1]*0xffffffff
- end
- end
- #-------------------------------------#
- # 初始化自身成一个全局变量
- #-------------------------------------#
- $sys_timer=SystemTimer.new()
- #-------------------------------------#
-
- #==============================================================================
- # ☆★☆ AVI播放器 ☆★☆
- #------------------------------------------------------------------------------
- # - FantasyDR
- # - 2006.3.8
- #------------------------------------------------------------------------------
- # MSN: [email protected]
- #------------------------------------------------------------------------------
- # Note:
- #
- # 1.游戏必须使用游戏样板工程附带的RGSS102J.dll
- #
- # 2.在下方 PROJECT_NAME = 后面填写你的游戏工程名.
- #
- # 3.在游戏中,调用脚本事件播放你的视频文件,如果一行写不下可以在逗号后换行.
- #
- # $MP.play(movie_name, movie_length,
- # skip, fullscr,
- # x, y, width, height, loop)
- #
- # 参数说明:
- #
- # movie_name : 视频文件名(*.avi),必须
- # movie_length : 电影时间,单位是秒,必须
- # skip : 是否可以按A键跳过,true/false,默认是true
- # fullscr : 是否强制为全屏幕播放,true/false,默认是false
- # x,y : 视频播放的左上角坐标,默认是0,0
- # width,height : 视频的宽度,可以任意.默认是640,480
- # loop : 循环播放,true/false,默认是true
- #
- # 例如播放logo.avi,时间13秒,禁止跳过,强制全屏,范围(是0,0)-(640,480),循环播放
- # $MP.play("logo.avi",13,false,true)
- #==============================================================================
- # ★★★请先这里填写游戏的工程名★★★
- PROJECT_NAME = "Project1"
- #==============================================================================
- # ■ Win32API
- #------------------------------------------------------------------------------
- # 需要用到的API
- #==============================================================================
- # 切换到全屏延时
- SWITCH_DELAY = 0.1
- # API使用的一些常数
- WS_EX_TOPMOST = 0x8
- WS_EX_TOOLWINDOW= 0x80
- WS_VISIBLE = 0x10000000
- WS_POPUP = 0x80000000
- GWL_HINSTANCE = (-6)
- WM_CLOSE = 0x10
- WS_CHILD = 0x40000000
- WS_NONE = 0x16000000
- CP_ACP = 0
- CP_UTF8 = 65001
- # 字符编码转换API
- $MP_m2w = Win32API.new('kernel32', 'MultiByteToWideChar', '%w(i,l,p,i,p,i)', 'i')
- $MP_w2m = Win32API.new('kernel32', 'WideCharToMultiByte', '%w(i,l,p,i,p,i,p,p)', 'i')
-
- # 按键API
- $MP_keybd = Win32API.new('user32', 'keybd_event', '%w(i,i,l,l)', 'v')
- # 视频播放API
- $MP_mciSendString = Win32API.new('winmm','mciSendString','%w(p,p,l,l)','V')
- # 锁定窗口
- # hWnd,ifEnable
- $MP_EnableWindow = Win32API.new('user32','EnableWindow','%w(l,l)','L')
- # 激活窗口
- # hWnd
- $MP_SetActiveWindow = Win32API.new('user32','SetActiveWindow','%w(l)','L')
- # 当前活动窗口
- $MP_GetActiveWindow = Win32API.new('user32','GetActiveWindow','%w()','L')
- # hWnd,wMsg,wParam,lParam
- $MP_PostMessage = Win32API.new('user32','PostMessage','%w(l,l,l,p)','L')
- # 获取当前窗口句柄
- $MP_FindWindowEX = Win32API.new('user32','FindWindowEx','%w(l,l,p,p)','L')
- # 获取屏幕坐标
- $MP_ClientToScreen = Win32API.new("user32", "ClientToScreen", 'ip', 'i')
- # 获取hInt
- $MP_GetWindowLong= Win32API.new('user32','GetWindowLong','%w(l,l)','L')
- # 获取类名
- # hWnd,lpClassName,maxCount
- $MP_GetClassName= Win32API.new('user32','GetClassName','%w(l,p,l)','L')
- # 建立窗体
- # ExStyle,ClassName,WindowName,
- # style,x,y,width,height
- # 0,0,hInstance,0
- $MP_CreateWindowEX = Win32API.new('user32','CreateWindowEx','%w(l,p,p,l,l,l,l,l,l,l,l,p)','L')
- #==============================================================================
- # ■ MoviePlayer
- #------------------------------------------------------------------------------
- # 处理视频播放画面的类。
- #==============================================================================
- class MoviePlayer
- #--------------------------------------------------------------------------
- # ● 初始化
- # project_name : 工程名称
- #--------------------------------------------------------------------------
- def initialize(project_name = PROJECT_NAME)
- @sys_timer=SystemTimer.new()
- buffer = "\0\0" * project_name.size
- @project_name = "\0" * project_name.size
-
- $MP_m2w.call(CP_UTF8, 0, project_name, -1, buffer, project_name.size)
- $MP_w2m.call(CP_ACP,0,buffer,-1,@project_name,project_name.size,0,0)
-
- @hWnd = $MP_FindWindowEX.call(0,0,nil,@project_name)
- @hInt = $MP_GetWindowLong.call(@hWnd,GWL_HINSTANCE)
- @class_name = " " * 256
- $MP_GetClassName.call(@hWnd,@class_name,256)
- end
- #--------------------------------------------------------------------------
- # ● 是否已经全屏幕
- #--------------------------------------------------------------------------
- def is_full?
- # 播放起始坐标
- point = [0, 0].pack('ll')
- if $MP_ClientToScreen.call(@hWnd, point) == 0
- return false
- end
- x, y = point.unpack('ll')
- if x == 0 and y == 0
- return true
- else
- return false
- end
- end
- #--------------------------------------------------------------------------
- # ● 切换全屏
- #--------------------------------------------------------------------------
- def switch_full
- $MP_keybd.call (0xA4, 0, 0, 0)
- $MP_keybd.call (13, 0, 0, 0)
- $MP_keybd.call (13, 0, 2, 0)
- $MP_keybd.call (0xA4, 0, 2, 0)
- Graphics.update
- sleep(SWITCH_DELAY)
- Graphics.update
- end
- #--------------------------------------------------------------------------
- # ● 播放电影
- # movie_name : 视频文件名(*.avi)
- # movie_length : 电影时间,单位是秒
- # skip : 是否可以按键跳过
- # fullscr : 是否强制为全屏幕播放
- # x,y,width,height: 播放的位置以及宽度
- # loop : 循环播放
- # sync : 同步播放
- #--------------------------------------------------------------------------
- def play(movie_name,movie_length,
- skip = true,fullscr = false,
- x = 0,y = 0,width = 640,height = 480,loop = true, sync = true)
- # 数据不合法则退出
- return true if movie_name == nil or movie_length <= 0
- # 文件不存在
- movie_name = Dir.getwd()+"\\"+movie_name
- return true unless FileTest.exist?(movie_name)
- # 窗口宽度
- width -= (x + width)- 640 if (x + width) > 640
- height -= (y + height)- 480 if (y + height) > 480
-
- if fullscr and !is_full?
- self.switch_full
- end
-
- fullscr = self.is_full?
-
- # 播放起始坐标
- point = [x, y].pack('ll')
- if $MP_ClientToScreen.call(@hWnd, point) == 0
- return true
- end
- x, y = point.unpack('ll')
- return true if (x + width) < 0 or (y+height) < 0
-
- if fullscr
- wnd = $MP_CreateWindowEX.call(WS_EX_TOPMOST,@class_name,@project_name,
- WS_VISIBLE | WS_POPUP,x,y,width,height,
- 0,0,@hInt,0)
- else
- wnd = $MP_CreateWindowEX.call(WS_EX_TOOLWINDOW,@class_name,@project_name,
- WS_VISIBLE | WS_POPUP,x,y,width,height,
- 0,0,@hInt,0)
- end
- # 窗体建立失败
- return true if wnd == 0
-
- # 屏蔽原窗体
- $MP_EnableWindow.call(@hWnd,0)
-
- $MP_mciSendString.call("open \"" + movie_name + "\"" +
- " alias FILE style 1073741824 parent " +\
- wnd.to_s,0,0,0)
- if loop
- $MP_mciSendString.call("play FILE repeat window",0,0,0)
- else
- $MP_mciSendString.call("play FILE window",0,0,0)
- end
-
- playing = Proc.new {
- @sys_timer.clear()
- step = 0.1
- begin
- loop do
- # 如果在窗口模式
- unless fullscr
- # 变成全屏
- if self.is_full?
- break
- elsif sync
- Graphics.update
- end
- end
- #sleep(step)
- if skip
- Input.update
- break if Input.trigger?(Input::A)
- end
- if @sys_timer.now_s >= movie_length
- break
- end
- if sync && $MP_GetActiveWindow.call() != wnd
- $MP_SetActiveWindow.call(wnd)
- end
- end
- rescue Hangup
- retry
- end
- # 关闭当前窗体
- $MP_PostMessage.call(wnd,WM_CLOSE,0,0)
- $MP_mciSendString.call("close FILE",0,0,0)
- $MP_EnableWindow.call(@hWnd,1)
- $MP_SetActiveWindow.call(@hWnd)
- }
-
- sync ? playing.call : Thread.new { playing.call }
-
- return true
- end
- end
- $MP = MoviePlayer.new
复制代码 然后调用
$MP.play("split.avi",10, true, false, 10, 10, 320, 240, false, true)
参数分别是:
# movie_name : 视频文件名(*.avi),必须
# movie_length : 电影时间,单位是秒,必须
# skip : 是否可以按A键跳过,true/false,默认是true
# fullscr : 是否强制为全屏幕播放,true/false,默认是false
# x,y : 视频播放的左上角坐标,默认是0,0
# width,height : 视频的宽度,可以任意.默认是640,480
# sync : 是否同步播放 |
评分
-
查看全部评分
|