A Flash Developer Resource Site

Results 1 to 18 of 18

Thread: [RESOLVED] help on collision detection, please

  1. #1
    Senior Member
    Join Date
    Jan 2007
    Location
    Barcelona
    Posts
    389

    resolved [RESOLVED] help on collision detection, please

    Hi,

    I'm having trouble understanding why I can't detect a collision with the hitTest method in my file.

    My goal is to detect the avatars in my file being attached on a clip named board in order to have something happening on collision but I've been trying so many different ways, I just don't know what to try.

    I've just attached a different clip on stage and still no collision is detected. Could this be a depth problem?




    here's my file:



    https://onedrive.live.com/?cid=CD824...10C6E8AC%21131

  2. #2
    . fruitbeard's Avatar
    Join Date
    Oct 2011
    Posts
    1,780
    Hi Cap,

    Try

    if(myAvatar.hitTest(board.ball))
    {
    trace("Collision");
    }

    you missed the board before the ball
    you should try to delete your onEnterFrames at some point( once avatar reaches its destination point maybe) as it drives your file crazy after a while.

  3. #3
    Senior Member
    Join Date
    Jan 2007
    Location
    Barcelona
    Posts
    389
    Hi, thanks, Fruit!

    I can't believe it! I've been trying to trace this so many times, I must have got a positive trace and missed it. I had tried referencing the ball like you suggest.

    Obviously, it's not the ball I want to be able to have my avatars collide with. It's my characters.

    I can't tell a difference. They are movieclips as well.

    Whenever I tried to hit Test myAvatar with myAvatar, nothing would happen and that's why I added a different instance name when creating the avatars, but I can't achieve a thing.

    About deleteing the onEnterFrames, I bet you're right, and I'd do so as soon as I saw the way to check for a collision. That should be simple setting the inited flag to false and back to true again once the clip I want to attach finishes playing.

    I don't know, I'm rereading the smartfox tutorial over and over but I can't come to a conclusion. I've no clue of how the variables are passed...

    Would you say creating arrays to store the avatar names would help?

  4. #4
    . fruitbeard's Avatar
    Join Date
    Oct 2011
    Posts
    1,780
    Hi Cap,

    This might help you a little, instead of the hitTest(board.ball) code try
    PHP Code:
    for (0userList_lb.lengthj++)
    {
        var 
    a:Object userList_lb.getItemAt(j).data;
        
    trace(a);
        var 
    b:MovieClip board["clip_" a];
        
    trace(b);
        if (
    b.hitTest(myAvatar._xmyAvatar._ytrue))
        {
            
    trace("Collision " b);
            
    delete onEnterFrame;
        }

    its somewhat rusty but it does hit, you will need to implement it elsewhere in the code too.

    good luck

  5. #5
    Senior Member
    Join Date
    Jan 2007
    Location
    Barcelona
    Posts
    389
    thanks,

    I wish I saw this clearer.

    I have tried it and now I figure I will have to update that new info to the variable updating method.

    Like you said, having that happen onEnterFrame might not be a good idea...

    How could I set a flag or way to stop the onEnterFrame to keep sending the variables?

  6. #6
    . fruitbeard's Avatar
    Join Date
    Oct 2011
    Posts
    1,780
    Hi Cap,

    I would recommend going back to the original avatar chat from smartfox and just use the uVars for a male or female icon.
    That way the avatars move properly and the enterframes stop when required.

    You can still add the copy chat text and other things and messa round with the look and feel.

  7. #7
    . fruitbeard's Avatar
    Join Date
    Oct 2011
    Posts
    1,780
    Hi Cap,

    I have altered the original one for you, it has male and female avatar combined.
    You will need to add the copy chat feature, perhaps I can do it later if you feel like you can not do it'
    fruitbeard.net/uploaded/capChat.zip

    I would suggest leaving the room list there too, so you and the dona can chase each other around the rooms

  8. #8
    . fruitbeard's Avatar
    Join Date
    Oct 2011
    Posts
    1,780
    Hi Cap,

    If you download the files, then find a line in the chat code like this
    myAvatar.easingTo("Quint", "InOut", px, py, 100);

    and put directly underneath it the code below so it looks like this
    PHP Code:
    myAvatar.easingTo("Quint""InOut"pxpy100);
    myAvatar.onEnterFrame = function()
    {
        if(
    myAvatar._x == px && myAvatar._y == py)
        {
            
    delete myAvatar.onEnterFrame;
            
    trace("I have finished moving");
        }

    this will tell you when your avatar has finished moving and delete the onEnterFrame.

    smartfox doesnt actually use any onEnterFrames, this is the one we add and the only one.

    you may need to put one for the other mc.easingTo("Quint", "InOut", uVars.px, uVars.py, 100); code!!

    but try it all out first then add things as you go along.

  9. #9
    Senior Member
    Join Date
    Jan 2007
    Location
    Barcelona
    Posts
    389
    Hey, thanks.

    Will try it. But, can't really understand the moving deal. SmartFox adds those 2 extra files, one being an include and the other a class. I think I checked on it before and it will call onEnterFrame as well.

    What if I moved the code into a function where onEnterFrame is deleted each time?

    Anyway, thanks, I'm in class now. I will check on it tonight.

  10. #10
    . fruitbeard's Avatar
    Join Date
    Oct 2011
    Posts
    1,780
    Hi Cap,

    Nope, smartfox using no onEnterFrames, the tween uses an interval if you look of 100ms, I have given you a small amount of code using an onEnterFrame and it deletes it once the avatar reaches its destination point.

    You did try to use 3 onEnterFrames in your other files but deleted none of them.

    Whats with the love of onEnterFrames Cap?

  11. #11
    . fruitbeard's Avatar
    Join Date
    Oct 2011
    Posts
    1,780
    Hi again Cap,

    I have been busy, I'm not sure how you test your files at home!
    I use smartfox , open the window in flash and one the swf from the folder so I can see two avatars in the room.

    This file now detects the hit of the other avatar and traces a message, only traces from the flash version, but I'm sure you can make it work on both

    http://fruitbeard.net/uploaded/capChat2.zip

  12. #12
    . fruitbeard's Avatar
    Join Date
    Oct 2011
    Posts
    1,780
    Hi Cap,

    Again

    Try this one, I have a hit, but for the life of me I can not get the message window to pop up, perhaps you can figure it out, I have been on it too long.

    http://fruitbeard.net/uploaded/capChat3.zip

  13. #13
    . fruitbeard's Avatar
    Join Date
    Oct 2011
    Posts
    1,780
    Cap,

    check your email now

  14. #14
    Senior Member
    Join Date
    Jan 2007
    Location
    Barcelona
    Posts
    389
    hi,

    I thought I understood how to make my avatars collide and I think I managed now crosschecking clips wherever it needed to be done, but I want to add a clip that turns my avatars visibility back as soon as it ends and it seems to be attached without me knowing it. (I get that trace).

    If the clips do hit and the attached clip pops up it won't always disappear. Could it be because the colliding clips are still colliding and if so, is there a way to turn hitTest off until the attached clip disappears.

    here's my file:

    https://onedrive.live.com/?cid=CD824...10C6E8AC%21131

  15. #15
    . fruitbeard's Avatar
    Join Date
    Oct 2011
    Posts
    1,780
    Hi Cap,

    I know the avatars are quite large clips so you need to make the hittest smaller,

    so instead of if(mc.hitTest(myAvatar)

    use if(mc.character.hitTest(myAvatar.character)

    and instead of b.hitTest(myAvatar)

    use b.character.hitTest(myAvatar.character)

    this will make it so only avatar.character is available for the hitTest

    what you need to do after the hitTest is true is add an interval or timeout to make both clips visible again, setTimeout is probably better, also make _global.isBusy = true when it hits and set _global.isBusy = false after the tmieout

  16. #16
    Senior Member
    Join Date
    Jan 2007
    Location
    Barcelona
    Posts
    389
    Thanks,

    you're so right.

    Makes sense that the hitTest area is smaller for the avatars.

    I've added those lines to the end of the clip attached and it sort of works, but it only does so for one of the avatars.

    Any idea why?

  17. #17
    Senior Member
    Join Date
    Jan 2007
    Location
    Barcelona
    Posts
    389
    only one of them becomes visible again.

    https://onedrive.live.com/?cid=CD824...10C6E8AC%21131


    am I not referring to the clips right from the attached ball?

  18. #18
    Senior Member
    Join Date
    Jan 2007
    Location
    Barcelona
    Posts
    389
    Hi, Fruit,

    hope the weekend has been alright.

    I've been working on my file for hours and can't find a way to have it work. I don't think things are too normal...

    Look at this:

    Code:
    if (mc.character.hitTest(myAvatar.character) && mc.gender != myAvatar.gender) {
    	delete onEnterFrame;
    	_global.isBusy = true;
    	mc._visible = false;
    	myAvatar._visible = false;
    	// _root.attachMovie("ball", "ball", _root.getNextHighestDepth(), {_x:myAvatar._x,_y:myAvatar._y});
    }
    when I test it, the clip keeps being attached.

    I have been trying to figure out what you mean by timeout and have tried to apply a function named like that in my userVariablesUpdate event handler, but haven't been able to get it working.

    I have tried:

    function setTimeOut(){
    _global.isBusy = false;
    mc._visible = true;
    myAvatar._visible = true
    _root.ball.removeMovieClip();
    }

    and then setInterval("setTimeOut", 3000); instead of attaching the ball clip.

    was this very wrong?

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