I am trying to make a bubble shooter game. I have searched all but not getting any help from anywhere If anyone has the source code then please give that to me.
Or
If you can help me in solving this problem
I am trying to make a bubble shooter game. I have searched all but not getting any help from anywhere If anyone has the source code then please give that to me.
Or
If you can help me in solving this problem
Array is deprecated. Use vector instead.
Let me show you some simple example:
Vector<Node*> myVector = getChildren();
Vector<Node*>::iterator myIterator;
for (myIterator = myVector.begin(); myIterator != myVector.end(); ++myIterator)
{
auto mySprite = *myIterator;
// do something with this sprite.
}
Thanks for the help.
Will using vector instead of array can do the same task?
int BaseScene::generateRandom()
{
int rn = arc4random()%6+1;
CCArray * balls = (CCArray*) this->getChildren();
CCArray * ballsTypeLeft = CCArray::create();
{
for (int j=0; jcount(); j++)
{
CCNode * a = (CCNode*)balls->objectAtIndex(j);
if(a->getTag() >= Tag_Ball_Start)
{
Ball * currentBall = (Ball*)balls->objectAtIndex(j);
bool alreadyHas = false;
for(int k=0;kcount();k++)
{
if(strcmp(((CCString*)ballsTypeLeft->objectAtIndex(k))->getCString(), (CCString::createWithFormat("%d",currentBall->type))->getCString()) == 0)
{
alreadyHas = true;
}
}
if(alreadyHas)
{
}
else
{
ballsTypeLeft->addObject(CCString::createWithFormat("%d",currentBall->type));
}
}
}
}
if(ballsTypeLeft->count() <=2)
{
int tmp = arc4random()%ballsTypeLeft->count();
return ((CCString*)ballsTypeLeft->objectAtIndex(tmp))->intValue();
}
you’re welcome.
Yes, the vector is standard for C*+ (Array is come from cocos2d obj-C)
Vector<Node*> balls = getChildren();
Vector<Node*>::iterator myIterator;
for (myIterator = balls.begin(); myIterator != balls.end(); ++myIterator)
{
auto a = *myIterator;
if(a->getTag() >= Tag_Ball_Start)
{
//do some work with a
}
}
For “addObject” method you can use “pushback” method in vectors.
Search google for vector and you can find your answer, and if you need some help, always, there is some people here to help you.
Thank you so much its working.
But what about the line “Ball * currentBall = (Ball*)balls->objectAtIndex(j);”
what should I do over here.
I am quite new to this so not able to make it working.
It would be more helpful if you can convert the whole method using Vector.
Desperately waiting for the reply.
Thanks in advance.
int BaseScene::generateRandom()
{
int rn = arc4random()%6+1;
Vector<Node*> balls = this->getChildren();
Vector<string> ballsTypeLeft;
{
for (Node * a : balls)
{
// CCNode * a = (CCNode*)balls->objectAtIndex(j);
if(a->getTag() >= Tag_Ball_Start)
{
Ball * currentBall = dynamic_cast<Ball*>(a);
bool alreadyHas = false;
for(int k=0;kcount();k++)
{
if(strcmp(((CCString*)ballsTypeLeft.at(k))->getCString(), (CCString::createWithFormat("%d",currentBall->type))->getCString()) == 0)
{
alreadyHas = true;
}
}
if(alreadyHas)
{
}
else
{
ballsTypeLeft.pushBack(CCString::createWithFormat("%d",currentBall->type));
}
}
}
}
if(ballsTypeLeft.size() <=2)
{
int tmp = arc4random()%ballsTypeLeft.size();
return ((CCString*)ballsTypeLeft.at(tmp))->intValue();
}
return rn;
}
I do nt understand from where jcount(), and kcount() came, so i improvised… you must modify above code to suits your needs better.
Thanks
Thanks a lot.
It was “j < balls -> count();” in place of jcount and
k < ballsTypeLeft -> count() in place of kcount.
Inside for loop replace ballsTypeLeft->count()
with ballsTypeLeft.size()
, I think you should look into Vector and its method to better understand what methods you have. Also ballsTypeLeft
is uninitialized so it will always return 0
when you do ballsTypeLeft.size()
. Initialize it with appropriate type as well in order for it to work.
I am not getting the help from anywhere. What should I have to do the next?
Please help.
Thanks
ballsTypeLeft
is a vector of String
, you can not cast String
to String*
.
To solve your problem, ballsTypeLeft
has to be declared as Vector<String*>
.
IMHO, std::vector<std::string>
is better.
Thanks a lot.
All the errors has been resolved.
But a new error came after compiling and I don’t have any idea from where it is coming.
Error:
and
2.Error C2893 Failed to specialize function template ‘unknown-type std::invoke(_Callable &&,_Types &&…)’ OnVisual c:\program files (x86)\microsoft visual studio 14.0\vc\include\type_traits 1491
Can you post the full error log so I can know where the errors come from?