热门标签 | HotTags
当前位置:  开发笔记 > 编程语言 > 正文

AS3在对象本身中进行碰撞检测-AS3collisiondetectioninanobjectitself

I´mprogramingaspaceshipsidescrollinas3.Thebottomofthestagearemountainsandherecomes

I´m programing a space ship side scroll in as3. The bottom of the stage are mountains and here comes the problem, when I try to detect the ship collision against the mountains.. Because the poor collision detection and the need of avoid large loops my idea is create an object that works as a collider itself detecting a collision and avoiding parse all the stage or more selective metod. I place "by hand" in the flash stage several instances of circles with a class for manage them where I place the If(this.collider.hits(ship)....
I spent looong time but I can find the way to make it work some of the mistakes i get are like this Error 1061: Call to a possibly undefined method hitTestObject through a reference with static type Class. some Idea? Thanks in advance

我在as3编写太空船侧滚动。舞台的底部是山脉,这就是问题,当我试图探测船撞击山脉时。由于不良的碰撞检测和避免大环的需要,我的想法是创造一个对象作为对撞机本身检测碰撞并避免解析所有阶段或更具选择性的方法。我在闪存阶段“手动”放置了一个带有类的圆圈实例,用于管理它们,我放置了If(this.collider.hits(ship)....我花了很多时间,但我可以找到制作方法它工作的一些错误我得到的是这样的错误1061:通过静态类型类的引用调用可能未定义的方法hitTestObject。一些想法?提前谢谢

1 个解决方案

#1


when you hit test with points it is important that the point being tested is relative to the object being tested against, eg

当你用点击测试时,测试点与被测对象相关是很重要的,例如

if(mountain.hitTestPoint(this.x + circle1.x, this.y + circle1.y))

if(mountain.hitTestPoint(this.x + circle1.x,this.y + circle1.y))

will return true if the circles are inside the object calling the function because their position relative to the mountain is now relative to it rather then relative to the ships xy position within the clip... hope that makes sense.

如果圆圈位于调用函数的对象内部,则返回true,因为它们相对于山的位置现在相对于它而不是相对于剪辑中的xy位置...希望这是有道理的。

btw I have done this myself in the past but I would have to remind you that you can only hit test with the points so there is no need to have circles, use blank sprites instead and set the visible flag in the properties panel to false, no drawing will make it slightly faster... not that you will notice, also sprites/graphics use less memory then movie clips.

顺便说一下,我自己过去也做过这个,但是我必须提醒你,你只能用点进行测试,所以不需要有圆圈,而是使用空白精灵,并将属性面板中的可见标志设置为false,没有绘图会让它稍微快一点......不是你会注意到,精灵/图形使用的内存比电影剪辑少。

also I would recommend hard coding some points in the clips rather then actually adding the clips in the sprite/clip itself, this will make it easier to work with them and scale later on (believe me this will annoy the hair from your head to do something later and slow the game to scale on the fly)

我还建议硬编码片段中的一些点,而不是实际添加片段/片段中的片段,这样可以更容易地使用它们并稍后进行缩放(相信我会惹恼你脑袋里的头发)以后的东西,慢慢地让游戏在飞行中缩放)

try something like this... you can determine the points values by adding a clip to the movie clip and getting its position from the properties if you must.

尝试这样的事情......你可以通过向影片剪辑添加剪辑并从属性中获取其位置来确定点值(如果必须)。

private var hitPoints:Vector. = new Vector.

hitPoints.push(new Point(10, 40));
hitPoints.push(new Point(30, 40));
//...do this for all your points

//loop through all your points and check if the hit relative to the ships position.
for(var i:int = 0; i 

in this code you will need to make sure the scene object is a reference to your scenery at the bottom of the screen.

在此代码中,您需要确保场景对象是对屏幕底部的场景的引用。

I hope this helps but if this is not enough help then you should post some of your code here so we can have a look and see where it can be improved.

我希望这有帮助,但如果这还不够,那么你应该在这里发布一些代码,这样我们就可以看看它可以改进的地方了。


推荐阅读
author-avatar
萧俊瑄俊明纬伦
这个家伙很懒,什么也没留下!
PHP1.CN | 中国最专业的PHP中文社区 | DevBox开发工具箱 | json解析格式化 |PHP资讯 | PHP教程 | 数据库技术 | 服务器技术 | 前端开发技术 | PHP框架 | 开发工具 | 在线工具
Copyright © 1998 - 2020 PHP1.CN. All Rights Reserved | 京公网安备 11010802041100号 | 京ICP备19059560号-4 | PHP1.CN 第一PHP社区 版权所有