我有点想要理解c++。我正在使用cocos2dx,并试图为游戏制作一个精灵(砖块)矢量。我能够向向量中添加一堆精灵(至少我认为我正在将它们加载到向量中),但是当我试图迭代并读取它们时,我会得到一个错误:“调用已删除的构造函数'cocos2d::Sprite'”。我以为我懂指南针,但有人能向我解释我做错了什么,以及这个片段是怎么回事吗?
std::vector<Sprite> sprites;
brick = Sprite::create("brick.png");
for ( int i = 0; i < 20; i++ ){
Spri
我是Cocos2d的新手。我也知道
但是我不知道如何只在一个循环中移动一个精灵,在那之后,它会触发完成块或调用回调。
// Don't know how to create an action which moves the sprite in a circle
CCAction *moveSpriteInACircle;
// the completion callback block
CCCallBlockN * actionMoveDone = [CCCallBlockN actionWithBlock:actionMoveDoneBlock];
// run the ac
要重现这个问题,只需按下右下角的关闭按钮,在安卓系统上它会崩溃,但在iOS上不会。
导致崩溃的代码是:
void TestNode::test()
{
// This will cause crash on Android, but OK on iOS
CCCallFunc *selector = CCCallFunc::create(this, callfunc_selector(TestNode::destroy));
this->runAction(selector);
// This is ok on both Android and iOS
/
我用cocos2d-x-3.13.
我刚刚开始,但我遇到了一些问题:我在一个向量中有很多精灵,每一秒我就把它们移动到每个位置,当我想删除它们时,问题就出现了,因为我有一个用循环来移动它们的函数:
HelloWorldScene.cpp
bool HelloWorld::init() {
...
_enemies.reserve(15);
for (unsigned i = 0; i < 5; i++) {
//Here I create the sprites, and I activate the physics in each one :p
我有一个工作线程在后台进行计算,一旦工作线程完成计算,我想发送一个事件/消息来调用更新函数来更新屏幕上的图形。
我如何在cocos2d中做到这一点?
一些演示代码:
-(void) updateGraphic
{
//this one update all the graphics/sprite
}
//note workerThreadFunc is being used to start a new thread
-(void) workerThreadFunc
{
//...
//...
//finish calculation here
//since it's in a d
我有下面的代码,用于检查对sprite的接触:
void SpriteBlock::addEvents()
{
auto listener = cocos2d::EventListenerTouchOneByOne::create();
listener->setSwallowTouches(true);
listener->onTouchBegan = [&](cocos2d::Touch* touch, cocos2d::Event* event)
{
Vec2 p = touch->getLocation();
Rect rect = this
在我的游戏场景中,我从一个使用MoveBy动作随机移动的球类中产生球。我的问题是,在MoveTo操作结束后,我如何释放球?请看下面的代码:
//GameScene class
...
Ball *ball = new Ball(); //<----need to release this after action is over
ball->spawnBall(this);
...
//Ball class
...
void Ball::spawnBall(cocos2d::Layer *layer){
ball = Sprite::create();
la
在Cocos2d中,您可以使用"CCMoveTo“方法将sprite移动到特定位置,如下所示:
[sprite runAction: [CCMoveTo actionWithDuration:1 position:location]]; //Moves a sprite to the position "location" in 1 second.
在Corona SDK中有这样的东西吗?我试着用谷歌搜索了一下,但什么也没找到。