Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

408
Vistas
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 la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda