A Flash Developer Resource Site

Results 1 to 8 of 8

Thread: [MX04] [Problem] swap depths don't work properly

  1. #1
    Member
    Join Date
    Nov 2005
    Posts
    42

    [MX04] [Problem] swap depths don't work properly

    Hi guys,
    I have a frustrating problem! I have created a "hero" that I can move with cursor keys and an animated "baddie" that just walks around at the moment. Inside the animated bad guy there is 2 movie clips, one movie clip to make the "hero" appear in front of the baddie with this code.

    onClipEvent(enterFrame){
    if(this.hitTest(_root.man.hit_area) and _global.ogre_in_front == true){

    _root.ogre.swapDepths(_root.man);
    _global.ogre_in_front = false;

    }

    }
    And the MC that pushes the "hero" to the background is

    _global.ogre_in_front = false;
    onClipEvent(enterFrame){
    if(this.hitTest(_root.man.hit_area) and _global.ogre_in_front == false){

    _root.ogre.swapDepths(_root.man);
    _global.ogre_in_front = true;

    }

    }

    The problem is that the "hero" doesn't always go behind when he should the swap depths seem to get confused very quickly and some times they don't seem to swap at all. Does anyone have any ideas? Thanks in advance!

  2. #2
    ....he's amazing!!! lesli_felix's Avatar
    Join Date
    Nov 2000
    Location
    London UK
    Posts
    1,506
    Can the two hitTests be positive at the same time?

    (ignore the ogre_in_front variable, just look at the hitTests)

  3. #3
    Member
    Join Date
    Nov 2005
    Posts
    42
    Tried it but without the in_front variable the character just seems to flicker

  4. #4
    ....he's amazing!!! lesli_felix's Avatar
    Join Date
    Nov 2000
    Location
    London UK
    Posts
    1,506
    I think that will happen either way if the two hittests can be activated at the same time.

    use trace statements in each function to find out whats happening, but I think you'll find that the two functions are swapping depths continuously.

  5. #5
    Senior Member Ray Beez's Avatar
    Join Date
    Jun 2000
    Posts
    2,793
    Also is this correct?

    if(this.hitTest(_root.man.hit_area) and _global.ogre_in_front == false){

    To me that looks wrong. I always seperate different condition tests with parenthesis:

    if((this.hitTest(_root.man.hit_area)) and (_global.ogre_in_front == false)){

  6. #6
    Member
    Join Date
    Nov 2005
    Posts
    42
    maybe that's why the code wasn't playing properly in the first place?

  7. #7
    Senior Member
    Join Date
    Sep 2004
    Posts
    633
    _global.ogre_in_front = false; or true
    maybe the problem is in the part of code which decides when ogre is in front or the back?

  8. #8
    M.D. mr_malee's Avatar
    Join Date
    Dec 2002
    Location
    Shelter
    Posts
    4,139
    does the hero go behind an ogre when he's above it (vertically higher?) if so just use the _y property to swap depths
    lather yourself up with soap - soap arcade

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