flash, shaped mc's
- Started
- Last post
- 10 Responses
- wwfc
Afternoon!
I could do with a bit help if anyone can - I have a .fla that has an mc(cursor) that follow the users mouse/cursor around and also two other movieclips called obstacle1 & obstacle2.
The cursor mc follows the exact mouse position until it comes into contact with either obstacle mc - at which point it stays at the bounding box perimeter. It also slides a little when the mouse moves around inside the obstacle mc.
My question is how do I get the cursor mc to react to the actual 'shape' of the obstacle movieclips and not just there bounding box area?? I can't it sussed! The script that controls it is in a .as file and I have popped it up here: http://pastebin.com/m39513cd2
there is also a snippet of code on the timeline too:
var cursor:MovieClip = _level0.attachMovie("cursor", "cursor1", 0);var manager:CursorManager = new CursorManager(cursor);
manager.addObstacle(mcShape1);
manager.addObstacle(mcShape2);
function onEnterFrame():Void
{
manager.updateCursorPosition();
}I don't know what I need to change in the code to make the cursor mc recognise the true shape of the movieclip? or should I be adding script relevant to the obstacles to make them shaped?
Hope someone is in the mood to put me out of misery!
thanks in anticipation
- kult0
Flash will only ever natively recognize the RECT bounding area of a movieclip. You might have to look into some custom per-pixel collision detection.
- wwfc0
...I thought flash could recognise both bounding box and the actual shape - I think I remember back in the day if you used the shapeFlag command it recognised the shape as opposed to the entire area.
Wouldn't per pixel method be a little heavy on the speed of things?
thanks for the reply btw ;-)
- kult0
I could be misinforming you, but as far as I know you'll need to utilize the bitmap data (rasterizing a mask perhaps) to check for collisions.
- ElectroLAX30000
Cache the mc as bitmapData and then per pixel collision is how Adobe recommends so do it that way... or else.
- Fariska0
Had the same problem. I solved using this method
http://www.kirupa.com/forum/show…
(8th post, from senocular).
Did a slightly different function but the principle is perfectly working.
- wwfc0
...it does work indeed - nice link Fariska - but I dunno how I add the bits that make it work to my current scripting?
anyone hold my hand?
- Fariska0
I did a function of that, i have that at home, i'll mail you later, if you're not in a rush.
- wwfc0
...cheers Fariska - that would be great if you could email it to me - spent a large part of the weekend and today trying to suss it - so I am more than happy to wait a bit longer if it's gonna work ;-)
- wwfc0
...still trying to get this sorted cheers for the pointers Fariska much appreciated but it just wouldn't work - thanks for taking the time to have a look.
I have got it part working - the cursor mc now follows the mouse over the bounding box of the obstacle clip and recognises the actual shape of said clip. But the problem is that when hittest happens between the clip shape and the cursor mc - the cursor jumps back to the clips bounding box!!!!!! I have been plugging away at this but I just can't work out how to make the cursor mc follow the obstacles shape as opposed to the bounding box - I have tried a variety of combinations but am b*ggered if I can suss it!
Any flash heads on here that can see where the problem lies?
...please?here is the entire script:
http://pastebin.com/d2a84ca0bI don't know if I should be looking at line 27 or 34 onwards?
This kind of thing make sense to anyone?How do I make the cursor mc follow it's way around the obstacle mc's shape and not the bounding box????
nnnrggh!
- vaene0
Came upon this discussion late and am working on a similar project any chance you could repost at pastebin?