Alright, I’m following an outdated tutorial and coding a test game in the latest version and I noticed a consistent error, I’d like to know what’s the formal and uniformed way to tackle this logic problem.
Call to non-static member function without an object argument
What am I suppose to do? Create a new object solely to access it’s class methods? That solution feels a bit wrong to me, so I’m wondering if someone can enlighten me on this problem, thanks!
Ok, after looking at the CCARRAY_FOREACH() declaration in the header file, I’m not exactly sure how it works, is this also the right way to use it?
Does ‘itAster’ become the object the CCARRAY_FOREACH() is currently on? Is it a reference? Thanks again!
‘itAster’ is CCSprite type object. So there is no chance it become an object of CCArray. CCARRAY_FOREACH will run a loop for each child object of CCArray. In your case, CCArray is _asteroids and Every child of CCArray will refer back to itAster. Of couse it will refer one child at a time and will refer to next one in next iteration. The process continue until all children are traversed.
CCObject **itAster;
CCARRAY\_FOREACH {
CCSprite**asteroid = (CCSprite \*)itAster;
if ( ! asteroid-\>isVisible() )
continue;
\</pre
So basically, CCARRAY\_FOREACH() only accepts parameters of type CCArray and CCObject? However in Xcode, the parameters show up as ‘**Array*’ and ’**Object*\_’, how do I know the specific required type for sure?
So basically, CCARRAY_FOREACH() only accepts parameters of type CCArray and CCObject? However in Xcode, the parameters show up as ‘*Array’ and ’*Object_’, how do I know the specific required type for sure?
CCArray can only hold CCObject objects. For CCARRAY_FOREACH(), you pass the CCArray you want to loop in to and CCObject will be the object per iteration. In your example, you could read it as for each itAster in _asteroids do these