Jump to content

Phaser video object destroy() error and can`t make any updates on it


hatem.ismail
 Share

Recommended Posts

Dears, kindly I need help phaser  issue on working on videos objects

here is my game code exmple:

var game = new Phaser.Game(800, 600, Phaser.CANVAS, 'phaser-example', { preload: preload, create: create});function preload() {    game.load.video('video', 'http://crossorigin.me/http://www.sample-videos.com/video/mp4/720/big_buck_bunny_720p_1mb.mp4');}var video;function create() {    video = game.add.video('video', 0.5, 0.5);    video.play(true);    video.addToWorld(0, 0, 0.5, 0.5);    setTimeout(function(){        video.destroy();    }, 3000);}

when try call destroy() method return error:

 Uncaught TypeError: Cannot read property 'paused' of null 

 

 

also I properties like video.visible = false, or change x, y position not effective

 

here is full code on jsfiddle:

http://jsfiddle.net/hatem_ismail/uv6cqebj/1/

 

 

Thank you

 

Link to comment
Share on other sites

  • 1 month later...
  • 8 months later...

You can't destroy a Video while it's still being used as a texture by an Image or Sprite.

You should save a reference from `addToWorld` (which is the Image using the video) then, if you want, destroy the Image first and then the Video.

var video = game.add.video('video', 0.5, 0.5);

video.play(true);

var videoImage = video.addToWorld(0, 0);

game.time.events.add(3000, function() {
    videoImage.destroy();
    video.destroy();
});

 

Link to comment
Share on other sites

Ok, if anyone stumbles across this, the problem was that I was trying to call destroy() on the initial object reference. You can call it on what is returned from 'addToWorld()'

EG:

var mov = game.add.video('myVideo');
var txt = mov.addToWorld(0, 0);

 mov.onComplete.add(function(obj){
     txt.destroy();
 });

Link to comment
Share on other sites

 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...