phaser
phaser copied to clipboard
Video game object can't setDisplaySize
Version
- Phaser Version: 3.60.0
- Operating system: win11
- Browser: chrome/firefox
Description
Video game object does not have frame
property, thus it can't get video.frame.realWidth
for setDisplaySize method
Example Test Code
From this test code,
Replace line 15 to
const intro = this.add.video(640, 360, 'spaceace').setDisplaySize(200, 200);
And it will show error message
caught TypeError: Cannot read properties of null (reading 'realWidth')
at Video.set [as displayWidth] (Size.js:73:1)
at Video.setDisplaySize (Size.js:181:1)
...
BTW, how to preload video coss-origin?
Previously, asBlob
parameter seems can be used for coss-origin.
Additional Information
LoadURL method has crossOrigin parameter now.
Facing the same issue in Phaser 3.60.0 with the video game object does not have frame property. I am using rex's UI plugin (v1.60.2) as well, and for example if I try to add a video object into a UI sizer, same error Cannot read properties of null (reading 'realWidth') at Video.get [as displayWidth]
will be shown.
A temporary solution I found is to assign a random placeholder texture to the video. For example, from the same test code, add an image load to the preloader
this.load.image('placeholder', 'assets/textures/grass.png');
then replace line 15 to
const intro = this.add.video(640, 360, 'spaceace').setTexture('placeholder').setDisplaySize(200, 200);
will result in no error and the size is changed, although the size seems to be dependent to the placeholder's texture size
Thank you for submitting this issue. We have fixed this and the fix has been pushed to the master branch. It will be part of the next release. If you get time to build and test it for yourself we would appreciate that.