I am making a game and I am trying to create a game end function. How would I go about resetting all images to their starting positions?
Share
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
You can programaticly store all positions of a image class inside a Object inside a array.
And after you can loop the
arrayrestoring theirs positions back.Call the
savePositionsfunction on the initial state, and you can callrestoreStoredPositionslater. If you want persistent data, stringy the array to JSON and you can store it to a Cookie or HTML5 LocalStorage.I know this is pure JS but this is just a concept that I wrote now.
You can adapt this to use the each() and the jquery selector on place of the getElementBy…
I used the style.top and left just for readability, computedStyles is the correct path.