phaserjs / phaser

Phaser is a fun, free and fast 2D game framework for making HTML5 games for desktop and mobile web browsers, supporting Canvas and WebGL rendering.
https://phaser.io
MIT License
37.15k stars 7.1k forks source link

Phaser.Textures.Texture from HTMLCanvas not getting rendered #4652

Closed Jugacu closed 5 years ago

Jugacu commented 5 years ago

Description

When i try to create a Phaser.Textures.Texture from a canvas already drawn and assign it to an sprite via Phaser.GameObjects.Sprite.texture it wont render.

It does work if i use the texture manager but i feel like that other way should work aswell

Example Test Code

https://codepen.io/anon/pen/bPyNXy

photonstorm commented 5 years ago

Sorry, but no, the correct way is to use the Texture Manager, so that the correct objects are created internally. Your approach ignores the fact that Textures require a reference to the Texture Manager in order to be constructed properly and also that Game Objects need a Texture and a Frame in order to render.

You cannot just dump a canvas DOM element on a Sprite and expect it to render I'm afraid, that just isn't how WebGL works. It needs to be converted into a WebGLTexture first.