PDA

View Full Version : How to check For Identical MovieClips


nikhiljoshi122
11-14-2009, 09:12 AM
hey All,
I am working on a game in which i need to compare two movieclips for being identical.
What i am doing is creating a complex shape out of some primitive shapes and then I allow the user to drag and drop some primitive shapes to recreate a similar shape.
My problem is how can I calculate that the user created shape is similar to the original complex shape or not.

I have already posted this once before but dun get any replies.
Hope to get some help this time.:confused:
nik

henke37
11-14-2009, 07:00 PM
Check for position and angle similarities.

nikhiljoshi122
11-15-2009, 03:57 AM
Thanks for replying
But my complex shape is made of primitive shapes like circle ,square etc by randomly rotating and scaling them.
Its kind of an organic shape
How could I check another movieclip with my complex shape if it is identical or not.

henke37
11-15-2009, 09:36 AM
You check each part seperatly.

nikhiljoshi122
11-16-2009, 12:00 PM
I think I am not able to clarify my doubt
Actually My complex shape is similar to underlying image
http://diodegames.com/img.jpg
now if i allow a user to draw a similar shape with pencil tool with high thickness.
How can I measure is the two shapes are similar and if not then ant way of calculating the percentage similarity between two of them.

box86rowh
11-16-2009, 12:20 PM
you could flop one on top of the other and then go through pixel by picel to see how many share the same surface area, then return them back to position

magicTuscan
11-16-2009, 12:41 PM
I think I am not able to clarify my doubt
Actually My complex shape is similar to underlying image
http://diodegames.com/img.jpg
now if i allow a user to draw a similar shape with pencil tool with high thickness.
How can I measure is the two shapes are similar and if not then ant way of calculating the percentage similarity between two of them.

Easy:
Just store for every individual obj (movieClip) properties into an object array.
For example that blob you have.


private var _objectProps : Object = [];

function addObjectProps(targetObject:MovieClip) : void {
var userBlobProps:Object = {
"_userName": userBlobs.userName,
"_width":userBlobs.width,
"_height":userBlobs.height,
"_color":userBlobs.color,
"_rotation":userBlobs.rotation,
"_scaleX":userBlobs.scaleX,
"_scaleY":userBlobs.scaleY
}
_objectProps.push(userBlobProps );
}


So imagine am a user and i provided my name as magicTuscan, and I have created a new blob...via below


private function newBlob() : void {
var thisBlobCreatedByUser: MovieClip = new UserBlob() as MovieClip;
//code to draw and add blob to stage here

userBlobs["userName"] = "magicTuscan";

//after all is done- now attach blob props to array & then you can compare later on!!!

addObjectProps(thisBlobCreatedByUser); // thats it
}

private function compareBlobs() : void {
// do your comparing here
}

-Ev-
11-16-2009, 02:36 PM
When you're ready to compare the two drawings, you can use the BitmapData class to compare them.

1. Use BitmapData.draw() to draw both clips into BitmapData objects with the same dimensions.
2. Use the BitmapData.compare() method, which will return a NEW BitmapData object, in which the pixel RRGGBB values are the DIFFERENCE between the compared bitmaps. If two pixels in the compared bitmaps were identical, the resulting BitmapData will have a black pixel at that (x, y) coordinate.
3. Use the BitmapData.threshold() method to check if every pixel is greater than 0x00000000. It doesn't matter what color you change the pixels to, since this is a disposable BitmapData object. The key to this step is that the method returns the number of pixels that were changed.
4. Divide the number of changed pixels by the total pixels of your bitmap objects (width x height), and that will give you the exact percentage difference between the two drawings.

nikhiljoshi122
11-17-2009, 01:44 AM
Hey Ev thanx a ton
I was was looking for a solution like this only.
great.:)
nik