View Full Version : moving objects help

04-28-2004, 09:13 PM
The code below moves an image horizontally. I have a simular function that moves another image vertically. What I want to do is make the horizontal moving image turn right ('var hdir') when it 'crashes' with the vertical moving image, and Im really not sure how I would do that. If someone could give me a as much as a hint that would be great.

*** Most of the script is taken from an earlier post on this forum ***

var newTop = 375;
var newLeft = 350;
var dir = "up"; // for the other function
var hdir = "right";

function startH(id) {

if ( hdir == "right") {
newLeft = newLeft + 5;
if(newLeft == 1000){
hdir = "left"

else if(hdir =="left") {
newLeft = newLeft - 5;
if(newLeft == 10) {
hdir = "right"

dom = document.getElementById(id).style;

dom.top = newTop;
dom.left = newLeft;



04-28-2004, 09:53 PM
I'm not familiar with the other post, but:

So you've got the vertical moving img and the horizontal moving image. How do you know when they've collided? Which variables will be equal or can you check to see this?

That'll be your first clue.