영상

avi 동영상 실행 스크립트

by 백호 posted Feb 21, 2009
?

단축키

Prev이전 문서

Next다음 문서

ESC닫기

크게 작게 위로 아래로 댓글로 가기 인쇄
class Scene_Movie

 def initialize(movie,length)
  @movie_name = Dir.getwd()+"\Movies\"+movie+".avi"
  @counter = length
 end
 
 def main
   
  Graphics.transition
  @wnd = Win32API.new('user32','FindWindowEx','%w(l,l,p,p)','L')
  @temp = @wnd.call(0,0,nil,"Scripts").to_s
  @movie = Win32API.new('winmm','mciSendString','%w(p,p,l,l)','V')
  @movie.call("open ""+@movie_name+"" alias FILE style 1073741824 parent " + @temp.to_s,0,0,0)
  @movie.call("play FILE",0,0,0)
  loop do
    Graphics.update
    sleep(1)
    Input.update
    if Input.trigger?(Input::B)
      break
    end
    @counter = @counter - 1
    if @counter == 0
      break
    end
  end
  @movie.call("close FILE",0,0,0)
  $scene = Scene_Map.new
  Graphics.freeze
 end
end

avi 확장자 동영상만 가능하며
경로는 Yourgame/movies 안에 넣어주시고요.
불러오는 거는 $scene = Scene_Movie.new("File name",5)
이내요;;
제가 해보니까 오류 뜨던데;; 수정하면 먹힐듯;;

이거 주의사항인 것 같은데 누구 번역좀;;
Copy this into a new section of your game. To play a file, move the avi file into a "movies" subdirectory (yourgamedata, yourgamegraphics, yourgamemovies). Then call "$scene = Scene_Movie.new(filename,length)" where filename is your movies actual filename (minus the .avi) and length is the playtime in seconds.

Example: My games path is "C:game". I create a folder in "C:game" called movies. I then move my movie, called "intro.avi" into "C:gamemovies". Now I open my game, paste the above into a new section of the scrîpt editor (ABOVE MAIN), and close the scrîpt editor. Then I make a new event on my map, give it a graphic of a guy, and click to add command. I go to the third page and pick the bottom right one labeled "call scrîpt". Then I type "$scene = Scene_Movie.new("intro",8)" (the 8 because my intro is 7.5 seconds long and I know to round up if I must round). Now I run my game, and whenever I talk to this guy, it plays my movie.


Now not all avi files will work, but I really hope your making your own movies, so it should be no problem to try different codecs. Make your movies 640x480 in resolution. This scrîpt will be buggy as hell if you are running your computer at 640x480, and the editor is probably impossible to work with. If this is the case, increase your resolution to at least 800x600 and not only will it work, but people might believe you when you say you know more than nothing about computers 

Anyway, this should be working flawlessly, and my small following will hopefully help me troubleshoot any issues people have, so feel free to post issues here and someone (I pray not always myself) will get back to you.

EDIT: I'm going to list some relavent stuff from the other topic here to answer a few questions before they're asked.

First off, this is not perfect, it cannot play videos while in fullscreen mode, but it can check your screens resolution to make a good guess if you're running fullscreen or not (hence the whole buggy 640x480 resolution thing I mentioned). If you game is running windowed, then your resolution shouldn't be 640x480 (with todays technology it's probably more like 1024x786 or higher, mines @ 1280x1024). When you go into fullscreen mode (alt+enter) your screen resolution changes to 640x480. So if it's about to play a video and the resolution is 640x480 it guesses that you don't actually use 640x480 resolution, you're just in fullscreen mode, so it jumps to windowed mode, plays the video, and re-enters fullscreen mode afterwards. If you were in windowed mode, it just plays the video. I've also noticed that playing the game in windowed mode with a resolution of 640x480 actually won't work right anyway because the games area is 640x480 PLUS the titlebar AND the taskbar... so you'd probably notice if your running 640x480, and you should definately change it to a higher setting anyway.

Second, as I mentioned not all Codecs work. The word "Codec" seems to scare a lot of people around here, so let me explain. A video file has three things (that are relevant to this thread): a video codec, and audio codec, and a file extension. Any extension can have any video/audio codec combinations, the codecs are basically just instructions on how to use the data in the file. "Compression" is used in most codecs, which makes the files more portable. You should find codecs that work well for what you need (usually less filesize means less quality with little workaround room), and stick with it. If you use common codecs, then others can watch your movies too... If you use "Hax0r's leaked Playstation codec" (don't think this is real, but an example) then most people won't have it, so you either need to provide the codec with your game, or somehow get them to a place where they can download/install it. I would just say to use "Windows Media Player 9" for video, and any common MP3 codec for audio. If you don't know what codecs are, then you probably haven't downloaded any additional ones to your comp, so just pick ones from the list that's there in your video editing program. You can use Divx (I guess) but make sure it's a new version, and be sure to mention the divx codec is needed to watch your games videos. Again, I recommend just using the "pre-installed" codecs for less headaches. Windows Media Player 9 is actually pretty good, only about 1 additional meg for every 14 megs of Divx.

What's with the "length" variable in your scrîpt? Well, the game needs a way to hold out until the video is done, and the best way is to probe for keypresses... but you don't want to force the user to press a key at the end of the video, so you include the files playtime and when the counter runs out it will continue the game. If you don't want this feature, just enter a huge number, put a "end of video" screen at the (you guessed it) end of your videos, and make sure people know to press a button at the end of the videos to continue. Oh, while I'm at it, you can press Esc. during the video to skip it, but since the engine only probes for the keypresses every so often, you may have to hold the "Esc" key for as long as one second for the engine to realize you pressed it (small error).