简体   繁体   English

haxe / OpenFL:如何销毁/移除砖块

[英]haxe/OpenFL: How to destroy/remove a brick

I think this is rather strange that I haven't found anything... which means the answer is really simple but I'm not getting it or it's something else. 我觉得这很奇怪,因为我还没有找到任何东西……这意味着答案确实很简单,但是我没有得到答案,或者是其他原因。

I'm using haxe and openFL and the exercise is specific about not using any other frameworks. 我正在使用haxe和openFL,该练习专门针对不使用任何其他框架。 I'm building an Atari breakout clone. 我正在建立Atari突破克隆。 I'm trying to handle the collision event between the block and the ball. 我正在尝试处理块与球之间的碰撞事件。 All the blocks are stored in an array map[] which is being iterated. 所有块都存储在要迭代的数组map[]中。

if ( (ball.x > (map[i].x) && ball.x < (map[i].x+20)) && (ball.y > (map[i].y) && ball.y < (map[i].y+20)) ) {
                    this.removeChild(map[i]);
                    ballMovement.y *= -1;
                }

The ball has 10px radius and each block is 20x20. 球的半径为10px,每个块为20x20。 (Also, yes the ball will bounce awkwardly but I haven't had time to make a decent bouncing function yet, so that'll have to do for now) (而且,是的,球会笨拙地弹跳,但是我还没有时间做一个像样的弹跳功能,所以现在必须这样做)

I'm getting some unexpected behaviour. 我有一些意想不到的行为。 Yes the blocks disappear now, but Sometimes it seems the ball bounces off invisible blocks. 是的,方块现在消失了,但是有时候球似乎从看不见的方块上反弹了。 The question is, am I removing those elements properly? 问题是,我是否可以正确删除这些元素? Is the collision detection not properly set? 碰撞检测设置不正确吗?

也许您也应该从地图上删除block(map [i]),因为似乎您检查的是地图元素而不是显示元素的冲突。

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

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