编辑:我现在包含了一个 Player.as 和一个 addchild
我整天都在努力了解如何做到这一点,并在这样做的过程中再次学到了很多东西。但我已经到了需要帮助的地步。
我知道我必须这样做:在 Back1 类中创建一个 Collisions 变量。
因为名为 Back1 的背景是包含碰撞图像的影片剪辑
我找到了一个或 2 个很好的站点,可以很好地解释变量和类,但我仍然不知道应该如何解决这个问题
变量和类之后的研究:
http://www.republicofcode.com/tutorials/flash/as3variables/
上述问题导致以下错误,但我认为这是由于未在 Back1 类中创建 Collisions var
ArgumentError:错误 #1063:Bumper() 上的参数计数不匹配。预期:2,值 0。
在 flash.display::MovieClip/gotoAndStop() 在 DocumentClass/onRequestStart()DocumentClass.as:64] 在 flash.events::EventDispatcher/dispatchEventFunction() 在 flash.events::EventDispatcher/dispatchEvent() 在 MenuScreen/onClickStart( )MenuScreen.as:18]
package { import flash.display.MovieClip; import flash.events.*; import flash.events.KeyboardEvent; import flash.ui.Keyboard; import flash.geom.Point; import Bumper; //import Back1; public class Test extends MovieClip { public var leftBumping:Boolean = false; public var rightBumping:Boolean = false; public var upBumping:Boolean = false; public var downBumping:Boolean = false; public var leftBumpPoint:Point = new Point(-30,-55); public var rightBumpPoint:Point = new Point(30,-55); public var upBumpPoint:Point = new Point(0,-120); public var downBumpPoint:Point = new Point(0,0); public var scrollX:Number = 0; public var scrollY:Number = 500; public var xSpeed:Number = 0; public var ySpeed:Number = 0; public var speedConstant:Number = 4; public var frictionConstant:Number = 0.9; public var gravityConstant:Number = 1.8; public var jumpConstant:Number = -35; public var maxSpeedConstant:Number = 18; public var doubleJumpReady:Boolean = false; public var upReleasedInAir:Boolean = false; public var keyCollected:Boolean = false; public var doorOpen:Boolean = false; public var currentLevel:int = 1; public var animationState:String = "idle"; public var bulletList:Array = new Array(); public var enemyList:Array = new Array(); public var bumperList:Array = new Array(); public var back1:Back1; public var collisions:Collisions; //public var back1:Collisions = new Collisions ; public var player:Player; public function Test() { addEventListener(Event.ADDED_TO_STAGE, init); } public function init(e:Event):void { player = new Player(320, 360); back1 = new Back1(); collisions = new Collisions(); //back1.collisions = new Collisons(); addBumpersToLevel1(); } public function addBumpersToLevel1():void { addBumper(500, -115); addBumper(740, -115); } public function addPlayerTolevel1():void { addPlayer(320, 360); } public function loop(e:Event):void { trace("back1.collisions "+back1.collisions); trace("back1 "+back1); trace("collisions "+collisions); if (back1.collisions.hitTestPoint(player.x + leftBumpPoint.x,player.y + leftBumpPoint.y,true)) {
以防万一我添加了 Bumper.as
package {
import flash.display.MovieClip;
import flash.events.Event;
public class Bumper extends MovieClip{
public function Bumper(xLocation:int, yLocation:int) {
// constructor code
x = xLocation;
y = yLocation;
addEventListener(Event.ENTER_FRAME, bumper);
}
public function bumper(e:Event):void{
//code here
}
}
}
播放器.as
package {
import flash.display.MovieClip;
import flash.events.Event;
public class Player extends MovieClip {
public function Player(xLocation:int, yLocation:int) {
// constructor code
x = xLocation;
y = yLocation;
}
// public function removeSelf():void {
// trace("remove enemy");
// removeEventListener(Event.ENTER_FRAME, loop);
// this.parent.removeChild(this);
// }
}
}
Back1.as 文件(注意它必须被错误地实例化)
package {
import flash.display.MovieClip;
public class Back1 extends MovieClip {
//public var collisions:Back1;
//what should i put here?
}
}