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

Showcase your libraries, tools and other projects that help your fellow love users.
Post Reply
User avatar
shinprog
Prole
Posts: 15
Joined: Sat Oct 21, 2017 11:56 am
Contact:

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

Post 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:
Attachments
demo-full.love
full demo
(44.53 MiB) Downloaded 371 times
intro.lua
the class
(1.09 KiB) Downloaded 382 times
demo.love
demo without the video
(1.22 KiB) Downloaded 244 times
I'm a french hight school student who starts programming :)
I'm not very comfortable with english but I'll do my best.

CO-funder of the Kagerou Project Fr Community.
http://kagescan.esy.es http://fb.me/KagerouProjectFr
User avatar
Tjakka5
Party member
Posts: 243
Joined: Thu Dec 26, 2013 12:17 pm

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

Post 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.
hoon1722
Prole
Posts: 1
Joined: Fri Jun 21, 2024 3:48 pm

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

Post 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)?
Post Reply

Who is online

Users browsing this forum: No registered users and 1 guest