I was reading through a tute on collission detection and I found what I think Im looking for. ( detecting collission when an object is in a "drag' status)
but I dont understand it....its slash syntax...I'm a newbie to dot sytax!! I'm not certain what all these become in MX 2004. could anyone translate for me?
this is a quote from the tute:
Code:
7. Now in the first frame of your ENEMY movie, enter the following code:
flag = this.hitTest("/ship"); if (flag == true) { tellTarget ("/") { gotoAndStop
("hit"); } } You do this by selecting setVariable from the Actions menu. Then in the Variable section, enter: flag
and in the in the Value section, enter: this.hitTest("/ship")
8. Then after that line of code, enter the following:
if (flag == true) { tellTarget ("/ship") { gotoAndStop (2); } } This is the code that will tell your ship movie to explode upon collision.
9. That's really all there is to it! Have fun!
This is what I was working with before I went searching. I have this on my drag object
Cool! it worked! now I want to ask, what is it? could you break it down for me? And maybe what some common application of this are? I feel as if this will be an important function.
Well, this is basically a drag and drop routine if you need to check something while dragging.
To break it down:
code:
on(press){
startDrag(this);
//This creates a function watch for onMouseMove events. That means whenever the
//mouse is moved, whatever is inside of this function will occur.
this.onMouseMove = function(){
//For now, it is your hittest, however, you add as much code as you like in this statement.
if(_root.pin.hitTest(_root.balloon)){
_root.balloon.balloon2.gotoAndPlay("popped");
}
}
}
on(release){
stopDrag();
//Setting this.onMouseMove to undefined is erasing whatever checks were set up in
//onPress statement.
this.onMouseMove = undefined
}
I've used something like this for mouse based games before.
Ok, I think I understand that now. But I have one more question. Now I am trying to make a pin pop many balloons. my popped balloons have an animation for when they are popped. I found with this script I could pop a balloon, but if i kept moving the mouse, it would restart the animation. I corrected that by adding a
delete this.onMouseMove;
it worked for one MC.
now I have 4 balloons, when I pooped one, it would delete the onMouseMove so I could not pop any more.
I figured I would add the this.onMouseMove = function(); to the top of each if statement to see if it would work. now it will only pop the last balloon in my if statement.
I'm out of ideas......
here is what I have. (probably no very good)
However, to make things easier, this is where you would use For loops and concatenation.
First, rename your balloon movie clips to:
balloon_0
balloon_1
balloon_2
balloon_3
Next you would set up a for loop and use concatenation to check each
of the balloons.
Concatenation is the operation of joining two character strings end to end or a string and variable.
In otherwords if you have this:
code:
var i = 0
_root["balloon_"+i]
is exactly like saying this:
code:
_root.balloon_0
You follow me so far?
Okay..here's the example:
code:
//...SNIP...
this.onMouseMove = function(){
//FOR LOOP CODE IS LIKE THIS
//for (starting number;repeat this until this condition is no longer true;how
//the number will increase. ++ in Flash means it will increase by 1 for //each time through the loop.
for (var i = 0;i <= 3;i++){
if(_root.pin.hitTest(_root["balloon_"+i])){
_root["balloon_"+i].gotoAndPlay("popped");
}
sorry to take so long to get back to this thread. Thank you for the mini tute on for loops, I have read up on them before, but this has been the easiest to understand. I will definately make a n effort to get to know it better.
i have another question about the onMouseMove function. I did what you said and put in a For loop with the If statement. But the problem stil remains where due to the onMouseMove, it triggers my drag objects animation every time the mouse is moved on the hitTest target making a very un-clean animation. Im trying to have the animation play only once per object... I have the fla. attached, the code is all over the place (I'm a newbie so I do what I can, so if anyone has some code clean up suggestions, feel free.) there is some code on the frame labeled "splat" that I tried to write on the first frame with an onEnterFrame event handler, but it didn't work. so I put the code on the objects (the frame is about 3 levels deep if you go looking for it) and the little red box is just a timer to end the sequence (its part of a bigger quiz game) the box is usually not visible, but I did this so it could be found.
Anyways, i know its a total mess, but its really the best i can do....
Thanks for all the help
....wow, just uploaded the Fla, dont know why its so big. it was only 16k when it was a frame of my quiz game..strange
OK, that worked great! Thank you
I'm wondering if I could run by what I understand this script to be saying and could you tell me if im right or not. I'm still new to this so Im interested to know.
onClipEvent (load) {
for (var i = 0; i<=5; i++) {
_root["fly_"+i].splat = false;
}
setting a all the flys booleen to false.
for (var i = 0; i<=5; i++) {
if (_root.fly_swatter.mesh.hitTest(_root["fly_"+i]) && _root["fly_"+i].splat == false) {
_root.fly_swatter.gotoAndPlay("swat");
_root["fly_"+i].splat = true;
_root["fly_"+i].fly2.gotoAndStop("splat");
we are now watching the flys and waiting to the IF condition to be met. The condition is IF the swatter is on a fly AND if the fly's booleen is false (meaning it hasn't been squashed) then swat the fly, change its booleen to true so that it can no longer trigger the animation and stop the playhead on the sqwashed fly anim.
Thanks so much. I think I learnt something new here.