A Flash Developer Resource Site

Results 1 to 9 of 9

Thread: randomizing characters

  1. #1
    Junior Member
    Join Date
    Jul 2009
    Location
    loveland, OH
    Posts
    5

    randomizing characters

    I'm making a "wheres waldo or i-spy" type game that involves randomizing characters in a different order in each level. i will also like to do it with the main character too.

    can anyone please help.

  2. #2
    Ө_ө sleepy mod
    Join Date
    Mar 2003
    Location
    Oregon, USA
    Posts
    2,441
    Can you be a little more specific? What are you having trouble with?

  3. #3
    Junior Member
    Join Date
    Jul 2009
    Location
    loveland, OH
    Posts
    5
    Quote Originally Posted by neznein9 View Post
    Can you be a little more specific? What are you having trouble with?

    Im trying to have some characters randomize on the screen, and at the same time have one main character do the same by its seslf. Then when you click on one character it does everything again on a different screen.

  4. #4
    Senior Member caroach's Avatar
    Join Date
    Nov 2002
    Location
    Chicago, IL
    Posts
    374
    Are you just randomizing the position of the characters on the stage?
    moo

  5. #5
    lemon juice hurts your eyes florianvanthuyn's Avatar
    Join Date
    Jul 2005
    Location
    Merelbeke, Belgium
    Posts
    546
    When you store your characters in a MovieClip with on each frame one character and a stop(); action on the first frame, you can randomize the character shown with:
    PHP Code:
    myMC.gotoAndStop(Math.round(Math.random()*myMC.totalFrames)); 
    Which will take the MovieClip to a random frame.
    Randomizing it's position on the screen can be done with this:
    PHP Code:
    myMC.Math.random()*(stage.stageWidth myMC.width);
    myMC.Math.random()*(stage.stageHeight myMC.height); 
    Which will position the MovieClip anywhere on the stage without it ever leaving the edges (but then it's registration point must be top left).
    Florian Vanthuyne

    WAR AGAINST SOLVED THREADS
    mark yours as Resolved under Thread Tools!

  6. #6
    Junior Member
    Join Date
    Jul 2009
    Location
    loveland, OH
    Posts
    5

    making an array to randomize the backgrounds

    to go with my "where's waldo?" game i need to make it so when you click on the one character it changes to a random background everytime, and it doesnt change when you click on the wrong character.

  7. #7
    lemon juice hurts your eyes florianvanthuyn's Avatar
    Join Date
    Jul 2005
    Location
    Merelbeke, Belgium
    Posts
    546
    Use a MovieClip with one background / keyframe (and stop(); on the first keyframe).

    then use:
    PHP Code:
    function clickHandler(e:MouseEvent):void
    {
       if(
    MovieClip(e.currentTarget) == wallyMC)
       {
          
    backgroundMC.gotoAndPlay(Math.round(Math.random()*(backgroundMC.totalFrames 1) + 1));
       }

    Of course, wallyMC should be the name or instance name of the right Button
    Florian Vanthuyne

    WAR AGAINST SOLVED THREADS
    mark yours as Resolved under Thread Tools!

  8. #8
    Junior Member
    Join Date
    Jul 2009
    Location
    loveland, OH
    Posts
    5

    score limit to win or lose

    How would i go about, when you reach a score limit it goes to a win screen and if you dont it goes to a lose screen? and i also need some help with a timer.

  9. #9
    lemon juice hurts your eyes florianvanthuyn's Avatar
    Join Date
    Jul 2005
    Location
    Merelbeke, Belgium
    Posts
    546
    A Timer is used this way:
    PHP Code:
    var t:Timer = new Timer(delay,repeat_count); 
    delay - number in miliseconds; time between Timer ticks; 1000 = 1 sec
    repeat_count - number of times to count; 0 = endless;

    So to start a timer and use it, you need to call its start() function and add an EventListener to it:
    PHP Code:
    t.start();
    t.addEventListener(TimerEvent.TIMERtimerHandler);

    function 
    timerHandler(e:TimerEvent):void
    {
       
    // do your stuff;

    To know when the timer ends, you can use TimerEvent.TIMER_COMPLETE, rather than TimerEvent.TIMER, or use if(t.currentCount == repeat_count) in which repeat_count is of course the number you entered in the first line of code.

    To stop the Timer, simply call its stop() function, just like you started it.

    The score is probably stored in a variable / textbox, so simply retrieve that value and check if it's reached the minimum score and have to movie jump to a different frame which shows either the win screen or the loose screen:
    PHP Code:
    if(theScore >= 12gotoAndStop(2);
    else 
    gotoAndStop(3); 
    Florian Vanthuyne

    WAR AGAINST SOLVED THREADS
    mark yours as Resolved under Thread Tools!

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