+ 2
How do of find the coordinates of objects?
I am making a game with JS and I want a way by which I can get coordinates of my objects E.g. I have 2 rectangles .One is player and other is obstacle.I have made all animations of jump and go but I want to make a "You Lost" message when the 2 rectangles touch each other Please tell a way by which I can alert you lost when the two rectangles touch each other. Answers in JavaScript or CSS only .
4 Réponses
+ 3
Get the current left and too property of rectangle using getComputedStyle and assign new value to
rect.style.left=current left
rect.style.top=current top and then keep increasing current left and top to move rectangle and check if their value is equal to other rectangle ,
+ 2
Does
rect.style.left=current left
Contain the left side coordinates of rectangle
+ 2
Raghu Rao yes but you need to assign the current css left value to current left variable ,and use getComputedStyle to get current css value or you can assign it directly as well to the variable
+ 1
Abhay Thanks