A Flash Developer Resource Site

Results 1 to 8 of 8

Thread: need help for collision basics

  1. #1
    Member
    Join Date
    Dec 2006
    Posts
    31

    need help for collision basics

    This is for a roommaker type game. In my game I have a radio/cd player and little different colored discs. What I want to do is when the disc is drug onto the top of the cd player it will play the song that is chosen for that disc color.

    I really do not know anything about collision. I have been searching and reading for hours now and still can not get my test to work. (I am using the bell sound for the test and not a whole song.)

    I know that the elements need to be assigned first. I have:

    Code:
    lid=element ("lid")
    disc.element ("disc")
    Where does that start script go? This may sound silly, but I really don't know where to put these things.

    Then I have the collision script:

    Code:
    if (disc.collideRect(lid)){
    playSound ("bells")
    }
    First, is this correct? Then, of course, where does that script go? Do you use Boundry Detection? I understand the coding, just not where in the world to put the scripts.

    Please, some help ring my bell. Oops. ha ha

  2. #2
    Senior Member
    Join Date
    Dec 2006
    Posts
    274
    There is lot of tutorial about drag & drop..
    I have newer user drag&drop but it should go bit like this:

    square_mc = element ("square_mc");
    squareTarget_mc = element ("squareTarget_mc");
    reply_txt = element ("reply_text");

    square_mc.onPress = function():Void {
    this.startDrag(true);
    };
    square_mc.onRelease = function():Void {
    this.stopDrag();
    if (square_mc._droptarget == squareTarget_mc) {
    reply_txt.text="You got it!";
    }
    else {
    reply_txt.text="No, keep trying!";
    }

    };
    but this wont work somehow... ondrop & ondrag 3dfa events could be useful for situations like this.. as drag & drop functionality is "available" but I did not find any way to trigger "onDrop" event... mayby I'm just forget how this works.. ?!

  3. #3
    Game Master ConnELITE's Avatar
    Join Date
    Apr 2005
    Location
    United States, DC
    Posts
    474
    Hi, theres a button labled "Move Script" near the top just under the preview and export buttons. The first script should go there. The second script should be placed in a script element (add new element>script) and should run every frame.

    Hope this helps.
    BC

  4. #4
    Member
    Join Date
    Dec 2006
    Posts
    31
    Thank you both. I am working on it now. do you know if the collision will work if the element is made draggable? I am going to keep working on and reading about until I get this to work.
    Beauty is only a light switch away.

  5. #5
    Member
    Join Date
    Dec 2006
    Posts
    31
    Okay, again thanks for your pervious help. With a bit more reading, thinking and testing I have decided that it might be easier to have the sound play when released in the spot where the top of the cd player is and have the disc "snap" to the area, because right now I have it work onRelease.

    The only thing I can not find or figure out is the syntax for the variables x and y. How is this done? I really think I should know this. But I really think I need a break. Sometimes that helps.
    Beauty is only a light switch away.

  6. #6
    Member
    Join Date
    Dec 2006
    Posts
    31
    Okay, a break did me good. Sometimes you get stuck on one idea you know, so after my break I decided to go the route of if you click on the disc, it snaps to the top of the cd player and plays the song. When you click on the disc again, it snaps it back to the discs original place. I have not completely abandoned the drag and drop idea but this will give me a change to work on it while I still have something to offer.

    One question on that note then. I can assign a number (like 100) for the x and y. But what do I use to make it so that x and y equal their current position? In theory, that would solve my drag and drop problem.

    Thanks again for all the help...it really does help.
    Beauty is only a light switch away.

  7. #7
    Senior Member
    Join Date
    Dec 2006
    Posts
    274
    Syntax for variables x & y ???
    x & y are the current positions,,. if you set x=10, y=20 then they are the new current position. If you like to store old or whatever positions then you set new variables and assign values to them.. something like:
    var ox = myelement.x;
    var oy = myelement.y;

  8. #8
    Member
    Join Date
    Dec 2006
    Posts
    31
    I used 2 discs. When you release the first one it changes to the second one and stops the song. But I learned that x = x if you want assign the second disc the current position of the first disc. I don't think collision works for drag and drop, do you know?

    I think i'll stick to the click on and snap to idea.
    Beauty is only a light switch away.

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