HitTest question
- rednekSVK
-
rednekSVK
- Member since: Apr. 20, 2007
- Offline.
-
- Forum Stats
- Member
- Level 17
- Blank Slate
I have a Movie clip in a Movie Clip, and I want to HitTest it with another MovieClip inside MovieClip...
It looks like this:
if (_root.screen.Terrain.hitTest(_root.Player.Dot1._x, _root.Player.Dot1._y, true)) {
trace ("blahblah");
}
It doesn't work, why?
- Denvish
-
Denvish
- Member since: Apr. 25, 2003
- Offline.
-
- Send Private Message
- Browse All Posts (15,977)
- Block
-
- Forum Stats
- Member
- Level 46
- Blank Slate
Guessing either your instance names are wrong, or using 'screen' as an instance name causes conflicts with the 'screen' Object or the 'Screen' component mentioned in the AS2 reference help
- rednekSVK
-
rednekSVK
- Member since: Apr. 20, 2007
- Offline.
-
- Forum Stats
- Member
- Level 17
- Blank Slate
At 2/21/09 09:08 AM, Denvish wrote: Guessing either your instance names are wrong, or using 'screen' as an instance name causes conflicts with the 'screen' Object or the 'Screen' component mentioned in the AS2 reference help
Nope, instance names are right, double-checked
The "screen" thing is ok, it has to be "Screen" to cause conflicts (case-sensitive)
Maybe I should ment that this code is placed in movie clip named "Player", and works under onClipEvent (enterFrame) {
Thank you for reply anyway!
- adam2510
-
adam2510
- Member since: Oct. 2, 2005
- Offline.
-
- Forum Stats
- Member
- Level 13
- Blank Slate
if (_root.screen.Terrain.hitTest(_root.Player.Dot1)) {
trace ("blahblah");
}
try just that
- rednekSVK
-
rednekSVK
- Member since: Apr. 20, 2007
- Offline.
-
- Forum Stats
- Member
- Level 17
- Blank Slate
At 2/21/09 09:20 AM, adam2510 wrote: if (_root.screen.Terrain.hitTest(_root.Play er.Dot1)) {
trace ("blahblah");
}
try just that
It works, but I cant use it, I have to know exact X and Y points
At least I know there is no mistake in Instance names
- adam2510
-
adam2510
- Member since: Oct. 2, 2005
- Offline.
-
- Forum Stats
- Member
- Level 13
- Blank Slate
if (_root.screen.Terrain.hitTest(_root.Play er.Dot1._x) && _root.screen.Terrain.hitTest(_root.Playe r.Dot1._y)) {
trace ("blahblah");
}
what about that?
- rednekSVK
-
rednekSVK
- Member since: Apr. 20, 2007
- Offline.
-
- Forum Stats
- Member
- Level 17
- Blank Slate
- Yambanshee
-
Yambanshee
- Member since: Oct. 5, 2008
- Offline.
-
- Forum Stats
- Member
- Level 11
- Blank Slate
At 2/21/09 09:34 AM, adam2510 wrote: if (_root.screen.Terrain.hitTest(_root.Play er.Dot1._x) && _root.screen.Terrain.hitTest(_root.Playe r.Dot1._y)) {
trace ("blahblah");
}
what about that?
its not going to work, you need the shapeFlag boolean
try something like this:
if (_root.screen.Terrain.hitTest(this.Dot1._x, this..Dot1._y, true)) {
:trace ("blahblah");
:} - Yambanshee
-
Yambanshee
- Member since: Oct. 5, 2008
- Offline.
-
- Forum Stats
- Member
- Level 11
- Blank Slate
sorry for double post, but i know what your problem is. You need to use the function localToGlobal. try this:
var p1:Object = {x:Player.Dot1._x, y:Player.Dot1._y};
Player.localToGlobal(p1);
var Ter:Object = {x:_root.screen.Terrain._x, y:_root.screen.Terrain._y}
screen.localToGlobal(ter)
if (Ter.hitTest(p1.x, p1.y, true)) {
trace ("blahblah");
} - rednekSVK
-
rednekSVK
- Member since: Apr. 20, 2007
- Offline.
-
- Forum Stats
- Member
- Level 17
- Blank Slate
At 2/21/09 09:54 AM, Yambanshee wrote: sorry for double post, but i know what your problem is. You need to use the function localToGlobal. try this:
var p1:Object = {x:Player.Dot1._x, y:Player.Dot1._y};
Player.localToGlobal(p1);
var Ter:Object = {x:_root.screen.Terrain._x, y:_root.screen.Terrain._y}
screen.localToGlobal(ter)
if (Ter.hitTest(p1.x, p1.y, true)) {
trace ("blahblah");
}
Doesn't work :C
I fixed some syntax errors you had in there (ter and Ter, _root.Player...), and it still doesn't work :C
Another fact is, I quite don't understand how is it supposed to work
Try it for yourself if you don't believe me
Thanks for trying though
- Yambanshee
-
Yambanshee
- Member since: Oct. 5, 2008
- Offline.
-
- Forum Stats
- Member
- Level 11
- Blank Slate
At 2/21/09 10:01 AM, rednekSVK wrote:At 2/21/09 09:54 AM, Yambanshee wrote: sorry for double post, but i know what your problem is. You need to use the function localToGlobal. try this:Doesn't work :C
var p1:Object = {x:Player.Dot1._x, y:Player.Dot1._y};
Player.localToGlobal(p1);
var Ter:Object = {x:_root.screen.Terrain._x, y:_root.screen.Terrain._y}
screen.localToGlobal(ter)
if (Ter.hitTest(p1.x, p1.y, true)) {
trace ("blahblah");
}
I fixed some syntax errors you had in there (ter and Ter, _root.Player...), and it still doesn't work :C
Another fact is, I quite don't understand how is it supposed to work
Try it for yourself if you don't believe me
Thanks for trying though
I think my code's bigest problem is making the var Ter. I know how to make a single point, not a whole Mc. try taking away the ter var, and just lay the hitTest on screen.Terrain. Also, apologys for very bad code, i just quickly threw it together on the forum, didint cheak it for syntaxs.
if you want more detail on how it works, type in localToGlobal, and view help on it.
.
- rednekSVK
-
rednekSVK
- Member since: Apr. 20, 2007
- Offline.
-
- Forum Stats
- Member
- Level 17
- Blank Slate
Like this:
var p1:Object = {x:_root.Player.Dot1._x, y:_root.Player.Dot1._y};
Player.localToGlobal(p1);
if (_root.screen.Terrain.hitTest(p1.x, p1.y, true)) {
trace ("blahblah");
}
?
If so, it doesn't work either :C
Don't apology please, I am thankful for any help
- Yambanshee
-
Yambanshee
- Member since: Oct. 5, 2008
- Offline.
-
- Forum Stats
- Member
- Level 11
- Blank Slate
At 2/21/09 10:13 AM, rednekSVK wrote: Like this:
var p1:Object = {x:_root.Player.Dot1._x, y:_root.Player.Dot1._y};
Player.localToGlobal(p1);
if (_root.screen.Terrain.hitTest(p1.x, p1.y, true)) {
trace ("blahblah");
}
?
If so, it doesn't work either :C
Don't apology please, I am thankful for any help
Yea, that's the code. Its oddly not working for me either though :/. Ill keep on trying thoug
- rednekSVK
-
rednekSVK
- Member since: Apr. 20, 2007
- Offline.
-
- Forum Stats
- Member
- Level 17
- Blank Slate
- Yambanshee
-
Yambanshee
- Member since: Oct. 5, 2008
- Offline.
-
- Forum Stats
- Member
- Level 11
- Blank Slate
realised something wrong with my code. I did the localToGlobal wrong :s
heres the new code
var p1:Object = {x:Player.Dot1._x, y:Player.Dot1._y};
Player.localToGlobal(p1);
if (screen.terrain.hitTest(p1.x, p1.y, true)) {
trace("blahblah");
}
still doesn't work for me though, but it might work for you, as a normal hitTest aint working for me either, and that is the EXACT code i used for another one of my *working* games. here's its code (a bit of it atlest)
var p:Object = {x:car_mc.pc1._x, y:car_mc.pc1._y};
car_mc.localToGlobal(p);
if (track_mc.lines.hitTest(p.x, p.y, true)) {
speed = -speed;
} - rednekSVK
-
rednekSVK
- Member since: Apr. 20, 2007
- Offline.
-
- Forum Stats
- Member
- Level 17
- Blank Slate
Still doesn't work :C
Anyway, I quite don't understand, what's the difference between code you posted now and code you posted before?
And shouldn't it be:
var p1:Object = {x:_root.Player.Dot1._x, y:_root.Player.Dot1._y};
?
- Yambanshee
-
Yambanshee
- Member since: Oct. 5, 2008
- Offline.
-
- Forum Stats
- Member
- Level 11
- Blank Slate
no, this code is supose to be on the main Timeline.
Just copy the following in the main timeline, and if it works, i'll explain how it works
onEnterFrame = function(){
var p1:Object = {x:Player.Dot1._x, y:Player.Dot1._y};
Player.localToGlobal(p1);
if (screen.terrain.hitTest(p1.x, p1.y, true)) {
trace("blahblah");
}
}
As for the diffrence, i copyed the code wrong, so i thought there was a diff
- rednekSVK
-
rednekSVK
- Member since: Apr. 20, 2007
- Offline.
-
- Forum Stats
- Member
- Level 17
- Blank Slate
- Yambanshee
-
Yambanshee
- Member since: Oct. 5, 2008
- Offline.
-
- Forum Stats
- Member
- Level 11
- Blank Slate
are all the instance names correct ( I accidentally said terrain instead of Terrain)
- rednekSVK
-
rednekSVK
- Member since: Apr. 20, 2007
- Offline.
-
- Forum Stats
- Member
- Level 17
- Blank Slate
At 2/21/09 01:39 PM, Yambanshee wrote: are all the instance names correct ( I accidentally said terrain instead of Terrain)
LOL it was it, it's fully working now
Thank you, you're the best!
Would you mind to explain how it works by the way? I don't want to be just a copy'n'paster...
- Yambanshee
-
Yambanshee
- Member since: Oct. 5, 2008
- Offline.
-
- Forum Stats
- Member
- Level 11
- Blank Slate
At 2/21/09 02:35 PM, rednekSVK wrote:At 2/21/09 01:39 PM, Yambanshee wrote: are all the instance names correct ( I accidentally said terrain instead of Terrain)LOL it was it, it's fully working now
Thank you, you're the best!
Would you mind to explain how it works by the way? I don't want to be just a copy'n'paster...
glad :P. sorry it was getting l8 and i gt school 2day, so i had to go 2 bed.
onEnterFrame = function(){//this is like saying onClipEvent(enterFrame) but for frames
var p1:Object = {x:Player.Dot1._x, y:Player.Dot1._y};//creats a new point and goes to the x and y of Player.Dot1
Player.localToGlobal(p1);//Player's coordinates are changed to match the stage's, but only when using the poing p1 (the var we made)
if (screen.terrain.hitTest(p1.x, p1.y, true)) {//your hitTest. Note how we use x instead of _x. this is becaues _x is still in the Player's coordinates where as x is on the stage
trace("blahblah");
}
}; 


