globalToLocal(); syntax?
- 4urentertainment
-
4urentertainment
- Member since: Aug. 1, 2008
- Offline.
-
- Forum Stats
- Moderator
- Level 13
- Game Developer
I'm using AS2 and this is my code:
onClipEvent (load) {
var myPoint:Object = {x:_root.wall._x, y:_root.wall._y};
this.globalToLocal(myPoint);
}
onClipEvent (enterFrame) {
if(this.hitTest(myPoint._x,myPoint._y,true)){trace("lolz");}
}
but nothing happens.
So I have a wall on the main timeline, and a movieclip in 3 movieclips. I want to test if they are shapeFlag hitTesting. How do I do that?
- GustTheASGuy
-
GustTheASGuy
- Member since: Nov. 2, 2005
- Offline.
-
- Send Private Message
- Browse All Posts (12,016)
- Block
-
- Forum Stats
- Member
- Level 08
- Blank Slate
Yeah uh note how 'myPoint' has properties x,y, not _x,_y.
The conversion is not necessary there because hittests use global coordinates.
- 4urentertainment
-
4urentertainment
- Member since: Aug. 1, 2008
- Offline.
-
- Forum Stats
- Moderator
- Level 13
- Game Developer
But when I just say:
if(_root.walls.hitTest(this._x,this._y,true)){trace("lolz");}
It never does anything. However when I say:
if(_root.walls.hitTest(this)){trace("lolz");}
It always works since they are four walls in the movieclip wall surrounding the player. So what I want is to change the _root walls to local coordinates or what I'm trying to hitTest to convert it to global coordinates. How?
- Denvish
-
Denvish
- Member since: Apr. 25, 2003
- Offline.
-
- Send Private Message
- Browse All Posts (15,977)
- Block
-
- Forum Stats
- Member
- Level 46
- Blank Slate
The shapeflag hitTest seems to work fine to me, although it won't register until the MC is buried in the wall.
Adapted version here
- Yambanshee
-
Yambanshee
- Member since: Oct. 5, 2008
- Offline.
-
- Forum Stats
- Member
- Level 11
- Blank Slate
try this:
onClipEvent (load) {
var myPoint:Object = {x:_root.wall._x, y:_root.wall._y};
this.globalToLocal(myPoint);
}
onClipEvent (enterFrame) {
if(this.hitTest(myPoint.x,myPoint.y,true)){trace("lolz");}
} - 4urentertainment
-
4urentertainment
- Member since: Aug. 1, 2008
- Offline.
-
- Forum Stats
- Moderator
- Level 13
- Game Developer
Still doesn't work.
I'm pretty sure I'm doing something very wrong... But what?
I mean if I have a movieclip inside another movieclip. player2 is inside player1.
player1's x is 200
player2's x is 0
Now I want to convert that 0, to the _root coordinates where it will be 200 as well...
Denvish, the fla you sent, if I am not mistaken, the hitTest was on the player and the walls which were on the main timeline. What if the player was in another MC. How do I shapeFlag hitTest then???
- Denvish
-
Denvish
- Member since: Apr. 25, 2003
- Offline.
-
- Send Private Message
- Browse All Posts (15,977)
- Block
-
- Forum Stats
- Member
- Level 46
- Blank Slate
At 2/10/09 07:37 AM, 4urentertainment wrote: What if the player was in another MC. How do I shapeFlag hitTest then???
Change all the _x and _y values in the enterframe code to _parent._x and _parent._y
Or just put the code on the external MC, instead of the nested one
- 4urentertainment
-
4urentertainment
- Member since: Aug. 1, 2008
- Offline.
-
- Forum Stats
- Moderator
- Level 13
- Game Developer
At 2/10/09 08:40 AM, Denvish wrote:At 2/10/09 07:37 AM, 4urentertainment wrote: What if the player was in another MC. How do I shapeFlag hitTest then???Change all the _x and _y values in the enterframe code to _parent._x and _parent._y
Or just put the code on the external MC, instead of the nested one
The thing is, the external one has other things with it, and I only want on the nested one. If globalToLocal is impossible or something, I'll just have to get the nested movieclip on the main timeline.
- 4urentertainment
-
4urentertainment
- Member since: Aug. 1, 2008
- Offline.
-
- Forum Stats
- Moderator
- Level 13
- Game Developer
So no one knows the syntax for using globalToLocal?
- GustTheASGuy
-
GustTheASGuy
- Member since: Nov. 2, 2005
- Offline.
-
- Send Private Message
- Browse All Posts (12,016)
- Block
-
- Forum Stats
- Member
- Level 08
- Blank Slate
Take that Denvish! I hate you. >:c
4ursomething - learn to use, er, ..anything at all, God please?, before you whine about coordinate spaces.
onClipEvent (enterFrame)
{
var p = { x : _x, y : _y };
_parent.localToGlobal (p);
trace (_root.walls.hitTest (p.x, p.y, true));
}
I'm positive you should have the capacity to paste this without fucking it up.
- 4urentertainment
-
4urentertainment
- Member since: Aug. 1, 2008
- Offline.
-
- Forum Stats
- Moderator
- Level 13
- Game Developer
At 2/10/09 11:48 AM, GustTheASGuy wrote: Take that Denvish! I hate you. >:c
4ursomething - learn to use, er, ..anything at all, God please?, before you whine about coordinate spaces.
onClipEvent (enterFrame)
{
var p = { x : _x, y : _y };
_parent.localToGlobal (p);
trace (_root.walls.hitTest (p.x, p.y, true));
}
I'm positive you should have the capacity to paste this without fucking it up.
Great timing, I actually just figured out how to work it with this code:
onClipEvent (load) {
var p = {x:_root.player1.player2._x,y:_root.player1.player2._y}
trace(p.x);
_root.player1.player2.localToGlobal(p);
}
onClipEvent (enterFrame) {
trace(_root.player1._x);
trace(p.x);
}
Thanks anyway.
- GustTheASGuy
-
GustTheASGuy
- Member since: Nov. 2, 2005
- Offline.
-
- Send Private Message
- Browse All Posts (12,016)
- Block
-
- Forum Stats
- Member
- Level 08
- Blank Slate
Can you spare me the constant facepalming? At least pretend to be happy to understand, and don't post code showing you twisted some shit like a hapless dolt until it somewhat worked. You hapless dolt.
- Denvish
-
Denvish
- Member since: Apr. 25, 2003
- Offline.
-
- Send Private Message
- Browse All Posts (15,977)
- Block
-
- Forum Stats
- Member
- Level 46
- Blank Slate
- 4urentertainment
-
4urentertainment
- Member since: Aug. 1, 2008
- Offline.
-
- Forum Stats
- Moderator
- Level 13
- Game Developer
Well I'm not a total AS noob. I was able to code this.
Without copying a single line (except for the part where the light stops at the walls, but I didn't copy that either, understood it from a tutorial. Not too sure about the trigonometry part though.
That counts for something, right?
Controls:
Move with WASD, shoot with mouse, change weapons with Q,E, turn off light with F, run with SHIFT, open doors with space.
Right?



