In game video?

Get help using Construct 2

Post » Tue Apr 03, 2012 6:27 am

Hi,

Is it possible to add a video in my C2 game?

Tks
B
42
S
9
G
7
Posts: 58
Reputation: 7,465

Post » Tue Apr 03, 2012 6:42 am

Quite possible.

You need to add a HTML5 video tag where it comes from the source and a little bit of hack c2runtime.js:

In HTML:
<video id="video" controls="controls" autoplay="autoplay" src="your_video_file.webm"></video>

In JS:
var canvas = document.getElementById('canvas');
var video = document.getElementById('video');
var drawvideo = canvas.getContext('2d');

video.addEventListener('play', function () {
    var $this = this;
    (function loop() {
        if (!$this.paused && !$this.ended) {
            drawvideo.drawImage($this, 0, 0);
            setTimeout(loop, 1000 / 30);
        }
    })();
}, 0);


I know it shows double video and not perfect, but you can hide another video using CSS display: none; for ID of video.Joannesalfa2012-04-03 06:51:51
B
105
S
29
G
28
Posts: 3,102
Reputation: 27,380

Post » Tue Apr 03, 2012 6:54 am

B
99
S
22
G
197
Posts: 4,216
Reputation: 113,797

Post » Tue Apr 03, 2012 7:02 am

Ah! i didn't know there a video plugin.
B
105
S
29
G
28
Posts: 3,102
Reputation: 27,380

Post » Tue Apr 03, 2012 1:19 pm

Great! Thank you!
B
42
S
9
G
7
Posts: 58
Reputation: 7,465


Return to How do I....?

Who is online

Users browsing this forum: Yahoo [Bot] and 2 guests