A Flash Developer Resource Site

Page 1 of 2 12 LastLast
Results 1 to 20 of 23

Thread: [RESOLVED] [help]traffic control game

  1. #1
    Junior Member
    Join Date
    Aug 2010
    Location
    Jakarta,Indonesia
    Posts
    15

    resolved [RESOLVED] [help]traffic control game

    Hi
    I want to make these kind of game
    http://www.youtube.com/watch?v=_H_aqDcTzcg

    but in more compleks route, and i want to make the car can choose direction (straigt, turn left of turn right)

    but 1st thing 1st.

    i need a logical state for the timeline

    how the car works?
    how can i set the car run independently?
    because it can't be done in the main timeline.
    i'm guessing it has something to do the the action script, but i have no idea.

    i'm kinnda new to flash, this is the 1st time i want to create a AI-like programing with flash.

    please help, thanks.

    Im using CS4
    Last edited by whitelynx_nivla; 08-28-2010 at 12:03 PM. Reason: resolved for now

  2. #2
    Lunatic
    Join Date
    Nov 2002
    Location
    AS3 Forum
    Posts
    342
    I don't mean to be a d*ck but looking at your first post, I'm thinking this might be way too advanced for you.

    You're gonna wanna stay away from the timeline altogether when you create a project like this. Everything would be done through code.

    You should probably start with a small project where you don't use the timeline at all and make everything happen from the code. Then you can go from there.

  3. #3
    Flash/Flex Developer samac1068's Avatar
    Join Date
    Apr 2007
    Location
    Here, no there
    Posts
    1,813
    I agree with Beathoven. I've been programming a while and I've been reluctant to built these site because I don't feel I have enough experience with the language. Programming AI isn't something you can do on a whim.
    Some people are like Slinkies, not really good for anything, but they bring a smile to your face when pushed down the stairs.

  4. #4
    Lunatic
    Join Date
    Nov 2002
    Location
    AS3 Forum
    Posts
    342
    To get you started, I would have a couple classes separated as follow:

    Level : contains the level, the bounds that the cars are allowed in.

    Car: contains all the information about the car, where it's trying to go.

    Lights: Traffic light objects, graphics & dispatches "go & stop events". The events would let all the other objects if they can go through the lights in the direction they're trying to go. Lights would be a child of level.

    Then you would have your main document class that would generate a level object and random car objects coming in from the different possible entry roads.

    That would be the base logic behind it.

  5. #5
    Junior Member
    Join Date
    Aug 2010
    Location
    Jakarta,Indonesia
    Posts
    15
    Quote Originally Posted by Beathoven View Post
    I don't mean to be a d*ck but looking at your first post, I'm thinking this might be way too advanced for you.

    You're gonna wanna stay away from the timeline altogether when you create a project like this. Everything would be done through code.

    You should probably start with a small project where you don't use the timeline at all and make everything happen from the code. Then you can go from there.
    Quote Originally Posted by samac1068 View Post
    I agree with Beathoven. I've been programming a while and I've been reluctant to built these site because I don't feel I have enough experience with the language. Programming AI isn't something you can do on a whim.
    thanks for the sugestions
    but I already make couples of AI program with other language, such as C++ and Java
    Now I want to pick up Flash because I think I can manipulate the animation more easily with it (CMIIW)

    Quote Originally Posted by Beathoven View Post
    To get you started, I would have a couple classes separated as follow:

    Level : contains the level, the bounds that the cars are allowed in.

    Car: contains all the information about the car, where it's trying to go.

    Lights: Traffic light objects, graphics & dispatches "go & stop events". The events would let all the other objects if they can go through the lights in the direction they're trying to go. Lights would be a child of level.

    Then you would have your main document class that would generate a level object and random car objects coming in from the different possible entry roads.

    That would be the base logic behind it.
    Thanks
    Very helping

    About the cars, just to make sure, I really can't animate it with time line right?I have to move it with code right?

  6. #6
    Lunatic
    Join Date
    Nov 2002
    Location
    AS3 Forum
    Posts
    342
    Well if you're making a game, you're probably gonna wanna randomise where and when the stuff comes in (In this case the cars). You're gonna want the car to go from point A to point B, C, D or E randomly. Thus you will have to animate them accordingly.

    You're gonna have to create a car object and pass it a 'route' argument. Starting point finish point. And then you will have to programmatically figure how to get from said start and finish points. You will have to hittest and account for other cars as well as lights along the way.

    The animations will be fairly easy. They are simple Tweens.

    They are created this way:

    var myCarTween:Tween = new Tween(myCar_mc, "x", Strong.easeIn, 0, 1, 500, false);

    And there you have it, you're car is moving along the x axis from x:0 to x:1 in 500 milliseconds.

    Most properties can be tweened easily (x, y, width, height, rotation, etc.). That makes it even easier to deal with than the actual time line.

    Does that help a bit?
    Last edited by Beathoven; 08-27-2010 at 12:18 PM.

  7. #7
    Junior Member
    Join Date
    Aug 2010
    Location
    Jakarta,Indonesia
    Posts
    15
    Quote Originally Posted by Beathoven View Post
    Well if you're making a game, you're probably gonna wanna randomise where and when the stuff comes in (In this case the cars). You're gonna want the car to go from point A to point B, C, D or E randomly. Thus you will have to animate them accordingly.

    You're gonna have to create a car object and pass it a 'route' instance. Starting point finish point. And then you will have to programmatically figure how to get from said start and finish points. You will have to hittest and account for other cars as well as lights along the way.

    The animations will be fairly easy. They are simple Tweens.

    They are created this way:

    var myCarTween:Tween = new Tween(myCar_mc, x, Strong.easeIn, 0, 1, 500, false);

    And there you have it, you're car is moving along the x axis from x:0 to x:1 in 500 milliseconds.

    Most properties can be tweened easily (x, y, width, height, rotation, etc.). That makes it even easier to deal with than the actual time line.

    Does that help a bit?
    Yes
    I've sorted out the points where the car start, but I didnt manage to find an easy way to animate the car to run

    Thanks, i'll try to use that code.

    what's the flase statement in the last code for?

  8. #8
    Lunatic
    Join Date
    Nov 2002
    Location
    AS3 Forum
    Posts
    342
    Tween Class is defined like this:

    Tween (Object To Tween, Property To Tween, Easing Function, Start Value, End Value, Timespan, TimeSpan in Seconds:Boolean)

    False means my timespan value will be interpreted in milliseconds.

  9. #9
    Junior Member
    Join Date
    Aug 2010
    Location
    Jakarta,Indonesia
    Posts
    15
    Quote Originally Posted by Beathoven View Post
    Tween Class is defined like this:

    Tween (Object To Tween, Property To Tween, Easing Function, Start Value, End Value, Timespan, TimeSpan in Seconds:Boolean)

    False means my timespan value will be interpreted in milliseconds.
    many2 thanks.
    i'm trying it now
    Last edited by whitelynx_nivla; 08-27-2010 at 12:04 PM.

  10. #10
    Lunatic
    Join Date
    Nov 2002
    Location
    AS3 Forum
    Posts
    342
    P.S: Property to Tween is of type String, so you have to pass it like this:

    Tween(myMc, "alpha", Strong.easeIn, 0, 1, 1, true);

  11. #11
    Junior Member
    Join Date
    Aug 2010
    Location
    Jakarta,Indonesia
    Posts
    15
    Hmm
    i got errors
    1046 : type was not found or was not a compile-time constan
    1180 : call to a possible undefined method Tweeen.
    1120 : Access of imdefinged propertu Strong.

    also, when I type Strong.easIn it request input
    (t:Number,b:Number,c:Number,d:Number):Number

    Should I leave them blank?

  12. #12
    Lunatic
    Join Date
    Nov 2002
    Location
    AS3 Forum
    Posts
    342
    First you need to import the Tweening and easing classes in your code:

    import fl.transitions.Tween;
    import fl.transitions.easing.*;

    Just so you know there's other easing algorythms. Just google "easing actionscript 3" and the adobe website will have documentation on all possible easing types.

  13. #13
    Junior Member
    Join Date
    Aug 2010
    Location
    Jakarta,Indonesia
    Posts
    15
    Quote Originally Posted by Beathoven View Post
    First you need to import the Tweening and easing classes in your code:

    import fl.transitions.Tween;
    import fl.transitions.easing.*;

    Just so you know there's other easing algorythms. Just google "easing actionscript 3" and the adobe website will have documentation on all possible easing types.
    thanks
    i'll play with the code for some time now.

    i'll let you know if there's another problem

    thanks Beathoven

  14. #14
    Junior Member
    Join Date
    Aug 2010
    Location
    Jakarta,Indonesia
    Posts
    15
    sorry to bother again

    i've imported the classes

    and there's no errors

    but i dont see the car anaimated
    i thought that 500ms is too fast, so i pump up to 5000, but still it wont animated.

    the car's just sitting there on the starter x and y koodinates.

    did i put the code at the wrong layer?
    i put it on seperate layer, at the same time where the car is created.

    should i put it on the same layer as the car movie symbol?

  15. #15
    Lunatic
    Join Date
    Nov 2002
    Location
    AS3 Forum
    Posts
    342
    First off you have to make sure that the car has a name.

    Click on your car instance and look in the properties tab. You'll see you have a car of instance "car_mc" but above it it won't have a name. So assign it the name you're gonna use to refer to it.

    Then use that name in the code.

    Now I have to warn you, I can already tell you're using the timeline and layers and it's gonna become very messy very quick.

    I don't think you grasp the concept of Object Oriented Programming yet. You should probably look into it before getting any further ahead.

    Your FLA file should contain 1 frame and 1 layer with a initiating document class assigned to it. Everything blank. The library can contain your fonts and your visual objects. For instance you could design the car inside the fla as a MovieClip and keep it in the library. From there you would export the car_mc object for actionscript so you can refer to it and create it on the fly within the code.

  16. #16
    Junior Member
    Join Date
    Aug 2010
    Location
    Jakarta,Indonesia
    Posts
    15
    Quote Originally Posted by Beathoven View Post
    First off you have to make sure that the car has a name.

    Click on your car instance and look in the properties tab. You'll see you have a car of instance "car_mc" but above it it won't have a name. So assign it the name you're gonna use to refer to it.

    Then use that name in the code.

    Now I have to warn you, I can already tell you're using the timeline and layers and it's gonna become very messy very quick.

    I don't think you grasp the concept of Object Oriented Programming yet. You should probably look into it before getting any further ahead.

    Your FLA file should contain 1 frame and 1 layer with a initiating document class assigned to it. Everything blank. The library can contain your fonts and your visual objects. For instance you could design the car inside the fla as a MovieClip and keep it in the library. From there you would export the car_mc object for actionscript so you can refer to it and create it on the fly within the code.
    Hmm
    Yes, my car image's name is car.jpg
    and the instance name of the movie clip from that image is car_mc

    maybe I am not ready for this...
    I'll starting with more simple task

    thanks for helping me so far.

  17. #17
    Lunatic
    Join Date
    Nov 2002
    Location
    AS3 Forum
    Posts
    342
    Just to make sure we're on the same page here.

    You imported car.jpg to the stage.

    You converted it to a MovieClip symbol (Right click, Convert To Symbol...)

    And then you clicked on it, went in the properties panel and changed <Instance Name> to car_mc (As shown in the attached picture).

    You then made your tween in the actionscrip this way:

    var myTween:Tween = new Tween(car_mc, "x", Strong.easeIn, 0, 100, 500, false);
    Attached Images Attached Images

  18. #18
    Junior Member
    Join Date
    Aug 2010
    Location
    Jakarta,Indonesia
    Posts
    15
    Quote Originally Posted by Beathoven View Post
    Just to make sure we're on the same page here.

    You imported car.jpg to the stage.

    You converted it to a MovieClip symbol (Right click, Convert To Symbol...)

    And then you clicked on it, went in the properties panel and changed <Instance Name> to car_mc (As shown in the attached picture).

    You then made your tween in the actionscrip this way:

    var myTween:Tween = new Tween(car_mc, "x", Strong.easeIn, 0, 100, 500, false);
    yes I did
    I also chage the 500 to 5000 so that I can see the movement more easy.
    5000mili seconds means 5 seconds for the movement right?

    Also I tried to move in Y cordinate
    so I wrote
    var myTweenX:Tween = new Tween(car_mc, "x", Strong.easeIn, 0, 100, 5000, false);
    var myTweenY:Tween = new Tween(car_mc, "y", Strong.easeIn, 100, 200, 5000, false);

    I aslo put stop(); at the end of the script, because there's a simple timeline tween animation for the prolog.
    I dont want the prolog to be looping around each time the time line ends.
    Does it effect the code?
    Last edited by whitelynx_nivla; 08-27-2010 at 04:40 PM.

  19. #19
    Lunatic
    Join Date
    Nov 2002
    Location
    AS3 Forum
    Posts
    342
    Can you post your fla file?

  20. #20
    Lunatic
    Join Date
    Nov 2002
    Location
    AS3 Forum
    Posts
    342
    Quote Originally Posted by whitelynx_nivla View Post
    yes I did
    I also chage the 500 to 5000 so that I can see the movement more easy.
    5000mili seconds means 5 seconds for the movement right?

    Also I tried to move in Y cordinate
    so I wrote
    var myTweenX:Tween = new Tween(car_mc, "x", Strong.easeIn, 0, 100, 5000, false);
    var myTweenY:Tween = new Tween(car_mc, "y", Strong.easeIn, 100, 200, 5000, false);

    I aslo put stop(); at the end of the script, because there's a simple timeline tween animation for the prolog.
    I dont want the prolog to be looping around each time the time line ends.
    Does it effect the code?
    Just as a note, Tweens created within the actionscript are 'asynchronous' which means they are not affected by the timeline.

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