What is the standard practice in using static methods?

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.

Old code:

if ( CCRect::CCRectIntersectsRect(shipLaser->boundingBox(), asteroid->boundingBox()) ) {
    shipLaser->setIsVisible(false) ;
    asteroid->setIsVisible(false) ;
    continue ;
}

Latest version:

if ( CCRect::intersectsRect(shipLazer->boundingBox(), asteroid->boundingBox()) ) {
    shipLaser->setVisible(false) ;
    asteroid->setVisible(false) ;
    continue ;
}

Error:

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!

You could write this like that: shipLazer->boundingBox().intersectsRect(asteroid->boundingBox())

Hey again! You’ve been really helpful with assisting my learning progress, just want to say thanks:D

That’s a style of coding I’ve not used in a while, you gave me a good jolt to the memory.

And of cause, here’s another question, haha

CCSprite *itAster = (CCSprite *)_asteroids->objectAtIndex(0);
CCARRAY_FOREACH(_asteroids, itAster) {
    if ( ! itAster->isVisible() )
        continue ;
}

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?

Edited the last post after a long period of time.

Nothing Sort wrote:
>

> CCObject *itAster;
>     CCARRAY_FOREACH(_asteroids, itAster) {
>         CCSprite *asteroid = (CCSprite *)itAster;
>         if ( ! asteroid->isVisible() )
>             continue;
> 

>

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