A Flash Developer Resource Site

Results 1 to 19 of 19

Thread: Car boundary lines HELP!!! It drives outta screen

  1. #1
    XRave tongxn's Avatar
    Join Date
    Apr 2005
    Location
    Somewhere near Here
    Posts
    870

    Car boundary lines HELP!!! It drives outta screen

    I got a car game but when i drive the car, it can go outta my screen! What should i do to prevent that?
    Please give me the script as i am a newbie and do not understand how variables worked...
    thanks if you can give me the answer
    When you actually know what "OMG I have so much homework!" means, you won't want to be me.
    Xrave

  2. #2
    Didn't do it. japangreg's Avatar
    Join Date
    Mar 2001
    Location
    \o/ |o| |o_ /o\
    Posts
    784
    Hey, Tongxn.

    Please take a few minutes and read through the guide sticky at the top of the forums; note especially the section on providing all necessary information for your question.

    From the information you have provided, there is little that I or anyone else can do to help; is this a side-view or top-view game? what code are you using to move the car?

    If you can cut and paste the code you are using, we might be able to help.
    Hush child. japangreg can do what he wants. - PAlexC
    That was Zen - this is Tao.

  3. #3
    XRave tongxn's Avatar
    Join Date
    Apr 2005
    Location
    Somewhere near Here
    Posts
    870
    I am using the code from the turtorial Car movement from FK, but the tutorial didn't say what to do to stop the car running out of the boundary lines of the screen. someone told me to do hittest but their information's not complete either...
    Anyway, i got this frontpage saying which car do u want, and then there's 4 scenes each containing a car and the background is the same. but i found out that the car just drive out of the screen and it drives me mad!

    Any ideas would be appreasiated.
    When you actually know what "OMG I have so much homework!" means, you won't want to be me.
    Xrave

  4. #4
    magnetologicus Magnetos_II's Avatar
    Join Date
    Jan 2004
    Location
    real date May 2001
    Posts
    572
    hello tongx think in terms of _x and _ys you dont really need hittest() for keeping your car within the screen boundaries
    for left to right just check if _x is less or greater then the stage width if so stop car
    for up and down check if _ y is less or greater then stage hieght if so stop car
    also posting your fla or some code would be good

    hope it helps

  5. #5
    Script kiddie VENGEANCE MX's Avatar
    Join Date
    Jun 2004
    Location
    England
    Posts
    2,590
    If you can understand a car script, it should be bloody easy for you to add boundaries. Here's the pseduo-script, you'll use it after the movement script:

    if car's _x is more than the max x boundary,
    set car's _x to max x boundary.
    else if car's _x is less than min x boundary,
    set car's _x to min x boundary.
    if car's _y is more than the max y boundary,
    set car's _y to max y boundary.
    else if car's _y is less than min y boundary,
    set car's _y to min y boundary.

    It doesn't take an expert to figure this out. Hell, you should've been able to do it without any help if you understood the tutorial...
    http://www.birchlabs.co.uk/
    You know you want to.

  6. #6
    XRave tongxn's Avatar
    Join Date
    Apr 2005
    Location
    Somewhere near Here
    Posts
    870
    Alright I get the point, but how do you stop the car from moving?
    When you actually know what "OMG I have so much homework!" means, you won't want to be me.
    Xrave

  7. #7
    Script kiddie VENGEANCE MX's Avatar
    Join Date
    Jun 2004
    Location
    England
    Posts
    2,590
    If it's constantly being moved back to the furthest place it will go, it will appear as if it isn't moving at all. For instance, if it's 25 pixels away from the left border, and moves 100 pixels to the left (a bit unrealistic, but still), it gets moved back 75 pixels. Now it's right on the border. If it continues moving at that speed next frame, it will move 100 pixels left, and be pushed back 100 pixels to the right. This will happen again the next frame, and the next frame, and so on, until it changes direction.
    http://www.birchlabs.co.uk/
    You know you want to.

  8. #8
    XRave tongxn's Avatar
    Join Date
    Apr 2005
    Location
    Somewhere near Here
    Posts
    870
    sorry, I didn't get that, i am rubbish at guessing ASs...
    When you actually know what "OMG I have so much homework!" means, you won't want to be me.
    Xrave

  9. #9
    Style Through Simplicity alillm's Avatar
    Join Date
    Mar 2004
    Location
    Wales
    Posts
    1,988
    Basicly, if you set boundrys to the game e.g.
    Code:
    minX = 0
    maxX = 500
    minY = 0
    maxY = 500
    where you change the numbers to whatever space you want you car to be able to drive in, then when you detect that the car has gone outside one of these boundrys

    Code:
    if (car._x > maxX) {
    Then you can place the car ON the boundry

    Code:
    car._x = maxX
    This will make it look like the car isnt moving because it all happens in 1 frame.

    Ali

  10. #10
    Style Through Simplicity alillm's Avatar
    Join Date
    Mar 2004
    Location
    Wales
    Posts
    1,988
    Just made a quick lil example for you (you wont get this every time you ask for help so make the most of it ). The code is on frame 1. Ive highlighted the bit you need with coments. The rest you dont need to worry about, i thought i would just make it a bit more interesting by giving the car some simple physics .

    Ask if you have any questions

    Ali
    Attached Files Attached Files

  11. #11
    XRave tongxn's Avatar
    Join Date
    Apr 2005
    Location
    Somewhere near Here
    Posts
    870
    wow man, u got that going on!

    THANKS
    When you actually know what "OMG I have so much homework!" means, you won't want to be me.
    Xrave

  12. #12
    Certified Jackball
    Join Date
    Jul 2005
    Location
    Seattle Washington
    Posts
    132
    Hey, I know! Delete the car MC and then it can't drive out of the boundries! Damn, I'm a genius...
    srry bout my englesh, im american

    Blog Hogger

    Hogger Studios

  13. #13
    Razor
    Join Date
    Aug 2002
    Location
    Canada
    Posts
    721
    Quote Originally Posted by bloghogger1
    Hey, I know! Delete the car MC and then it can't drive out of the boundries! Damn, I'm a genius...
    Or a dumb spammer.

  14. #14
    better than chuck norris
    Join Date
    Jun 2004
    Location
    West Coast of Michigan
    Posts
    667
    no, i would go with smart ass. that's A S S! not ass with some stupid stars. @$$! i can beat the system!

    other options with walls:
    Code:
    if (land.hitTest(car._x, car._y, true)) {
        car.speed *= -.7;
    }

  15. #15
    better than chuck norris
    Join Date
    Jun 2004
    Location
    West Coast of Michigan
    Posts
    667
    no stars... wow.

  16. #16
    XRave tongxn's Avatar
    Join Date
    Apr 2005
    Location
    Somewhere near Here
    Posts
    870
    no thanks, i think the original post by alillm's better
    When you actually know what "OMG I have so much homework!" means, you won't want to be me.
    Xrave

  17. #17
    Spaghetti-Code Extraordinaire
    Join Date
    Sep 2005
    Location
    Chattanooga, TN.
    Posts
    53
    nevermind...
    I must have been in a real bad mood when I posted this.
    Last edited by hippofungus; 10-21-2005 at 11:16 AM.
    "You teach a child to read, and he or her will be able to pass a literacy test."
    Source: United Press International, "Bush Proposes Increase in Education Funds," Mark Kukis, Feb. 21, 2001

  18. #18
    Certified Jackball
    Join Date
    Jul 2005
    Location
    Seattle Washington
    Posts
    132
    Honestly, I didn't post that. I'm guessing my friend did, seeing as how he was looking around flashkit when I was in the bathroom.

    Sorry 'bout that!
    srry bout my englesh, im american

    Blog Hogger

    Hogger Studios

  19. #19
    XRave tongxn's Avatar
    Join Date
    Apr 2005
    Location
    Somewhere near Here
    Posts
    870
    Never Mind.... We all need a laugh sometimes...

    :P
    When you actually know what "OMG I have so much homework!" means, you won't want to be me.
    Xrave

Posting Permissions

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




Click Here to Expand Forum to Full Width

HTML5 Development Center