简体   繁体   English

Adobe Flash Actionscript 3符号内的碰撞检测

[英]Adobe Flash Actionscript 3 collision detection within symbol

I'm learning actionscript and I'm trying to do a basic pong game from a tutorial but I'm having trouble with finding a way to properly code the collisions. 我正在学习动作脚本,我正在尝试从教程中做一个基本的乒乓球游戏,但我找不到正确编码碰撞的方法。 Everything works but the collision wall extends past the edge of my symbol at the bottom of the screen. 一切正常,但碰撞墙延伸过屏幕底部符号的边缘。 I need the entire game to be within a symbol so I can have it within a menu interface that I plan on later importing it into. 我需要整个游戏都在一个符号内,所以我可以在一个菜单界面中将它放在我计划以后导入它中。 You can find the code frame by double clicking the pong game. 你可以通过双击乒乓游戏找到代码框架。

My problem is in the code: 我的问题在于代码:

//if the bottom of the ball is lower than the bottom of the screen
if(ball.y >= stage.stageHeight-ball.height/2){ 
    ball.y = stage.stageHeight-ball.height/2; //reposition it
}

I need to find a way to change to code to detect collision based on the boundaries of the symbol or pixel height rather than stage height but I don't know how. 我需要找到一种方法来改变代码来检测基于符号边界或像素高度而不是阶段高度的碰撞,但我不知道如何。 You can download the flash file to see it. 您可以下载Flash文件以查看它。

You have forgot that you are inside your Pong MovieClip which has the dimensions 550x400px which are different from your stage ones 960x540px and that's why your ball go out your black zone to your stage bottom border. 你已经忘记了你在你的Pong MovieClip里面,它的尺寸为550x400px,与你的舞台960x540px不同,这就是为什么你的球会从你的黑色区域走到你的舞台底部边界。

So you can : 所以你可以 :

  • Put your code directly into your root timeline, and it will work fine. 将您的代码直接放入根时间轴,它将正常工作。

Or 要么

  • Edit your current code to use your Pong MovieClip dimensions and not those of your stage. 编辑当前代码以使用Pong MovieClip维度而不是舞台维度。

Hope that can help. 希望能有所帮助。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM