9 Replies - 1074 Views - Last Post: 16 April 2008 - 09:29 PM

#1 icedd  Icon User is offline

  • D.I.C Head
  • member icon

Reputation: 5
  • View blog
  • Posts: 98
  • Joined: 04-March 08

Hit test problem ...ish

Post icon  Posted 08 April 2008 - 02:04 PM

All I'm trying to do is this. Say I have a mc called "man", he is controlled by the arrow keys, and when he hits another mc called "border" I want the frame to jump to frame 2.
onClipEvent (enterFrame) {
		if (Key.isDown(Key.UP)) {
		this._y -=5;
			}
	
		if (Key.isDown(Key.DOWN)) {
		this._y +=5;
			}
		
		if (Key.isDown(Key.LEFT)) {
		this._x -=5;
			}
		
		if (Key.isDown(Key.RIGHT)) {
			this._x +=5;
			}
		if (hitTest(_level0.border)==true) {gotoAndStop(2);}
		
}

That code is applied directly to the "man" movie clip

Is This A Good Question/Topic? 0
  • +

Replies To: Hit test problem ...ish

#2 girasquid  Icon User is offline

  • Barbarbar
  • member icon

Reputation: 108
  • View blog
  • Posts: 1,825
  • Joined: 03-October 06

Re: Hit test problem ...ish

Posted 08 April 2008 - 03:14 PM

Okay...and what's the problem?

Try changing it to this.hitTest.
Was This Post Helpful? 0
  • +
  • -

#3 icedd  Icon User is offline

  • D.I.C Head
  • member icon

Reputation: 5
  • View blog
  • Posts: 98
  • Joined: 04-March 08

Re: Hit test problem ...ish

Posted 08 April 2008 - 03:16 PM

View Postgirasquid, on 8 Apr, 2008 - 07:14 PM, said:

Okay...and what's the problem?

Try changing it to this.hitTest.





Sorry, I got side tracked when I posted that, the problem is it dosn't work. My man just walks into the border and nothing happens. And I did try adding "this.hittext" with 0 sucess

This post has been edited by icedd: 08 April 2008 - 03:32 PM

Was This Post Helpful? 0
  • +
  • -

#4 girasquid  Icon User is offline

  • Barbarbar
  • member icon

Reputation: 108
  • View blog
  • Posts: 1,825
  • Joined: 03-October 06

Re: Hit test problem ...ish

Posted 08 April 2008 - 06:13 PM

Okay - are you sure that _level0.border is what you think it is, then? Are you sure it doesn't have a bounding box the size of the entire stage(which the "man" mc is constantly hitting), or too small a box for the mc to collide with?

Try looking at the documentation for hitTest - there's a boolean you can pass in called "shapeFlag" that will make the hitTest test for collisions based on the filled in shapes of each object, instead of their bounding boxes.
Was This Post Helpful? 0
  • +
  • -

#5 icedd  Icon User is offline

  • D.I.C Head
  • member icon

Reputation: 5
  • View blog
  • Posts: 98
  • Joined: 04-March 08

Re: Hit test problem ...ish

Posted 08 April 2008 - 06:18 PM

View Postgirasquid, on 8 Apr, 2008 - 10:13 PM, said:

Okay - are you sure that _level0.border is what you think it is, then? Are you sure it doesn't have a bounding box the size of the entire stage(which the "man" mc is constantly hitting), or too small a box for the mc to collide with?

Try looking at the documentation for hitTest - there's a boolean you can pass in called "shapeFlag" that will make the hitTest test for collisions based on the filled in shapes of each object, instead of their bounding boxes.


No I am not sure, Im not even sure if What I want will work with the hittest,, Im just kinda guessing, i was hoping someone could pint me in the right direction
Was This Post Helpful? 0
  • +
  • -

#6 girasquid  Icon User is offline

  • Barbarbar
  • member icon

Reputation: 108
  • View blog
  • Posts: 1,825
  • Joined: 03-October 06

Re: Hit test problem ...ish

Posted 09 April 2008 - 10:56 AM

In that case, try taking a look at the ActionScript reference for the hitTest function - changes are, you're not using it properly(although I don't have the reference here, and therefore can't say for sure). If you read through that documentation, it will have examples that you can adapt to whatever you need.
Was This Post Helpful? 0
  • +
  • -

#7 Ganesan_Priya  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 4
  • Joined: 15-April 08

Re: Hit test problem ...ish

Posted 15 April 2008 - 02:50 AM

Hi
You dont use enterframe concept for that.....Instead of that you can apply Key.addlistener concept you can get better solution......
The following code is working fine for me....
Please test it.....
var key_object:Object = new Object();
key_object.onkeydown = function() {
if (Key.isDown(Key.UP)) {
man_mc._y -= 5;
}
if (Key.isDown(Key.DOWN)) {
man_mc._y += 5;
}
if (Key.isDown(Key.LEFT)) {
man_mc._x -= 5;
}
if (Key.isDown(Key.RIGHT)) {
man_mc._x += 5;
}
if (hitTest(_level0.border) == true) {
gotoAndStop(2);
}
if (target_mc.hitTest(man_mc) == true) {
man_mc.gotoAndStop(2);
} else {
man_mc.gotoAndStop(1);
}
};
Key.addListener(key_object);

Please see the attached file......it is working fine......


View PostGanesan_Priya, on 15 Apr, 2008 - 02:49 AM, said:

Hi
You dont use enterframe concept for that.....Instead of that you can apply Key.addlistener concept you can get better solution......
The following code is working fine for me....
Please test it.....
var key_object:Object = new Object();
key_object.onkeydown = function() {
if (Key.isDown(Key.UP)) {
man_mc._y -= 5;
}
if (Key.isDown(Key.DOWN)) {
man_mc._y += 5;
}
if (Key.isDown(Key.LEFT)) {
man_mc._x -= 5;
}
if (Key.isDown(Key.RIGHT)) {
man_mc._x += 5;
}
if (target_mc.hitTest(man_mc) == true) {
man_mc.gotoAndStop(2);
} else {
man_mc.gotoAndStop(1);
}
};
Key.addListener(key_object);

Please see the attached file......it is working fine......

Was This Post Helpful? 0
  • +
  • -

#8 icedd  Icon User is offline

  • D.I.C Head
  • member icon

Reputation: 5
  • View blog
  • Posts: 98
  • Joined: 04-March 08

Re: Hit test problem ...ish

Posted 15 April 2008 - 02:53 AM

Thank you but where is the attached file?
Was This Post Helpful? 0
  • +
  • -

#9 Ganesan_Priya  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 4
  • Joined: 15-April 08

Re: Hit test problem ...ish

Posted 15 April 2008 - 10:43 PM

Hi Can you please take the attached file......?

Attached File(s)


Was This Post Helpful? 0
  • +
  • -

#10 icedd  Icon User is offline

  • D.I.C Head
  • member icon

Reputation: 5
  • View blog
  • Posts: 98
  • Joined: 04-March 08

Re: Hit test problem ...ish

Posted 16 April 2008 - 09:29 PM

Hey Thank you?

PS: When he hit the object, he didn't go to the next frame.. infact you didn't even have a next frame. But It was very easy to do using your code..

So thanks alot :)

ICEDD
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1