Page 1 of 1

[class] intro - the easiest way to display a video in your game

Posted: Tue Oct 24, 2017 2:40 pm
by shinprog
Hello,
It's my second library,Intro :D !

This is a class for load videos,center-it (give the good position) and add the correct scale (if the window is too small) in your game.
It is very useful if you want to display a simple video in your game and you want a clean code !

this is an example for display a video :

Code: Select all

require 'intro'
function love.load()
		intro = intro.init("resources/videos/intro.ogv")
		intro.play()
end
 
function love.draw()
	love.graphics.setBackgroundColor( 0,0,0) --not very useful,just set the default color and the background color
	love.graphics.setColor(255, 255, 255)
	if intro.video:isPlaying() then love.graphics.draw(intro.video, intro.x,intro.y, 0, intro.scale) end
end

Just 3 lines :rofl: two in the love.load() and one if statement in the love.draw!

HOW TO USE :
1\Make your video in the OGV format.it is strongly recommended to use ffmpeg and this line to convert:

Code: Select all

ffmpeg -i input.mp4 -codec:v libtheora -qscale:v 7 -codec:a libvorbis -qscale:a 5 output.ogv
2\Download the class and put it in your project folder.Add " require 'intro' " in the first line of your main program
3\initialize in love.load the video with intro.init(<the path of the ogv video>)
4\use theses functions :
  • play() : Play the video
    pause() : pause the video
    stop() : stop the video
5\ display the video with this line :

Code: Select all

love.graphics.draw(intro.video, intro.x,intro.y, 0, intro.scale)
If you want to display the video only if the video is playing,use a if statement with intro.video:isPlaying() (see the example)

In the attachment :
  • The complete demo,with a demo video (intro of my game) > 50~ Mo [demo-full.love]
    The demo > 2Ko~ [demo.love]
    The source of the class > 1Ko~ [intro.lua]
:roll: :roll: :roll: :roll: :roll:
Why I named It "intro" ? Because in the beginning ,this class can just load add one video,and today,i think it can load multiple videos (I haven't try it)...

If you have a suggestion,an issue or you used it in your game,please reply in this post :ultrahappy:

Re: [class] intro - the easiest way to display a video in your game

Posted: Tue Oct 24, 2017 5:49 pm
by Tjakka5
This doesn't work if you resize the window in runtime.
It also enforces a 100 pixel margin on the top and bottom, which seems odd.

Re: [class] intro - the easiest way to display a video in your game

Posted: Sun Jun 23, 2024 11:04 pm
by hoon1722
Thanks for this - I found some good success using this.

Is there a native Love2d way to recognise when a video ends (e.g., to skip to another scene)?