Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

407
Visualizações
Matter.js Creating Rectangle With Text Property Doesn't Work

I am currently trying to make a rectangle with text inside.

Here is my current code:

var Engine = Matter.Engine,
  Render = Matter.Render,
  Runner = Matter.Runner,
  Bodies = Matter.Bodies,
  Body = Matter.Body,
  Composite = Matter.Composite;

var engine = Engine.create();

var render = Render.create({
  element: document.body,
  engine: engine
});

var boxA = Bodies.rectangle(400, 305, 400, 400, {
  render: {
    fillStyle: "transparent",
    strokeStyle: "transparent",
    text: {
      content: "Hello",
      color: "black",
      size: 15
    }
  }
});

var ground = Bodies.rectangle(400, 500, 810, 20, {
  isStatic: true,
  render: {
    fillStyle: 'grey',
    strokeStyle: 'transparent',
    lineWidth: 3
  }
});

Composite.add(engine.world, [boxA, ground]);
Render.run(render);
var runner = Runner.create();
Runner.run(runner, engine);
<script src="https://cdnjs.cloudflare.com/ajax/libs/matter-js/0.18.0/matter.min.js"></script>

Here is the link to another stackoverflow post which answer I used in my code: Matter.js Text inside a rectangle

But with wireframe on it just creates a square with nothing in it. With wireframe off, it doesn't display anything, but it is there because I can see the outline of it if I change the strokeStyle of the body.

I also tried finding information about the text property of a Body on the documentation.

about 4 years ago · Juan Pablo Isaza
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda