我使用“ localToGlobal”方法检测碰撞。我为敌人的所有边界设置了边界点,但发生了碰撞。但是移动时它不起作用。
这是有关问题的图片。
https://s33.postimg.cc/6fuw14nb3/image.gif-工作
https://s33.postimg.cc/cutwy04db/image.gif-不起作用
代码
import flash.geom.Point;
import flash.net.SharedObject;
import flash.events.NetStatusEvent;
import flash.events.Event;
import flash.events.MouseEvent;
import flash.net.URLLoader;
import flash.net.URLRequest
import flash.display.Loader;
import flash.events.Event;
import flash.system.Capabilities;
import flash.text.TextField;
import flash.display.MovieClip;
import flash.display.Sprite;
import flash.display.Shape;
import flash.display.StageAlign;
import flash.display.StageScaleMode;
import flash.text.TextFormat;
import flash.text.TextFormatAlign;
var geriyonlev1:Number=+4;
var increment:Number = 0; //amount the car moves each frame
var carRotation:Number = carMC.rotation; //rotation of the car
var aracsag:Number = +5;
var aracsol:Number = -5;
var bPoint:Point = new Point(34,65);//right bottom corner
bPoint = dubageri1.localToGlobal(bPoint);
var cPoint:Point = new Point(-34,-40);//left top corner
cPoint = dubageri1.localToGlobal(cPoint);
var pxPoint:Point = new Point(-40,65);//left bottom corner
pxPoint = dubageri1.localToGlobal(pxPoint);
var orPoint:Point = new Point(27,-40);//right top corner
orPoint = dubageri1.localToGlobal(orPoint);
///*** HIT CONTROL EVENT *** \
stage.addEventListener(Event.ENTER_FRAME,sssa);
function sssa(event:Event) {
var zHit:Boolean = carMC.hitTestPoint(bPoint.x, bPoint.y, true);
textbaba.text = zHit? "! HIT !": "NO HIT";
if(zHit){
//dubageri1.gotoAndPlay(2);
}
var cHit:Boolean = carMC.hitTestPoint(cPoint.x, cPoint.y, true);
textbaba2.text = cHit? "! HIT !": "NO HIT";
if(cHit){
//dubageri1.gotoAndPlay(2);
}
var pxHit:Boolean = carMC.hitTestPoint(pxPoint.x, pxPoint.y, true);
textbaba3.text = pxHit? "! HIT !": "NO HIT";
if(pxHit){
//dubageri1.gotoAndPlay(2);
}
var orHit:Boolean = carMC.hitTestPoint(orPoint.x, orPoint.y, true);
textbaba4.text = orHit? "! HIT !": "NO HIT";
if(orHit){
//dubageri1.gotoAndPlay(2);
}
//carMC.x=mouseX;
//carMC.y=mouseY;
}
stage.addEventListener(Event.ENTER_FRAME,ilkcikis);
function ilkcikis(event:Event) {
if (geribas.yonler < -10) {
geribas.bizimnumara = geribas.yonler;
stage.addEventListener(Event.ENTER_FRAME,aracharekets);
stage.removeEventListener(Event.ENTER_FRAME,ilkcikis);
trace("kalkti");
}else if (geribas.yonler > +10) {
geribas.bizimnumara = geribas.yonler;
stage.addEventListener(Event.ENTER_FRAME,aracharekets);
stage.removeEventListener(Event.ENTER_FRAME,ilkcikis);
trace("kalkti");
}
}
///*** CAR CONTROL EVENT *** \
function aracharekets(event:Event) {
if(geribas.yonler>9){
carMC.rotation += .5*increment;
carMC.gotoAndStop(3);
carMC.rotation = -10;
carMC.x += aracsol;
}
if(geribas.yonler>15){
carMC.rotation += .5*increment;
carMC.gotoAndStop(3);
carMC.rotation = -13;
}
if(geribas.yonler>21){
carMC.rotation += .5*increment;
carMC.gotoAndStop(3);
carMC.rotation = -16;
}
if(geribas.yonler>27){
carMC.rotation += .5*increment;
carMC.gotoAndStop(3);
carMC.rotation = -19;
}
if(geribas.yonler>33){
carMC.rotation += .5*increment;
carMC.gotoAndStop(3);
carMC.rotation = -22;
}
if(geribas.yonler>39){
carMC.rotation += .5*increment;
carMC.gotoAndStop(3);
carMC.rotation = -25;
}
if(geribas.yonler>45){
carMC.rotation += .5*increment;
carMC.gotoAndStop(3);
carMC.rotation = -28;
}
if(geribas.yonler>51){
carMC.rotation += .5*increment;
carMC.gotoAndStop(3);
carMC.rotation = -31;
}
if(geribas.yonler>57){
carMC.rotation += .5*increment;
carMC.gotoAndStop(3);
carMC.rotation = -34;
}
if(geribas.yonler>63){
carMC.rotation += .5*increment;
carMC.gotoAndStop(3);
carMC.rotation = -37;
}
if(geribas.yonler>69){
carMC.rotation += .5*increment;
carMC.gotoAndStop(3);
carMC.rotation = -40;
}
if(geribas.yonler>75){
carMC.rotation += .5*increment;
carMC.gotoAndStop(3);
carMC.rotation = -43;
}
if(geribas.yonler>81){
carMC.rotation += .5*increment;
carMC.gotoAndStop(3);
carMC.rotation = -46;
}
if(geribas.yonler>85){
carMC.rotation += .5*increment;
carMC.gotoAndStop(3);
carMC.rotation = -49;
}
if(geribas.yonler>91){
carMC.rotation += .5*increment;
carMC.gotoAndStop(3);
carMC.rotation = -52;
}
////////////// DUZ HAREKETLER
if(geribas.yonler<-8){
carMC.gotoAndStop(1);
carMC.rotation = 0;
}
if(geribas.yonler<8){
carMC.gotoAndStop(1);
carMC.rotation = 0;
}
////////////// EKSI HAREKETLER
if(geribas.yonler<-9){
carMC.rotation -= .5*increment;
carMC.gotoAndStop(2);
carMC.rotation = 10;
carMC.x += aracsag;
}
if(geribas.yonler<-15){
carMC.rotation -= .5*increment;
carMC.gotoAndStop(2);
carMC.rotation = 13;
}
if(geribas.yonler<-21){
carMC.rotation -= .5*increment;
carMC.gotoAndStop(2);
carMC.rotation = 16;
}
if(geribas.yonler<-27){
carMC.rotation -= .5*increment;
carMC.gotoAndStop(2);
carMC.rotation = 19;
}
if(geribas.yonler<-33){
carMC.rotation -= .5*increment;
carMC.gotoAndStop(2);
carMC.rotation = 22;
}
if(geribas.yonler<-39){
carMC.rotation -= .5*increment;
carMC.gotoAndStop(2);
carMC.rotation = 25;
}
if(geribas.yonler<-45){
carMC.rotation -= .5*increment;
carMC.gotoAndStop(2);
carMC.rotation = 28;
}
if(geribas.yonler<-51){
carMC.rotation -= .5*increment;
carMC.gotoAndStop(2);
carMC.rotation = 31;
}
if(geribas.yonler<-57){
carMC.rotation -= .5*increment;
carMC.gotoAndStop(2);
carMC.rotation = 34;
}
if(geribas.yonler<-63){
carMC.rotation -= .5*increment;
carMC.gotoAndStop(2);
carMC.rotation = 37;
}
if(geribas.yonler<-69){
carMC.rotation -= .5*increment;
carMC.gotoAndStop(2);
carMC.rotation = 40;
}
if(geribas.yonler<-75){
carMC.rotation -= .5*increment;
carMC.gotoAndStop(2);
carMC.rotation = 43;
}
if(geribas.yonler<-81){
carMC.rotation -= .5*increment;
carMC.gotoAndStop(2);
carMC.rotation = 46;
}
if(geribas.yonler<-85){
carMC.rotation -= .5*increment;
carMC.gotoAndStop(2);
carMC.rotation = 49;
}
if(geribas.yonler<-91){
carMC.rotation -= .5*increment;
carMC.gotoAndStop(2);
carMC.rotation = 52;
}
/// ENEMY MOVE DOWN
dubageri1.y += geriyonlev1 +3;
}