![]() |
Multiple images moving different directions
I'm still kinda new at this. Please bear with me..I'm trying to make all imgs move in different directions using the following code. I was givin the code and I need to insert something into it so this will work. I just can't understand it and WANT to ..driving me NUTTY.
Code:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" |
What is the *specific* problem?
"It doesn't work" could mean you forgot to upload it to the web server. |
Okay, I see. Only the one image moves (makes sense, as there's no code in there to move more than one) and it only moves up and down.
Oh, and the code doesn't work at all in MSIE. |
So is this homework??? Because even the basic code for a single bug doesn't really work very well. (Only goes up and down or would only go left and right, if set up differently.) It doesn't "buzz" around, at all.
Personally, I'd toss the code and start all over. |
I hope this wasn't homework.
Code:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" |
Thanks!...it is homework...lol... but I'm trying to figure out what I needed to do to the code I posted so it would work for all the bugs...I'm really not here to have great people like yourself do my homework for me..I NEED to understand it, not because of school, because this stuff is AWESOME to me :thumbsup: . and I want to be able to look at this code I sent you from .....your shoes :D ... I read crazy amounts of books and read many peoples code just to practice understanding syntax the best I can (syntax is difficult for me to understand).... Thanks A LOT!...Master :cool: much respect
|
Well, maybe that code at least will point you in the right direction.
Your code is only setting up the values (xPosition, yPosition, etc.) for ONE of your images. You need to do it for all 5. I think it is way overcomplicated, too, by having separate values for speed and direction. Just do as I did and combine them: - speed is up, + speed is down, etc. Finally, you have to *MOVE* all of them. Again, your code only tries to move number zero. So... repetition is the key. DO the same thing for all 5. Don't just work with bug 0. |
Hope you noticed that there's no reason to have the <div>s around the <img>s. The images can move nicely by themselves. The divs are just extra goop in the way.
|
Ya I realized that on the <div>s after looking at your code..Right when I saw your code
and saw math random() I was thinking the same prior to using the code supplied .. it said "in random directions" on my paper given to me as well..I was given all that as a sample code and kinda was determined to use it.I Like how you used clientWidth and Height -48 so it wouldn't go outside the boundaries..I never would've thought of that one. Thanks again I will more than likely bother you for more knowledge. next time I'll try and ask questions rather than post my homework although its hard to describe when you don't see the code. |
I went back and added comments to the code. And in the process saw a better way to code this. But hey, I just tossed off that code. Except for two typos, it worked first time, so I can't complain too much.
|
Here, the better version:
Code:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" |
Commenting that out helps a lot to understand as well ... I need to start making that practice in all my works..also is "var Bugs = []" like "var Bugs = new Array"?....like I said syntax is my biggest problem
|
Yeah, = new Array() is a bit old-fashioned.
I'll bet you are wrong. I'll bet semantics are your biggest problem. Syntax is relatively easy: You'll get an error if it's wrong, even before the code starts to run. Semantics is more difficult. Code can be syntactically correct yet be semantic nonsense. |
This is what i came up with as well but the other one IS WAY cleaner...not
to mention the randomness of the directions..and I'd have to agree on semantics..I'll get to coding and get so far and then say "what the heck does this mean?" and it'll take me awhile to figure it out.....so your probably right. Code:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" |
???
Code:
var buzzSpeed = new Array(3);Aren't you glad JavaScript is so forgiving? |
| All times are GMT +1. The time now is 04:25 AM. |
Powered by vBulletin®
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.