간단한 iPhone 게임을 만들고 있습니다 (하지만 클래스를 사용하려면 Flash를 사용해야합니다 ...). 게임에서 객체를 제거하려고 할 때 중대한 문제가 있습니다."오류 # 2025 제공된 DisplayObject는 발신자의 하위 여야합니다." removeChild();를 시도 할 때;
게임은 무한한 "새로 고침"이있는 역동적 인 시간 낭비 버블 랩 게임입니다. 사용자가 모든 거품을 튀기면보다 무작위로 생성됩니다. (배열이 비어있을 때 setup()
으로 다시 전화하십시오.)
지금까지는 라이브러리에서 코드별로 끌어와 무작위로 스테이지에 배치 한 각기 다른 5 가지 색상의 버블 그래픽 중 하나를 사용했습니다. 그러나, 나는 오버랩을 좋아하지 않는다. 그래서 나는 각각의 버블에 작은 사각형 히트 공간을 주었다. 그래서 무작위로 배치되고 상당히 겹치게 될 것이다. 어떤 이유로 든 거품을 제거하려고 할 때 나에게 준다.
오류 # 2025 제공된 DisplayObject는 호출자의 자식이어야합니다.
addChild
및 removeChild
에 스테이지를 추가하려고 시도했지만 동일한 오류가 발생합니다.
import flash.events.*;
import flash.display.*;
var bubbles:Array = new Array();
var b:BlueBubble = new BlueBubble();
var b2:GreenBubble = new GreenBubble();
var b3:PinkBubble = new PinkBubble();
var b4:PurpleBubble = new PurpleBubble();
var b5:YellowBubble = new YellowBubble();
// values to be tweaked later
var bNum:uint = 1;
var maxSize:uint = 100;
var minSize:uint = 1;
var range:uint = maxSize - minSize;
var tooBig:uint = 100;
function init():void {
setup();
stage.addEventListener(Event.ENTER_FRAME, onEveryFrame);
}
function setup():void {
for (var i:uint=0; i<bNum; i++) {
// blue
b.width = Math.ceil(Math.random() * range) + minSize;
b.height = b.width;
b.x = Math.random()*(stage.stageWidth - b.width);
b.y = Math.random()*(stage.stageHeight - b.height);
bubbles.push(b);
stage.addChild(b);
// green
b2.width = Math.ceil(Math.random() * range) + minSize;
b2.height = b2.width;
b2.x = Math.random()*(stage.stageWidth - b2.width);
b2.y = Math.random()*(stage.stageHeight - b2.height);
bubbles.push(b2);
stage.addChild(b2);
// pink
b3.width = Math.ceil(Math.random() * range) + minSize;
b3.height = b3.width;
b3.x = Math.random()*(stage.stageWidth - b3.width);
b3.y = Math.random()*(stage.stageHeight - b3.height);
bubbles.push(b3);
stage.addChild(b3);
// purple
b4.width = Math.ceil(Math.random() * range) + minSize;
b4.height = b4.width;
b4.x = Math.random()*(stage.stageWidth - b4.width);
b4.y = Math.random()*(stage.stageHeight - b4.height);
bubbles.push(b4);
stage.addChild(b4);
// yellow
b5.width = Math.ceil(Math.random() * range) + minSize;
b5.height = b5.width;
b5.x = Math.random()*(stage.stageWidth - b5.width);
b5.y = Math.random()*(stage.stageHeight - b5.height);
bubbles.push(b5);
stage.addChild(b5);
//add event listeners for bubbles later
}
}
function onEveryFrame(e:Event) {
for (var i:uint=0; i<bubbles.length; i++) {
bubbles[i].width++;
bubbles[i].height++;
if (bubbles[i].height >= tooBig && bubbles[i].width >= tooBig) {
bubbles[i].height = tooBig;
bubbles[i].width = tooBig;
}
// Blue hit testing
if (b2.hitGreen.hitTestObject(b.hitBlue)) {
removeChild(b);
}
if (b3.hitPink.hitTestObject(b.hitBlue)) {
removeChild(b);
}
if (b4.hitPurple.hitTestObject(b.hitBlue)) {
removeChild(b);
}
if (b5.hitYellow.hitTestObject(b.hitBlue)) {
removeChild(b);
}
// Other hit testing...
}
}
init();
음, 일의 종류를 변경 시도에 대한 이전 오류를 교환 "오류 # 1009 :. null 객체 참조의 속성이나 메서드에 액세스 할 수 없습니다" ...하지만 아무것도 이해할 수 없다는 null입니다, 그래서 그것을 왜? – user1769210