是有可能检测一个碰撞上只有特定颜色? AS3 [英] Is it possible to detect a collision on only a specific colour? AS3
问题描述
我工作的一个游戏,一个边框围绕一个球绘制。
I am working on a game and a border is drawn around a ball.
边框尺寸取自一个XML文件中。
The border dimensions are taken from an XML file.
边框的边缘都使用由:
lineThick = Number(xmlContent.rec[i].look.strokethick);
lineColor = int(xmlContent.rec[i].look.strokehex);
drawings.graphics.lineStyle(lineThick, lineColor);
drawings.graphics.beginFill(fillColor);
在一个创建绘图功能
现在我想知道的是如何检测的时候,我的球(即移动在屏幕上)已经打到了边?
Now what I want to know is how can I detect when my ball (that is moving around the screen) has hit the edge?
我想过要把它检测到它撞色黑色,因为这是所有的线的颜色。
I thought about trying to make it detect when it hits the colour black because that is the colour of all the lines.
有没有更好的办法?是否有可能检测出黑色,使球反弹回来?
Is there a better way? is it possible to detect the colour black and make the ball bounce back?
推荐答案
在codeI用于游戏的这一部分,你可能需要稍微改变它自己的需求:
函数testCollisions():无效{
对于(VAR我:INT = enemies.length -1; I> = 0;我 - ){
tempEnemy =敌人[I]
如果(tempEnemy.hitTestObject(播放器)){
//这是部分放$ C $下反弹回球
}
}
}
This a part of the code i use for gaming, you might have to change it slightly to your own need:
function testCollisions():void {
for (var i:int = enemies.length -1;i >= 0;i--) {
tempEnemy = enemies[i];
if (tempEnemy.hitTestObject(player)) {
//this is the part to put the code for bouncing the ball back
}
}
}
下面我测试的球员碰撞的tempEnemy。我把所有的敌人阵列我tempEnemy对象。这可能不是最有效的,但它的工作原理。
Here i am testing collision of player on tempEnemy. i have all of my tempEnemy objects in the enemies array. this might not be the most efficient but it works.
这篇关于是有可能检测一个碰撞上只有特定颜色? AS3的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!