only had one error, and that was that you did not capatalize the word Test in hitTest. I know, it really shouldn't make a difference, but it's a Flash function, and everything is case sensitive. I'm glad it worked out, though, and you're welcome.
ok, i'll remember that.
i got another question, i'm making a basketball game and when the ball goes up it crosses the "sixteen" and adds a score to my scoreboard, how do i stop this?(ball="four")
oh and what does a case sensitive have to do with a ')'
"when the ball goes up it crosses the "sixteen" and adds a score to my scoreboard, how do i stop this?(ball="four")"
Isn't this the effect you wanted to create in the first place? Perhaps I'm not understanding your question correctly.
I guess to stop it, delete the code that I wrote for you
"oh and what does a case sensitive have to do with a ')'"
It has nothing to do with it ^_^. Your parentheses, that being '(' and ')', were used perfectly. I said the problem was your capatalization of the word "Test" in "hitTest". I referred to it being "case sensitive", which means that there's a difference between "t" and "T". I hope this clears things up.
Why not just make "sixteen" small enough so it's only on top of the basket, thus disallowing the ball to ever hit it while going upwards?
If the ball happens to go at an angle where it will "make contact with" the basket while going up, then you might have a little work to do. You could make a variable that makes sure it first went upwards, like so.
Basically, this checks if the ball is hitting "sixteen". If so, then it checks if the ball went up, which is the variable ballWentUp. The first time it checks, it wont be true, so it passes the scoring part and adds 1 to ballWentUp, which means it's true. The next time the ball hits the basket, ballWentUp will be true, so it will go into that second if statement, which adds the score, and also makes ballWentUp equal to -1 because it will then be incremented to 0, which will put it back in place for the next time that you shoot. NOTE: This will only work if the ball ALWAYS hits "sixteen" while going upwards.
For other matters on your game, it's suggested you post a new thread so your questions aren't hidden elsewhere, such as the end of this almost four-thousand post sticky thread. ^^
but i cant figure out how to get my character to go to the next scene when he exits off the right or left side of the screen, can anyone help? i would really appreciate it
hey, i'm a joinin this hitTest party,i got me a question that i can't seem to find the answer to anywhere else in this thread or elsewhere on the board. If you've read my other two posts pleading for help, you'll know that i'm putting together a zelda-style interface for my cv (i'm an animator by trade, just wanted to do something a little different ). I eventually got my lil guy walking properly, then i managed to make him stop at objects, however, he aint stopping at everything, he'll walk right on through somethings sometimes, and the big ol' gallery at the top, he walks through that every time. As far as my feeble brain can tell, this may be because the hitTest area is partly offscreen? would this make a difference, how can i solve it? sorry for the long message but i'm well stuck! here's the swf: gruffcv , and i'll upload the fla
god, theres too much to read for a tired mind, so ill ask and hope u havent answered already, and if u have, sorry. my problem is that i want to hittest 2 things which are in an mc. should that really be a problem, cuz i just cant get it to work. ive allready sked in the object thread, but since its now a hittest problem i ask here. if you know y it wont work, please tell me.
*edit*
I just read this and i see that i should explain it a bit better. its for my mario kart racing game (or ihoss-cart, obvioulsy), and i have a map in the corner wiht the car as an icon. when i move forward the car in the map moves forward. what i want to is to see if the car is on the road and if it isnt, slow it down. therefore i added a road shape to the map and hittest it from the car icon to see if they hit.
code:
if (_parent.shape.hitTest(this._x,this._y,true)) {
_parent._parent.maxspeed=20;
}else{
_parent._parent.maxspeed=10;
}
it is relative cuz im going to load it inot another movie, and im sure all the mc exist.
i would really apreaciate it if someome could help me.
I really appreciate looking at your source files. They have been most helpful to me. I noticed a minor problem with {simple_shooter.fla} from your download page. The counter is not working after you kill an enemy. I took the second frame out in the enemy_mc because it had a stop action on that frame. That seemed to fix the problem. I know this is minor, I just thought I would bring it to your attention.
Now, "hyrossia" is the map mc. I have the map scrolling the way I want it now....but the problem now is the collision detection is out of whack (if the map is scrolling while you hit a wall you begin to go through it). Any solutions for this?
In scrolling, the hitTest is pretty much like moving accept backwards
so you would have to create a sperate scroll function like
Ive used hittest to deplete the health of my player whenever he hits a baddie movieclip - The problem is - I want the baddie to die and the player to lose say 25 of their health all in one go.
At the moment the player keeps losing life as long as he is in contact with the baddie movieclip......get me?
The way I would like it is in the bombs away game ie: when the plane hits the surface to air missiles they explode and the plane loses some energy....
Hello people, i'm wondering if someone can help me out.
I've been using the following code to control a movieclip's movement with the keys. This being Ed Mack's code from the first page i think. However, what i'd really like to be able to do is to have the movieclip attached to the mouse and try and get the hit test to work that way. I've had a couple of attempts and have searched for relevant threads, but as yet i've had no luck on either count.
If anyone has any ideas or knows how to do this, i'd be really grateful for their advice.
Thanks again
--- code starts ---
onClipEvent(load){
s = 5;
b = this.getBounds(this);
Originally posted by triple j I've been using the following code to control a movieclip's movement with the keys. This being Ed Mack's code from the first page i think. However, what i'd really like to be able to do is to have the movieclip attached to the mouse and try and get the hit test to work that way. I've had a couple of attempts and have searched for relevant threads, but as yet i've had no luck on either count.
Do you want movie clip to move to the direction of mouse coordinates? Only when mouse is clicked? Or do you want movie clip to appear in mouse position?
Its not hard to change the code to do following:
*when mouse is clicked check which way mouse is from mc current position
*start moving in that direction
*move until hit the wall or mouse position is reached
The movieclip will be in the mouse's position, so a start drag will be fine for that or code saying the the x and y values of the movieclip equal the x and y values of the mouse, whichever would be easiest to implement into the hittest.
I tried re-working the code and included a start drag with the movieclip locked to the mouse center, but i wasn't sure how to include the move function into it. As soon as i included the start drag the hittest stopped working. The answer is probably staring me in the face, but i can't seem to find the solution just yet.
That's excellent Tony, thank you very much for your help
It's a shame you can't use drag for this as it would have been alot smoother. Would it be possible to use the constrain to rectangle option in the start drag to limit its movement on the hittest ? For example, if the right hand side of the movie clip was hitting something, i would only have start drag for up, down and left ?? I'm not sure if it could work like that.
Once again thank you so much for your time and knowledge, it's been a big help
Originally posted by triple j Would it be possible to use the constrain to rectangle option in the start drag to limit its movement on the hittest ? For example, if the right hand side of the movie clip was hitting something, i would only have start drag for up, down and left ?? I'm not sure if it could work like that.
I never tried anything like that. First, I think you can only change constrain to rectangle option when you start the drag, that would mean you have to constantly stop dragging and start again.
And you cant actually hittest dragged movie clip against where it would go.
If you want, you could still use the _xmouse/_ymouse like this:
code:
onClipEvent (load) {
b = this.getBounds(this);
function move (x, y) {
if (!_root.hit.hitTest(_root._xmouse+b.xmin+1, _root._ymouse+b.ymin+1, true)) {
if (!_root.hit.hitTest(_root._xmouse+b.xmax-1, _root._ymouse+b.ymin+1, true)) {
if (!_root.hit.hitTest(_root._xmouse+b.xmin+1, _root._ymouse+b.ymax-1, true)) {
if (!_root.hit.hitTest(_root._xmouse+b.xmax-1, _root._ymouse+b.ymax-1, true)) {
_x = _root._xmouse;
_y = _root._ymouse;
}
}
}
}
}
}
onClipEvent (mouseMove) {
move();
}