HittestObject在ActionScript类中不起作用
我正在尝试测试.AS文件中的子弹是否触摸.fla文件中定义的播放器。
我在.fla文件中有此IF语句
if (spaceBarPressed == true) {
var eb = new EnemyBullet(player)
stage.addChild(eb)
eb.x = enemy.x + 120
eb.y = enemy.y + 120
}
,并且在我的.AS文件中有此语句
public function EnemyBullet(player) {
addEventListener(Event.ENTER_FRAME, update)
if (this.hitTestObject(player)) {
trace("hit")
}
}
function update(event:Event) {
this.x+=5
}
,但我似乎无法使其工作。
I am trying to test if the bullet defined in the .as file is touching the player defined in the .fla file.
I have this if statement in my .fla file
if (spaceBarPressed == true) {
var eb = new EnemyBullet(player)
stage.addChild(eb)
eb.x = enemy.x + 120
eb.y = enemy.y + 120
}
and this in my .as file
public function EnemyBullet(player) {
addEventListener(Event.ENTER_FRAME, update)
if (this.hitTestObject(player)) {
trace("hit")
}
}
function update(event:Event) {
this.x+=5
}
But I can't seem to get it to work.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我通过将对象播放器发送到类中的函数eneybullet,然后将其存储在类型的DisplayObject中,以将其存储在函数更新中。
.fla文件中的if statment的内容:
.as file 的内容
I fixed it by sending the object player to the function EnemyBullet in the class, and stored it in a variable of type DisplayObject to reference it in the function update.
Contents of if Statment in .fla file:
Contents of .as file