Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 2 of 2
  1. #1
    JPM
    JPM is offline
    Regular Coder
    Join Date
    Mar 2004
    Location
    Norway
    Posts
    204
    Thanks
    0
    Thanked 0 Times in 0 Posts

    moving objects help

    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 ***

    Code:
    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;
    
    }
    JP.
    <JPM />

  • #2
    Senior Coder
    Join Date
    Feb 2004
    Posts
    1,206
    Thanks
    0
    Thanked 0 Times in 0 Posts
    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.

    Sadiq.


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •