dcsimg
A Flash Developer Resource Site

Results 1 to 12 of 12

Thread: Spawning

  1. #1
    Junior Member
    Join Date
    Jan 2011
    Posts
    22

    Question Spawning

    Hi I need help with a point and click game. I currently have arrows allowing the player to swap frames. The problem is that when you click the arrow the character begins walking towards it then it swaps frames.

    I split the character layer into keyframes thinking that if I placed the character at the start of each frame it would start there. But the character keeps moving to the click point while you can skip the frames.

    Whats the best solution?

    Heres a pic to show my layers

    http://i4.photobucket.com/albums/y13...Untitled-1.jpg

  2. #2
    Senior Member Pazil's Avatar
    Join Date
    Sep 2006
    Location
    Ontario, Canada
    Posts
    913
    Just have a global boolean variable (seeing as your not doing this the OOP way anyways...) that indicates from which side the character left the last frame.
    Let's say that True is for when the player went left, and False is when the player went right.

    So if the user clicks the left arrow on the screen, have it set the variable to true, if he went right, set it to false. Then when you change frames to another one, just check the variable, and reposition the player.
    WIP-ZOMBIES

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

  3. #3
    Junior Member
    Join Date
    Jan 2011
    Posts
    22
    Thanks for the reply so far I have this:

    Arrow Code:
    Code:
    function onButtonClick(evt:MouseEvent):void {
    gotoAndStop (currentFrame + 1)
     (leaveDirection = false);}
    
    function BackButtonClick(evt:MouseEvent):void {
    gotoAndStop (currentFrame - 1)
     (leaveDirection = true);}
    I'm not sure what to put for the repositioning, is it just x,y position? so far on the backgrounds I have:

    Code:
    if(value == true) { }
    else if(value == false) {  }

  4. #4
    Senior Member Pazil's Avatar
    Join Date
    Sep 2006
    Location
    Ontario, Canada
    Posts
    913
    if (value == true) should be if (leaveDirection == true)?
    then just reposition the character in their (x/y simply, unless you need to adjust rotation and stuff...just set all his values to what you want them to be).

    And organize your code better:

    PHP Code:
    function BackButtonClick(evt:MouseEvent):void
    {
         
    gotoAndStop (currentFrame 1);
         (
    leaveDirection true);

    Btw, if you switch frames right when you click the arrow buttons, you can simply reposition the character right in your onButtonClick functions, (the x/y values).
    WIP-ZOMBIES

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

  5. #5
    Junior Member
    Join Date
    Jan 2011
    Posts
    22
    Its sort of worked it spawns the character in the 2nd frame at the start, it just goes crazy after a few swaps and starts moving the backgrounds around.
    Last edited by Vaux; 01-30-2011 at 12:02 PM.

  6. #6
    Senior Member Pazil's Avatar
    Join Date
    Sep 2006
    Location
    Ontario, Canada
    Posts
    913
    I don't have Flash CS5. Better just paste your code only relevant to the switching and spawning here.
    WIP-ZOMBIES

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

  7. #7
    Junior Member
    Join Date
    Jan 2011
    Posts
    22
    Ok

    code on character:
    Code:
    if(leaveDirection == true) { x = 28.10}
    else if(leaveDirection == false) { x = 949.05 }
    code on buttons:
    Code:
    function onButtonClick(evt:MouseEvent):void
    {
         gotoAndStop (currentFrame + 1);
         (leaveDirection = false);
    } 
    
    function BackButtonClick(evt:MouseEvent):void
    {
         gotoAndStop (currentFrame - 1);
         (leaveDirection = true);
    } 
    
    myButton.addEventListener(MouseEvent.CLICK, onButtonClick);
    
    backButton.addEventListener(MouseEvent.CLICK, BackButtonClick);
    Code:
    var leaveDirection

  8. #8
    Senior Member Pazil's Avatar
    Join Date
    Sep 2006
    Location
    Ontario, Canada
    Posts
    913
    Sorry for taking a while.

    My first suggestion is to at least put your code on your frame rather than slice'n'dice it over Movieclips etc.

    And it should work (looks like everything's good from the code), as at this point it's your setup where something might be going haywire. Try putting everything in one frame so you can actually make sense of it, and then see where that gets you...
    WIP-ZOMBIES

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

  9. #9
    Junior Member
    Join Date
    Jan 2011
    Posts
    22
    Thanks for the reply, I've shifted it all into the AS3 layer bar the mouse listerners. I've even defined the mc in the x position to make sure its just that mc. It only seems to work first try from a still position, if the character is moving it just ignores the commands and switches frames without repositioning the chracter.

    Is there any other way to enforce repositioning every frame switch?

  10. #10
    Senior Member Pazil's Avatar
    Join Date
    Sep 2006
    Location
    Ontario, Canada
    Posts
    913
    It's easier to work with a document class, which is basically an external .as file linked with your .fla. All you need to do is have a function handle the repositioning, and call it every frame switch.
    Working in the .fla with code becomes very confusing when you're tossing variables back and forth.
    WIP-ZOMBIES

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

  11. #11
    Junior Member
    Join Date
    Jan 2011
    Posts
    22
    What do I need to put in the .as file? I'm guess it'll want this code in it:

    Code:
    if(leaveDirection == true) { x = 28.10}
    else if(leaveDirection == false) { x = 949.05 }
    Then do I just call it on the swapping frame arrows?

  12. #12
    Senior Member Pazil's Avatar
    Join Date
    Sep 2006
    Location
    Ontario, Canada
    Posts
    913
    Pfff...To tell you the truth, I haven't worked with the IDE for ages, so linking code and using it in the timeline is totally unfamiliar to me.

    I say your best bet is to look up tutorials before you code anything more...
    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