A Flash Developer Resource Site

Results 1 to 20 of 25

Thread: [Flash8] shape based collision detection

Threaded View

  1. #1
    Yes we can tomsamson's Avatar
    Join Date
    Sep 2001
    Location
    Team Titan Secret Lair
    Posts
    4,666

    [Flash8] shape based collision detection

    I had to do shape based collision detection like Grant Skinner describes here:
    http://www.gskinner.com/blog/archive...8_shape_b.html

    Try swf here:
    http://img109.imageshack.us/my.php?image=test36cs.swf

    My code here, mc with linkage name backmc is the background, mc back2 is the moving one and there is mc mouse inside back2 which will be dragged:

    Code:
    import flash.display.BitmapData;
    import flash.geom.ColorTransform;
    import flash.geom.Matrix;
    import flash.geom.Rectangle;
    this.attachMovie ("backmc", "backmc", 1);
    this.attachMovie ("back2", "backmc2", 2);
    backmc2.mouse.startDrag (true);
    this.onEnterFrame = function () {
    	var myMatrix:Matrix = new Matrix ();
    	var myCT:ColorTransform = new ColorTransform (0, 0, 0, 1, 0, 255, 255, 0);
    	var myBmp:BitmapData = new BitmapData (400, 250, false);
    	myBmp.draw (backmc, myMatrix, myCT, "normal");
    	myCT = new ColorTransform (0, 0, 0, 1, 255, 255, 255, 0);
    	myBmp.draw (backmc2, myMatrix, myCT, "difference");
    	var cB:Rectangle = myBmp.getColorBoundsRect (0x00FFFFFF, 0x00FF0000, true);
    	var collision:Boolean = true;
    	if (cB.width == 0 and cB.height == 0) {
    		collision = false;
    	}
    	_root.collision=collision;
    };
    /*originally posted by tonypa,moved to its own thread by tomsamson*/
    Last edited by tomsamson; 09-15-2005 at 05:17 AM.

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