Hello,
I would like to create variable generic text on a sprite. I can’t manage to set the correct dimensions for either the sprite or the text. The text remains partially hidden.
I’ve created this PG
Thank you
Hello,
I would like to create variable generic text on a sprite. I can’t manage to set the correct dimensions for either the sprite or the text. The text remains partially hidden.
I’ve created this PG
Thank you
In this example, I’ve created the label correctly by scaling sprite width and height.
const sprite = new BABYLON.Sprite("Sprite", spriteManager);
sprite.position = _position;
sprite.width = _width * _scale;
sprite.height = _height * _scale;
How can I determine the text length to resize the DynamicTexture and SpriteManager correctly?
I would also like the sprites to remain the same size even when zooming. There is commented-out code related to scene.onBeforeRenderObservable
, which works in some way, but the sprite scaling doesn’t seem to maintain the correct proportions.
scene.onBeforeRenderObservable.add(() =>
{
spriteList.forEach((sprite) =>
{
const distance = BABYLON.Vector3.Distance(camera.position, sprite.position);
sprite.size = distance/50;
});
});
Hello,
I solved the sprite scaling by directly setting the sprite’s width and height based on the original dimensions.
Looks good! Did you solve all your questions?
Would it be possible to use the canvas as shown in this example within a sprite not in a mesh?
Ya, you can set the SpriteManager.texture
property.
Example:
Dynamic Texture from Canvas | Babylon.js Playground
nice bro