Be a Supporter!

globalToLocal(); syntax?

  • 378 Views
  • 13 Replies
New Topic Respond to this Topic
4urentertainment
4urentertainment
  • Member since: Aug. 1, 2008
  • Offline.
Forum Stats
Moderator
Level 13
Game Developer
globalToLocal(); syntax? 2009-02-10 06:44:49 Reply

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.
Forum Stats
Member
Level 08
Blank Slate
Response to globalToLocal(); syntax? 2009-02-10 06:53:34 Reply

Yeah uh note how 'myPoint' has properties x,y, not _x,_y.
The conversion is not necessary there because hittests use global coordinates.


BBS Signature
4urentertainment
4urentertainment
  • Member since: Aug. 1, 2008
  • Offline.
Forum Stats
Moderator
Level 13
Game Developer
Response to globalToLocal(); syntax? 2009-02-10 07:06:17 Reply

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.
Forum Stats
Member
Level 46
Blank Slate
Response to globalToLocal(); syntax? 2009-02-10 07:23:23 Reply

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


- - Flash - Music - Images - -

BBS Signature
Yambanshee
Yambanshee
  • Member since: Oct. 5, 2008
  • Offline.
Forum Stats
Member
Level 11
Blank Slate
Response to globalToLocal(); syntax? 2009-02-10 07:26:11 Reply

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");}
}

AS2||AS3||Motox
Thanks to hdxmike for the sig :]

BBS Signature
4urentertainment
4urentertainment
  • Member since: Aug. 1, 2008
  • Offline.
Forum Stats
Moderator
Level 13
Game Developer
Response to globalToLocal(); syntax? 2009-02-10 07:37:45 Reply

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.
Forum Stats
Member
Level 46
Blank Slate
Response to globalToLocal(); syntax? 2009-02-10 08:40:28 Reply

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


- - Flash - Music - Images - -

BBS Signature
4urentertainment
4urentertainment
  • Member since: Aug. 1, 2008
  • Offline.
Forum Stats
Moderator
Level 13
Game Developer
Response to globalToLocal(); syntax? 2009-02-10 08:50:31 Reply

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
Response to globalToLocal(); syntax? 2009-02-10 10:50:43 Reply

So no one knows the syntax for using globalToLocal?

GustTheASGuy
GustTheASGuy
  • Member since: Nov. 2, 2005
  • Offline.
Forum Stats
Member
Level 08
Blank Slate
Response to globalToLocal(); syntax? 2009-02-10 11:48:24 Reply

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.


BBS Signature
4urentertainment
4urentertainment
  • Member since: Aug. 1, 2008
  • Offline.
Forum Stats
Moderator
Level 13
Game Developer
Response to globalToLocal(); syntax? 2009-02-10 12:03:53 Reply

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.
Forum Stats
Member
Level 08
Blank Slate
Response to globalToLocal(); syntax? 2009-02-10 12:20:29 Reply

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.


BBS Signature
Denvish
Denvish
  • Member since: Apr. 25, 2003
  • Offline.
Forum Stats
Member
Level 46
Blank Slate
Response to globalToLocal(); syntax? 2009-02-10 12:27:50 Reply

lol PMT much Gust?


- - Flash - Music - Images - -

BBS Signature
4urentertainment
4urentertainment
  • Member since: Aug. 1, 2008
  • Offline.
Forum Stats
Moderator
Level 13
Game Developer
Response to globalToLocal(); syntax? 2009-02-10 16:50:47 Reply

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?