0

I'm trying to center an entity, but I want it to be center no matter the window configuration.(I'm relatively new to JavaScript and Crafty.js in general, so there might be a really easy fix I'm not seeing.) I've tried creating a variable and dividing the window.innerWindowHeight by 2 and seeing if that will pass as an z coordinate, but no luck.

(The code that I tried) let MiddleZ = window.innerHeight / 2;

Luke K
  • 1
  • 3
  • You're trying to solve a CSS problem with JS. Have a look at this: https://www.w3schools.com/csS/css_align.asp – Adriano Jul 26 '21 at 03:21
  • I'm centering an entity that has width, height, x and y coords as the `.attr({})`. I need to figure out a way to do the math in js and draw it to the canvas, all in the `Scene`, so I can't do it in css. I would if I could. – Luke K Jul 26 '21 at 03:27
  • Fixed it. I needed to put the math before I drew the canvas. – Luke K Jul 26 '21 at 03:31
  • I see. I didn't know you were working in the canvas element. – Adriano Jul 26 '21 at 03:36

0 Answers0