Submit Your Article


 
RPG Maker

Welcome Guest ( Log In | Register )


  Games Resources RPG Maker VX RPG Maker XP Scripts Tutorials Downloads

 
Reply to this topicStart new topic
> [Series]Adding Videos To Your Game (Part 1), RMFlash is maaaagical.
felipe_9595
post Jul 7 2011, 06:22 AM
Post #1


Level 12
Group Icon

Group: Revolutionary
Posts: 201
Type: Writer
RM Skill: Undisclosed




Okay, hi to all. Today we are going to add something pretty flashy for your game. We are going to add videos !!! For that, we are going to use the Script RMFLASH. With this script we can play .swf files. But, what the advantage over a Avi player or a Mpg player??? With some modifications to our script we can put Videos as background on Menus, the title screen or as a Battle Background!!

Okay, lets start. First add the RMFLASH script to your project:

First, create a folder called "Flash" on the "Graphics" folders.
CODE
#==============================================================================#
#                                                               Version 0.3.1  #
#                         RPG Maker XP Flash Player                            #
#                                                                              #
#  Author: 灼眼的夏娜                     Updated by: Dark_Wolf_Warrior/Dahrkael and   #
#                                             Playhome                         #
#                                                                              #
#  How to Use:                                                                 #
#                                      Graphics.freeze                         #
#  1. Go to Main Script and add ---->  $flash = Play.new                       #
#                                      $scene = Scene_Title.new                #
#                                                                              #
#  2. Copy the .dll and the .ocx to the game folder                            #
#                                                                              #
#  3. Make a folder called "Flash" in the folder "Graphics" -> Graphics/Flash/ #
#                                                                              #
#  4. To play a flash file use:                                                #
#    $flash.play("file.swf", button)                                           #
#                                                                              #
#    button can be 0 or 1, if 1 you can skip the flash using "Enter"           #
#                                                                              #
#                                                                              #
#                                                                              #
#  Interactive flashes requires RGSS knownledge to make they work              #
#                                                                              #
#  Original Keyb module by HoundNinja                                          #
#                                                                              #
#==============================================================================#



class String
  
  CP_ACP = 0
  CP_UTF8 = 65001
  
  def u2s
    m2w = Win32API.new("kernel32", "MultiByteToWideChar", "ilpipi", "i")
    w2m = Win32API.new("kernel32", "WideCharToMultiByte", "ilpipipp", "i")
    
    len = m2w.call(CP_UTF8, 0, self, -1, nil, 0)
    buf = "�" * (len*2)
    m2w.call(CP_UTF8, 0, self, -1, buf, buf.size/2)
    
    len = w2m.call(CP_ACP, 0, buf, -1, nil, 0, nil, nil)
    ret = "�" * len
    w2m.call(CP_ACP, 0, buf, -1, ret, ret.size, nil, nil)
    
    return ret
  end
  
  def s2u
    m2w = Win32API.new("kernel32", "MultiByteToWideChar", "ilpipi", "i")
    w2m = Win32API.new("kernel32", "WideCharToMultiByte", "ilpipipp", "i")
  
    len = m2w.call(CP_ACP, 0, self, -1, nil, 0);
    buf = "�" * (len*2)
    m2w.call(CP_ACP, 0, self, -1, buf, buf.size/2);
  
    len = w2m.call(CP_UTF8, 0, buf, -1, nil, 0, nil, nil);
    ret = "�" * len
    w2m.call(CP_UTF8, 0, buf, -1, ret, ret.size, nil, nil);
    
    return ret
  end

  def s2u!
    self[0, length] = s2u
  end  
  
  def u2s!
    self[0, length] = u2s
  end
  
end

class Bitmap
  
  RtlMoveMemory_pi = Win32API.new('kernel32', 'RtlMoveMemory', 'pii', 'i')
  RtlMoveMemory_ip = Win32API.new('kernel32', 'RtlMoveMemory', 'ipi', 'i')

  def address
    buffer, ad = "xxxx", object_id * 2 + 16
    RtlMoveMemory_pi.call(buffer, ad, 4); ad = buffer.unpack("L")[0] + 8
    RtlMoveMemory_pi.call(buffer, ad, 4); ad = buffer.unpack("L")[0] + 16
    RtlMoveMemory_pi.call(buffer, ad, 4); return buffer.unpack("L")[0]
  end
  
end

class RMFlash

    API_NEW              = Win32API.new("RMFlash", "_new", "piil", "l")
    API_UPDATE        = Win32API.new("RMFlash", "_update", "l", "v")
    API_FREE          = Win32API.new("RMFlash", "_free", "l", "v")
    API_PLAYING     = Win32API.new("RMFlash", "_is_playing", "l", "i")
    API_PAUSE          = Win32API.new("RMFlash", "_pause", "l", "v")
    API_RESUME        = Win32API.new("RMFlash", "_resume", "l", "v")
    API_BACK          = Win32API.new("RMFlash", "_back", "l", "v")
    API_REWIND        = Win32API.new("RMFlash", "_rewind", "l", "v")
    API_FORWARD        = Win32API.new("RMFlash", "_forward", "l", "v")
    API_CURFRAME      = Win32API.new("RMFlash", "_cur_frame", "l", "i")
    API_TOTALFRAME    = Win32API.new("RMFlash", "_total_frames", "l", "i")
    API_GOTOFRAME      = Win32API.new("RMFlash", "_goto_frame", "li", "v")
    API_GETLOOP          = Win32API.new("RMFlash", "_get_loop", "l", "i")
    API_SETLOOP          = Win32API.new("RMFlash", "_set_loop", "li", "v")
    API_CLEARALL      = Win32API.new("RMFlash", "_clear_all", "v", "v")
  API_VALID       = Win32API.new("RMFlash", "_valid", "l", "i")
  API_SENDMSG     = Win32API.new("RMFlash", "_send_message", "liii", "l")
    
  CUR_PATH        = Dir.pwd
  
    def self.get_version

    end

    def self.clear_all
        API_CLEARALL.call
    end
  
  def self.load(name, width, height, v = nil)
    new("#{CUR_PATH}/Graphics/Flash/#{name}".u2s, width, height, v)
  end
  
  attr_reader   :valid

    def initialize(flash_name, flash_width, flash_height, viewport = nil)
        @sprite = Sprite.new(viewport)
        @sprite.bitmap = Bitmap.new(flash_width, flash_height)
        @value = API_NEW.call(flash_name, flash_width, flash_height, @sprite.bitmap.address)
        @loop = API_GETLOOP.call(@value) > 0
    @valid = API_VALID.call(@value) > 0
    end

    def viewport
        @sprite.viewport
    end

    def update
        API_UPDATE.call(@value)
    end

    def dispose
        API_FREE.call(@sprite.bitmap.address)
    end

    def playing?
        API_PLAYING.call(@value) > 0
    end

    def pause
        API_PAUSE.call(@value)
    end

    def resume
        API_RESUME.call(@value)
    end

    def back
        API_BACK.call(@value)
    end

    def rewind
        API_REWIND.call(@value)
    end

    def forward
        API_FORWARD.call(@value)
    end

    def current_frame
        API_CURFRAME.call(@value)
    end

    def total_frames
        API_TOTALFRAME.call(@value)
    end

    def goto_frame(goal_frame)
        API_GOTOFRAME.call(@value, goal_frame)
    end

    def x
        @sprite.x
    end

    def x=(v)
        @sprite.x = v
    end

    def y
        @sprite.y
    end

    def y=(v)
        @sprite.y = v
    end

    def z
        @sprite.z
    end

    def z=(v)
        @sprite.z = v
    end

    def width
        @sprite.bitmap.width
    end

    def height
        @sprite.bitmap.height
    end

    def loop?
        @loop
    end

    def loop=(v)
        if @loop != v
            @loop = v
            API_SETLOOP.call(@value, v)
        end
    end
  
  def msg_to_flash(msg, wParam, lParam)
    return API_SENDMSG.call(@value, msg, wParam, lParam)
  end
  
  #  例
  WM_MOUSEMOVE  = 0x0200
  
  def make_long(a, b)
    return (a & 0xffff ) | (b & 0xffff) << 16
  end
  
  def on_mouse_move(x, y)
    return msg_to_flash(WM_MOUSEMOVE, 0, make_long(x, y))
  end

end

module Kernel

  alias origin_exit exit unless method_defined? :exit
  
  def exit(*args)
    RMFlash.clear_all
    origin_exit(*args)
  end
  
end

module Keyb
  $keys = {}
  $keys["Enter"] = 0x0D
  GetKeyState = Win32API.new("user32","GetAsyncKeyState",['i'],'i')
  module_function
  def trigger(rkey)
    GetKeyState.call(rkey) & 0x01 == 1
  end
end

class Play
  
  def play(filename, button)
    fondo = Sprite.new
    fondo.bitmap = Bitmap.new(640, 480)
    fondo.bitmap.fill_rect(0, 0, 640, 480, Color.new(0,0,0,255))
    fls = RMFlash.load(filename, 640, 480)
    fls.loop = 1
    fls.z = 9999
    @button = button
    @fr = Graphics.frame_rate
    Graphics.frame_rate = 40
    while true
      Graphics.update
      #Input.update
      fls.update
      break if @button == 1 and Keyb.trigger($keys["Enter"])
      break if !fls.playing?
    end
    fls.pause
    fls.z = -2
    fls.dispose
    Graphics.frame_rate = @fr
    fondo.dispose
  end
end[code]

Then, modify You main, add this line ( [b]$flash = Play.new[/b]   ) above [b]( $scene = Scene_Title.new)[/b]

Now your main should look like:

[code] # Transition preparation
  # Prepare for transition
  Graphics.freeze
  # Make scene object (title screen)
  $flash = Play.new    
  $scene = Scene_Title.new


Ok, now, the funny part.

Video as background on the tittle screen:

Okay, go to your Scene_Title and add the blackened line on the def main

CODE
#==============================================================================
# ** Scene_Title
#------------------------------------------------------------------------------
#  This class performs title screen processing.
#==============================================================================

class Scene_Title
  #--------------------------------------------------------------------------
  # * Main Processing
  #--------------------------------------------------------------------------
  def main
[b]    @flash_file = "1.swf"[/b][/hide]

Change [b]"1.swf"[/b] with the name of your swf.

And add the Next lines after The "Makes Command Windows":

[code]# Flash background
@fondo = RMFlash.load(@flash_file, 640, 480)
@fondo.z = @sprite.z - 1
#@fondo.loop = 1
@fr = Graphics.frame_rate
Graphics.frame_rate = 60


Then, go to the update method and add:

CODE
      # Update game screen
      Graphics.update
      # Update input information
      Input.update
      #Flash update
      [b]@fondo.update[/b]
      # Frame update
      update


Finally, add on the dispose method:

CODE
# Prepare for transition
    Graphics.freeze
    # Dispose of command window
    @command_window.dispose
    # Dispose of title graphic
    @sprite.bitmap.dispose
    @sprite.dispose
    [b]@fondo.pause
    @fondo.z = -2
    @fondo.dispose
    # Normal frame rate
    Graphics.frame_rate = @fr[/b]
end


Result:



Do you like it ;D??? well, this is jsut the ebginning ;D

Video as background on Battle:

This is almost the same thing, but you have to modify some others thing.

First, i use Enu Tankentai Xp, so i will explain how to implement it on that system. It should be the same for other CBS.

For tankentai:

I will post the entire "Sideview 2" script to show it. [Posting Pastebin, the script was screwing the formatting]

http://pastebin.com/MyBXLv4Y

If you see, i added a a (Flash Bbacks (lol)) to help you xP.


#=======================================================================
#=====================Flash Bbacks (lol)================================
#=======================================================================
# Use a different variable Value for differents flashs
# Lights Effects Can be done aswell, just use images
@archivo_flash = $game_map.map_id
@asdf = RMFlash.load(@archivo_flash, 640, 480)
#@asdf.loop = 1
@variable_del_fondo = Sprite.new
@variable_del_fondo.bitmap = Bitmap.new("Graphics/Pictures/#{$game_map.map_id}")
@variable_del_fondo.z = 400

This is how it works:

As you can see, @archivo_flash remembers the Map id and @asdf plays the flash file. @asdf is gonna load a File on the "Flash" folder with the the number of the map as name (Without extension), so, if you want to put a Flash battleback on the map number 34, you have to put a flash file with the name "34" (without extension)

Result:



looks goods no ;D

Extra: Light effects on battle scene

#=======================================================================
#=====================Flash Bbacks (lol)================================
#=======================================================================
# Use a different variable Value for differents flashs
# Lights Effects Can be done aswell, just use images
@archivo_flash = $game_map.map_id
@asdf = RMFlash.load(@archivo_flash, 640, 480)
#@asdf.loop = 1
@variable_del_fondo = Sprite.new
@variable_del_fondo.bitmap = Bitmap.new("Graphics/Pictures/#{$game_map.map_id}")
@variable_del_fondo.z = 400


@variable_del_fondo is going to load an image file from the "Pictures" with the same name as the map id (without the extension)

Result:




Okay, this is all for now, in part 2 i will explain how to put videos on your menus ^^

Cya



__________________________
Go to the top of the page
 
+Quote Post
   
Redd
post Jul 7 2011, 07:54 AM
Post #2


:<
Group Icon

Group: Revolutionary
Posts: 2,312
Type: Developer
RM Skill: Advanced




May you please put the scripts in spoilers? It makes it a lot easier to scroll through.
Also, for those wondering how you can put other formats of video into .swf, you can upload your video to youtube and then use this little nifty program to convert it to a .swf file.

Very good tutorial, I've been looking for a script like this for a while and I could never seem to find it happy.gif


__________________________
Go to the top of the page
 
+Quote Post
   
nichodo
post Jul 7 2011, 01:59 PM
Post #3


ITS OVER 9000!!
Group Icon

Group: Revolutionary
Posts: 157
Type: Mapper
RM Skill: Intermediate




Are you still working on resident evil: after history?

Nice tutorial BTW.
Reason for edit: No need to quote the entire OP


__________________________
correctly playing: Nothing for now.
correctly working on: Final Fantasy: Secret of Atlantis, ON HOLD.
Working on: Final Fantasy 5 - 2.

"I, Garland. WILL KNOCK YOU ALL DOWN!" < Garland final fantasy 1

I'm a christian.

QUOTE (X-M-O @ Dec 6 2011, 05:45 PM) *
That's automatic, I'm not constantly changing my avatar; I've made it do that by itself. ;)
Go to the top of the page
 
+Quote Post
   
felipe_9595
post Jul 7 2011, 05:54 PM
Post #4


Level 12
Group Icon

Group: Revolutionary
Posts: 201
Type: Writer
RM Skill: Undisclosed




i am taking a hiatus from the project (I have spend a lot of time on it, i am not throwing it away xDDD)


__________________________
Go to the top of the page
 
+Quote Post
   
Steelz4ever
post Jul 18 2011, 04:05 PM
Post #5


Level 1
Group Icon

Group: Member
Posts: 5
Type: Developer
RM Skill: Beginner




will this script work for VX?
Go to the top of the page
 
+Quote Post
   
TheBen
post Aug 25 2011, 01:56 PM
Post #6


Intolerable Noob
Group Icon

Group: Revolutionary
Posts: 344
Type: Developer
RM Skill: Beginner




No. It might with a few tweaks, but no one's really got there yet - here's a topic that deals with that.


__________________________
QUOTE
Great people talk about IDEAS
Average people talk about THINGS
Small people talk about OTHER PEOPLE

- A plaque on a BBQ restaurant in VA
Go to the top of the page
 
+Quote Post
   
Steysel
post Sep 9 2011, 10:10 PM
Post #7


Level 2
Group Icon

Group: Member
Posts: 23
Type: Writer
RM Skill: Beginner




Whoa, I didn't know that you can put videos on RMVX. Thanks for this tutorial. It really helps.
Go to the top of the page
 
+Quote Post
   

Reply to this topicStart new topic
1 User(s) are reading this topic (1 Guests and 0 Anonymous Users)
0 Members:

 

Lo-Fi Version Time is now: 22nd May 2013 - 02:05 PM
RPG RPG Revolution is an Privacy Policy and Legal
eXTReMe Tracker