A Flash Developer Resource Site

Results 1 to 6 of 6

Thread: Problem with Hittest and Random Frames

  1. #1
    Junior Member
    Join Date
    May 2011
    Posts
    7

    Problem with Hittest and Random Frames

    Well, I tried to make a code so that when the main character hittests the talking character that the talking character would go to a random frame to display a random message. The problem was that when the space bar is down, it will continuously go to random frames without stopping... What I'm really trying to accomplish here, is to make it so that when the space bar is held down It goes to and stops on a random frame of the talking character, and when the space bar is released the talking character returns to frame one (Which is the idle stance).
    Sorry for the mouthful, I don't want to confuse anyone. Thanks a bunch
    PHP Code:
    onClipEvent(enterFrame) {
         if (
    this.hitTest(_root.char) && Key.isDown(Key.SPACE)) {
            
    _root.talkingchar.gotoAndStop(random(4)+2);
        }
        else if (!(
    Key.isDown(Key.SPACE))) {
            
    _root.talkingchar.gotoAndStop(1);
        }

    sample of game also attached
    Attached Files Attached Files

  2. #2
    Senior Member Pazil's Avatar
    Join Date
    Sep 2006
    Location
    Ontario, Canada
    Posts
    913
    PHP Code:
    if (this.hitTest(_root.char) && Key.isDown(Key.SPACE) && _root.talkingchar.currentFrame == 1
    Or have a boolean value that you reset every time you release space. That way you can have different idle frames for the talking character.

    In return for me helping you out, be sure to check back to these forums once in a while and help out where you can!
    WIP-ZOMBIES

    I love vegetarians! More meat for the rest of us!

  3. #3
    Junior Member
    Join Date
    May 2011
    Posts
    7
    Where do I place this code? When I replaced the second line of code with your code it did not work. Is there something else I must input to make the code function? I'm kind of new to action script 2.0 and I'm not to familiar with Boolean functions. Can you help out a bit more? Thanks

  4. #4
    Senior Member Pazil's Avatar
    Join Date
    Sep 2006
    Location
    Ontario, Canada
    Posts
    913
    _root.talkingchar._currentFrame

    And you had it, in the 2nd line. But dude, just check out the properties of the movieclip yourself

    I should've noticed you were using AS2.0...
    WIP-ZOMBIES

    I love vegetarians! More meat for the rest of us!

  5. #5
    Junior Member
    Join Date
    May 2011
    Posts
    7
    He he, I really don't understand how the code works, but it functioned flawlessly, thanks a bunch! And I will go back to the forums to try to help others out.

  6. #6
    Senior Member Pazil's Avatar
    Join Date
    Sep 2006
    Location
    Ontario, Canada
    Posts
    913
    It's checking to see if the character is on frame 1 before changing the frame, and then changes the frame randomly, and so it is no longer on frame 1, and doesn't enter the statement again.
    WIP-ZOMBIES

    I love vegetarians! More meat for the rest of us!

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