|
|
|
#1 |
|
Senior Member
Join Date: May 2006
Posts: 119
|
Code translation please
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!
Code:
on(press){
startDrag(this);
if(_root.pin.hitTest(_root.balloon)){
_root.balloon.balloon2.gotoAndPlay("popped");
}
}
on(release){
stopDrag();
}
I hope thats enough explanation. Thank you in advance for any help Mark |
|
|
|
|
|
#2 |
|
Patron Saint of Beatings
Join Date: Nov 2000
Location: Ro-cha-cha-cha, New York
Posts: 1,992
|
Well, basically it's because the onPress/onRelease event only happens once.
I recommend doing something like this (NOTE: I'm assuming this code is from a button inside of a movie clip):
EDIT: Oh yeah. / = _root Last edited by WilloughbyJackson; 06-22-2006 at 01:30 PM. |
|
|
|
|
|
#3 |
|
Senior Member
Join Date: May 2006
Posts: 119
|
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.
Thank you very much Mark |
|
|
|
|
|
#4 |
|
Patron Saint of Beatings
Join Date: Nov 2000
Location: Ro-cha-cha-cha, New York
Posts: 1,992
|
Well, this is basically a drag and drop routine if you need to check something while dragging.
To break it down:
I've used something like this for mouse based games before. |
|
|
|
|
|
#5 |
|
Senior Member
Join Date: May 2006
Posts: 119
|
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) Code:
on(press){
Mouse.hide();
startDrag(this, true);
this.onMouseMove = function(){
if(_root.pin.hitTest(_root.r_balloon)){
_root.r_balloon.gotoAndPlay("popped");
delete this.onMouseMove
}
}
this.onMouseMove = function(){
if(_root.pin.hitTest(_root.b_balloon)){
_root.b_balloon.gotoAndPlay("popped");
_root.b_balloon._visible = false;
delete this.onMouseMove
}
}
this.onMouseMove = function(){
if(_root.pin.hitTest(_root.g_balloon)){
_root.g_balloon.gotoAndPlay("popped");
delete this.onMouseMove
}
}
this.onMouseMove = function(){
if(_root.pin.hitTest(_root.p_balloon)){
_root.p_balloon.gotoAndPlay("popped");
delete this.onMouseMove
}
}
}
on(release){
stopDrag();
this.onMouseMove = undefined
}
|
|
|
|
|
|
#6 |
|
Patron Saint of Beatings
Join Date: Nov 2000
Location: Ro-cha-cha-cha, New York
Posts: 1,992
|
First comment: You do not have to delete the onMouseMove after each hit test, you can just have the hit tests listed in sequence.
I.E.
Or you could use an if else chain here. 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:
is exactly like saying this:
You follow me so far? Okay..here's the example:
|
|
|
|
|
|
#7 |
|
Senior Member
Join Date: May 2006
Posts: 119
|
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.
Thanks again Mark |
|
|
|
|
|
#8 |
|
Patron Saint of Beatings
Join Date: Nov 2000
Location: Ro-cha-cha-cha, New York
Posts: 1,992
|
Not a problem.
|
|
|
|
|
|
#9 |
|
Senior Member
Join Date: May 2006
Posts: 119
|
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 |
|
|
|
|
|
#10 |
|
:
Join Date: Dec 2002
Posts: 2,557
|
Maybe try something like this...
Code:
onClipEvent (load) {
for (var i = 0; i<=5; i++) {
_root["fly_"+i].splat = false;
}
}
on (press) {
Mouse.hide();
startDrag(this, true);
this.onMouseMove = function() {
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");
}
}
};
}
on (release) {
stopDrag();
this.onMouseMove = undefined;
}
|
|
|
|
|
|
#11 | ||
|
Senior Member
Join Date: May 2006
Posts: 119
|
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. Quote:
Quote:
Thanks so much. I think I learnt something new here. |
||
|
|
|
|
|
#12 |
|
:
Join Date: Dec 2002
Posts: 2,557
|
Yes, that's exactly it!
|
|
|
|
![]() |
|
||||||
| Thread Tools | Search this Thread |
| Display Modes | |
|
|