In phaser 3 (using matter js physics), it seems that there’s no way of setting a texture to a polygon, and yet i need to have a hexagon/pentagon with a texture. I’ve been unable to figure out how to set an already made texture of a polygon (png) with the physics of a polygon. Please, give me a minimal code for creating a polygon with a texture and physics.
I’ve already figured out the vertices of a needed polygon, but cannot find a way to create it with a texture attached
const pentagonVertices = [
{x:(0) +0.5,y: ((2.01 / 4) +0.5)},
{x:(1.91/4)+0.5,y:((0.62/4) +0.5)},
{x:(1.18/4) +0.5,y:((-1.63/4) +0.5)},
{x:(-1.18/4)+0.5,y:((-1.63 / 4) +0.5)},
{x:(-1.91/4)+0.5,y:((0.62/4)+0.5)}
];
i try write it:
const polygon = globalThis.add.polygon(worldPosX, worldPosY, pentagonVertices, 0x8d8d8d); var poly = globalThis.add.image(worldPosX, worldPosY, 'image', polygon); globalThis.matter.add.gameObject(poly);
and
const polygon = globalThis.add.polygon(worldPosX, worldPosY, pentagonVertices, 0x8d8d8d); var poly = globalThis.matter.add.gameObject(polygon); poly.setTexture('image') //setTexture is not defined for some reason globalThis.matter.add.gameObject(poly);
Кита Спаркл is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.