A Flash Developer Resource Site

Results 1 to 3 of 3

Thread: [HELP] No collision when cursor not moving

  1. #1
    Junior Member
    Join Date
    May 2009
    Posts
    8

    [HELP] No collision when cursor not moving

    So I'm making a simple maze game. I tried AS2 and as you can see in my older thread that it failed.

    With AS3 I managed to resolve the problem I said in the thread, but now I face a new problem.

    If you open this .swf there's an explanation, but I'll do one here too:
    http://www.mediafire.com/?w71ctp8ejwi3h5b

    If you hit the wall, it will register a collision as it should. Goes the same for the exit. But if you look to the upper left, there's a rotating rectangle. If you hit the rotating rectangle, it will register a collision IF YOUR CURSOR MOVED.

    That's right, if you freeze the cursor in place as the rectangle comes sweeping in, it WILL NOT register a collision, meaning if it were a maze game, people could cheat by just staying still.

    THANKS IN ADVANCE. HELP WILL BE GREATLY APPRECIATED.

    I forgot, here's the code:
    Code:
    stop();
    
    stage.addEventListener(MouseEvent.MOUSE_MOVE, detectHits);
    
    function detectHits(event:MouseEvent) {
    
    if (wall.hitTestPoint(mouseX,mouseY,true)) {
    gotoAndPlay("440","Menu");
    stage.removeEventListener(MouseEvent.MOUSE_MOVE, detectHits);
    }
    
    else if (gate.hitTestPoint(mouseX,mouseY,true)) {
    gotoAndStop("2","Main");
    stage.removeEventListener(MouseEvent.MOUSE_MOVE, detectHits);
    }
    
    else if (sqr1.hitTestPoint(mouseX,mouseY,true)) {
    gotoAndPlay("440","Menu");
    stage.removeEventListener(MouseEvent.MOUSE_MOVE, detectHits);
    }
    Last edited by thebangzats; 03-28-2011 at 12:08 PM.

  2. #2
    AS2 intolerant person
    Join Date
    Jan 2009
    Location
    Swansea
    Posts
    352
    well clearly the function that decides whether it is a collision depends on change on mouse position, the mouse move event.

    do what you did for the mouse with the rotating object, but aswell as the mouse moving into the object, make a check to see if theobject has moved into the mouse.

    alternatively you could use the enter frame event to determine with each frame if the mouse is within the boundaries of an object. this should work universally with all objects (moving or static).

    flos

  3. #3
    Junior Member
    Join Date
    May 2009
    Posts
    8
    I don't follow, could you give me a snippet of code I can learn from? Btw, here's the code I have so far
    Code:
    stop();
    
    stage.addEventListener(MouseEvent.MOUSE_MOVE, detectHits);
    
    function detectHits(event:MouseEvent) {
    
    if (wall.hitTestPoint(mouseX,mouseY,true)) {
    gotoAndPlay("440","Menu");
    stage.removeEventListener(MouseEvent.MOUSE_MOVE, detectHits);
    }
    
    else if (gate.hitTestPoint(mouseX,mouseY,true)) {
    gotoAndStop("2","Main");
    stage.removeEventListener(MouseEvent.MOUSE_MOVE, detectHits);
    }
    
    else if (sqr1.hitTestPoint(mouseX,mouseY,true)) {
    gotoAndPlay("440","Menu");
    stage.removeEventListener(MouseEvent.MOUSE_MOVE, detectHits);
    }
    Errr... yeah I think I fixed it. I hadn't noticed that all this time I wrote MOUSE_MOVE instead of MOUSE_OVER
    Last edited by thebangzats; 03-28-2011 at 12:21 PM.

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