简体   繁体   English

将CCPoint添加到CCArray

[英]Adding CCPoint to CCArray

I'm looking to call up a random CCPoint from CCArray , and then remove that point from the array so that it's not called up again. 我正在寻找从CCArray调用一个随机CCPoint ,然后从数组中删除该点,以便不再调用它。 This is the code I used: 这是我使用的代码:

    myArray->addObject(pos1);

Where pos1 is a CCPoint and myArray is a CCArray . 其中pos1CCPointmyArrayCCArray When I write that line, it brings up an error that reads: "No viable conversion from cocos2d::CCPoint to cocos2d::CCObject *". 当我写那行代码时,它会显示一个错误:“从cocos2d :: CCPoint到cocos2d :: CCObject *没有可行的转换*”。 I know this means that CCPoint doesn't inherit from CCObject , but just making it inherit CCObject doesn't help the problem. 我知道这意味着CCPoint不会从CCObject继承,但是仅使其继承CCObject并不能解决问题。 I've also tried typecasting pos1 as well but that doesn't work either. 我也尝试过类型转换pos1 ,但这也不起作用。 What do you suggest I do so that I can keep an array of points? 您建议我怎么做才能保留多个积分? Thanks in advance. 提前致谢。

@Shiva Kumar Ganthi comments with C-arrays are all good, but I think that using std::vector would be better. 具有C数组的@Shiva Kumar Ganthi注释都很好,但是我认为使用std::vector会更好。 The main improvement would be the fact, that you can always check how many elements a vector has, and you don't have to worry about setting a used element to NULL and then checking for it when you take another random position (which can prove dangerous with big arrays that have a lot of NULL s). 主要的改进将是这样的事实:您始终可以检查vector有多少个元素,而不必担心将用过的元素设置为NULL并在您采取另一个随机位置时进行检查(这可以证明对于具有很多NULL的大数组来说很危险)。

Also learning about standard containers is also beneficial. 学习标准容器也是有益的。

Oh, on a side note : you don't have to use CCPoint * , CCPoint is just fine. 哦, CCPoint * :您不必使用CCPoint *CCPoint很好。

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

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