alright I hope i can help a little bit with this. I dont have all the answers for every question but I believe I should be able to get you going in the right direction with your balls falling correctly.
I'm not sure what version of actionscript your using but this will be AS3
First off you need to create movie clips of your balls
Starting on frame to you want to give them an animation of the ball breaking
then give them linkage for actionscript so under class name for my example you'd give them the name RedBall and BlueBall
then establish them as variables on the top
Code:
var rBall:RedBall;
var bBall:BlueBall;
Ok so here are some function that will create the balls and give them their properties.
Code:
function createR() {
for (var i=0; i<(Math.random()*2); i++) { //generates a random amount of red balls
rBall = new RedBall();
rBall.x = Math.random()*850; //applies a random position for each ball horizontally
rBall.y = Math.random()*340; //applies a random position for each ball vertically
rBall.speed = Math.floor(Math.random() * 5+1); //makes a dynamic speed property so how fast they move
rBall.addEventListener(Event.ENTER_FRAME, updateBall); //adds the eventlistener that will make them move
rBall.cacheAsBitmap = true; //saves some memory
addChild(rBall); //adds each ball to the stage
}
}
function createB() {
for (var i=0; i<(Math.random()*2); i++) {
bBall = new BlueBall();
bBall.x = Math.random()*850;
bBall.y = Math.random()*340;
bBall.speed = Math.floor(Math.random() * 5+1);
bBall.addEventListener(Event.ENTER_FRAME, updateBall);
bBall.cacheAsBitmap = true;
addChild(bBall);
}
}
Now that you have balls on the stage you need the function updateBall which is an Enter Frame event to make them move
Code:
function updateBall(e:Event) {
var cBall:MovieClip = e.currentTarget as MovieClip; //creates a variable for every fish so you can reference them as one
cBall.y +=cBall.speed; //this takes the speed from the dynamic property we added in the ball functions and everyframe adds it to the y position
if (cBall.y > 600) {
cBall.goToAndPlay(2); //tells the movieclip to play its break animation
cBall.removeEventListener(Event.ENTER_FRAME, updateBall); //removes the enterframe so the ball will stop moving
}
}
there might be one or two errors in this as i'm writing it on the fly but it should get you moving in the right direction
as for the hitTestObject the problem it checks if it hit your objects bounding box "the movie clip" and not the actual ball inside. So really it could hit the corner of the movie clip box and still think its hitting the ball since a ball doesn't fit perfectly inside the box. theres always space.
I believe what you'll need to do is use bitmap data for your objects and hit test against that specially since you want to check certain areas of your cup like the rim compared to the middle. I'm not to familiar with the whole topic but i'm sure there are people on here that will be able to help you out. But look up some information regarding hit testing on bitmapdata and you should be in the right direction
hope the helps, best of luck
Bookmarks