The forums have permanently moved to forum.kirupa.com. This forum will be kept around in read-only mode for archival purposes. To learn how to continue using your existing account on the new forums, check out this thread.


Results 1 to 10 of 10

Thread: Dragging an item over another

  1. #1

    Dragging an item over another

    I want to drag a picture over a grey box, and when I release the mouse button the picture to appear in the gray box. Easy peasy so far, right?

    Well I also want the grey box to have an outline appear when you are dragging the item over it, but the outline to disappear when you move it away again.

    rollOver events aren't triggered when you are dragging an object, so I was wondering what the best and most efficient way of doing this is. I was thinking of running a hitTest every frame to see if our dragging box is touching a grey box, but that seems inefficient. Also there will be up to 10 grey boxes - and I don't want to run a hitTest to check for 10 boxes every frame!

    Can anyone suggest the best method in AS2 please?
    ----------------------
    Flasher Games

  2. #2
    check distance from mouse.
    MY BLOG

    I need a SPRITER who can do pixel arts for an arcade fighter project. If you can help out, please pm me.
    I also need someone who can write simple xml files.


  3. #3
    not a bad idea, but I still have to run a check for that on every box on every frame
    ----------------------
    Flasher Games

  4. #4
    does 10 hittests a frame really lag that much? i think most games do a lot more than that.

  5. #5
    Quote Originally Posted by tapioca View Post
    does 10 hittests a frame really lag that much? i think most games do a lot more than that.
    The fewer the better, you haven't seen how much else I have going on per frame!
    Also imagine this is going in a browser, with other flash things all around it like adverts etc, thats a lot for the browser to do. So i'm trying to cut down everything I can so that it will run smoothly.
    ----------------------
    Flasher Games

  6. #6
    well, the two optimizy type things that i would probably do is put all of the grey boxes into their own mc, then hittest that to see if any of them were hit and if one is, hittest all the little boxes individually to see which one specifically was hit. and put the hittest on onmousemove instead of enterframe. i dun rmmbr how to do mousey type stuff so this code probably doesn't work but you can fix it.

    Code:
    // put all boxes in an mc called boxContainer
    // box instances are in an array called boxArray
    
    onMouseMove() {
      if (boxContainer.hitTest(mouse_x, mouse_y, true) {
        for (i = 0; i < 10; i++) {
          if (boxArray[i].hitTest(mouse_x, mouse_y, false) {
            // do your hit thingy here
            break;
          }
        }
      }
    }
    i heard putting all your hittests in one mc is faster but i've never actually tested it, so idk, try it for me maybe.

  7. #7
    Doesn't seem to make much sense for me. Obviously, I may be blatantly wrong. It's just a thought...
    Bruno Palermo
    When everything is catastrophic, thank the Gods things aren't worse!

  8. #8
    Doesn't seem to make much sense for me. Obviously, I may be blatantly wrong. It's just a thought...
    Last edited by bpalermo; May 31st, 2008 at 11:16 AM.
    Bruno Palermo
    When everything is catastrophic, thank the Gods things aren't worse!

  9. #9
    i dont think that one mc is the way to go because ive found that unless you call the items individuakllyt anyway it just hit tests everything from the most extreme boundy to the other of those items. one idea would be to write a class i personally am not sure how to do that but i heard its faster and more effiecient way of going at thnigs.

  10. #10
    cooldude: the last argument in hitTest is a shape flag that tells it to test on outside bounds if it's false or actual shape if it's true.

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  

Home About kirupa.com Meet the Moderators Advertise

 Link to Us

 Credits

Copyright 1999 - 2012