I am developing a simple game in HTML5
and javascript
. the game is as simple as this:
the game should instruct the player to put certain objects in certain places in the canvas, e.g: put the apple inside the box or, put the apple beside the box.
When the player drag the object and drop it in any place in the canvas
the game should evaluate his action and decide whether he placed the right object in the right place or not.
My question is: how can I test where the user placed an object according to another object? i.e: how can I know that the user put the object beside the box or below the box or even inside the box?
the only ideas that came across my mind are:
- to draw a transparent
Image()
in canvas and use its boundaries as a drop area - or create a
<div>
in the places that the player should put the object in, and whenever an object collides with this area I should test the user's action. However, I can't create a<div>
inside a canvas and didn't succeed in creating a transparentImage()
. any ideas ?