Canatron
Canatron

Reputation: 85

How to order shapes on a canvas - JavaScript

I want to make a shape (an XP bar) to always be ordered at the top of all shapes drawn.

How would this be possible, (I also use p5.js too, if that helps.) other than drawing it last (which I cannot do in my situation).

Upvotes: 1

Views: 284

Answers (1)

Kevin Workman
Kevin Workman

Reputation: 42174

You've got two main options:

Option one: Draw it last. This is the easiest way to do it. If you "cannot" do it this way for some reason, that sounds like you need to refactor your code then.

Option two: Use 3D coordinates to draw it with a Z coordinate that's closer to the user. Most drawing functions can take 3D coordinates instead of 2D coordinates. This should work, but it's more complicated than just drawing it last.

Upvotes: 1

Related Questions