Answer the question
In order to leave comments, you need to log in
Actionscript 3.0 how to properly use hitTestPoint?
Hello.
The essence of the game in a nutshell, the ball rolls, jumps, falls and. etc.
I wanted to make a simple game and ran into this problem:
When the ball falls on a flat surface, it stops in time, but if it hits some corner, it sometimes slips, everything can be seen in the screenshot.
private function run(e:Event):void{ //Функция запускается через ENTER_FRAME
if(left){xspeed = 5;} //если переменная left=true (шар катится влево)
else if(right){xspeed = -5;} //если переменная right=true (шар катится вправо)
else {xspeed = 0;} //в другом случае скорость =0 и шар стоит на месте
yspeed++; //Что то типа гравитации шар постоянно падает
ball_mc.x -= xspeed;
ball_mc.y += yspeed;
//Вот проблемный участок кода
while (boks_mc.hitTestPoint(ball_mc.x,ball_mc.y+ball_mc.width/2,true)){
ball_mc.y--;
yspeed = 0;
jamp = false;
}
while (boks_mc.hitTestPoint(ball_mc.x+ball_mc.width/2,ball_mc.y,true)){
ball_mc.x--;
xspeed = 0;
}
while (boks_mc.hitTestPoint(ball_mc.x-ball_mc.width/2,ball_mc.y,true)){
ball_mc.x++;
xspeed = 0;
}
}
Answer the question
In order to leave comments, you need to log in
This is not a glitch, you misunderstood the essence of this method.
hitTestPoint() - Calculates the display object to determine if it overlaps or intersects the x and y point . The x and y parameters specify a point in the coordinate plane of the client area, not the display object container containing the object (unless the container itself is the client area). hitTestObject()
should suit you better
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question