HTML5 Canvas set z-index

后端 未结 5 1266
陌清茗
陌清茗 2020-12-01 07:48

Is it possible to set the z-index of a drawn object in HTML5 canvas?

I am trying to get it so one object can be infront of a the \"player\" and another object is beh

5条回答
  •  日久生厌
    2020-12-01 08:00

    Just draw the things behind it first, then the thing, then the other objects.

    To do hit testing you may need to iterate backwards over your display list, testing each object. This will work if you know the object boundaries really well.

    Or you may want to try some standard graphics tricks like drawing the same objects to another in-memory canvas with unique colours for every object drawn: to hit test this just check the pixel colour on the in-memory canvas. Neat ;-)

提交回复
热议问题