joel2k8 Posted September 14, 2010 Share Posted September 14, 2010 Alright well Hello, I currently have a table that shows a background image and I have 1 TD with 100% width and height and in that TD I have a DIV that moves by margin-left and margin-top via JavaScript and the height is approx 20px by 20px, so basically I have a map with a character that moves when keys are pressed. My problem is I'm having trouble setting limits (where the character cannot go inside the TD). etc if it reachs a X and Y then it would stop, but it's not that easy, I currently have this in a IF function when the keys are pressed: var x; var y; var exclude = { x: [50, 50, 50, 50, 50], y: [50, 60, 70, 80, 90] }; if (exclude.x.indexOf(x) !== -1 && exclude.y.indexOf(y) !== -1){ // dismiss } else { //run main code.. } But that code doesn' work correctly because I want the numbers in exclude.x to match the oppisite of exclude.y so 50 and 50, 50 and 60 but instead its like this 50 and 50 or 60 or 70 or 80 or 90. I just want it to be set so it matches the number... x: [1, 2, 3, 4, 5], y: [1, 2, 3, 4, 5] Hope you can help I've been having trouble for awhile now, thanks. Quote Link to comment Share on other sites More sharing options...
Psycho Posted September 15, 2010 Share Posted September 15, 2010 I'm really not following your explanation well, but I think I know what you are wanting. if (exclude.x.indexOf(x) !== -1 && exclude.y.indexOf(y)===exclude.x.indexOf(x)){ That will chek if the X value is in the excluded list. If so, it then checks if the index of the Y value is the same as the index of the X value. So, the //dismiss branch will only be run if the X & Y values are corresponding values in the two arrays. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.