1
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 3 years have passed since last update.

phina.jsでvideoをcanvasに読み込む方法

Last updated at Posted at 2021-01-03

かなり不完全ですがご参考までに

video.js
const VIDEO_WIDTH = 250;
const VIDEO_HEIGHT = 150;

phina.define('MainScene', {
  superClass: 'DisplayScene',
  init: function(){
    this.superInit();
    var canvas = VideoCanvas();
    Sprite(canvas)
      .addChildTo(this)
      .setPosition(this.gridX.center(), this.gridY.center());
  }
});

phina.define('VideoCanvas', {
  superClass: 'Canvas',
  init: function(){
    this.superInit();
    const width = VIDEO_WIDTH;
    const height = VIDEO_HEIGHT;
    this.setSize(width, height);

    const video = document.createElement('video');
    document.body.appendChild(video);
    video.src="video.mp4";
    video.playsInline = true;
    video.style.display = "none";
    video.play();

    var self = this;
    (function canvasVideoPlay(){
      self.drawImage(video,0,0,width,height);
      requestAnimationFrame(canvasVideoPlay);
    })();
  },
});

phina.main(function() {
  var app = GameApp({
    startLabel: 'main',
  });
  app.run();
});
1
0
3

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?