Skip to content
Advertisement

How to use windowWidth and windowHeight outside of setup()?

I need the screen dimensions for a project, but trying windowWidth and windowHeight yields an error saying I can’t use them outside of setup(). I also tried defining the windowWidth and Height to a new constant, but it simply says the constant has not been defined.

Here’s the current state of my code (doesn’t work, but gives a pretty good idea of the code):

JavaScript

Advertisement

Answer

If you use global variables like WIDTH and HEIGHT it will allow you to use them from anywhere in the code.

JavaScript
User contributions licensed under: CC BY-SA
2 People found this is helpful
Advertisement