CCActionInterval* CCAnimate::reverse(void)
{
	NSMutableArray<CCSpriteFrame*> *pOldArray = m_pAnimation->getFrames();
	NSMutableArray<CCSpriteFrame*> *pNewArray = new NSMutableArray<CCSpriteFrame*>(pOldArray->count());
   
	if (pOldArray->count() > 0)
	{
		CCSpriteFrame *pElement;
		NSMutableArray<CCSpriteFrame*>::NSMutableArrayRevIterator iter;
		for (iter = pOldArray->rbegin(); iter != pOldArray->rend(); iter++)
		{
			pElement = *iter;
			if (! pElement)
			{
				break;
			}

			pNewArray->addObject((CCSpriteFrame*)(pElement->copy()->autorelease()));
		}
	}

	CCAnimation *pNewAnim = CCAnimation::animationWithName(m_pAnimation->getName(),
		m_pAnimation->getDelay(), pNewArray);

	pNewArray->release();

	return CCAnimate::actionWithDuration(m_fDuration, pNewAnim, m_bRestoreOriginalFrame);
}
示例#2
0
//------------------------------------------------------------------
//
// PongLayer
//
//------------------------------------------------------------------
PongLayer::PongLayer()
{
	m_ballStartingVelocity = CGPointMake(20.0f, -100.0f);
	
    m_ball = Ball::ballWithTexture( CCTextureCache::sharedTextureCache()->addImage(s_Ball) );
	m_ball->setPosition( CGPointMake(160.0f, 240.0f) );
	m_ball->setVelocity( m_ballStartingVelocity );
	addChild( m_ball );
	m_ball->retain();
	
	CCTexture2D* paddleTexture = CCTextureCache::sharedTextureCache()->addImage(s_Paddle);
	
	NSMutableArray<NSObject *> *paddlesM = new NSMutableArray<NSObject *>(4);
	
	Paddle* paddle = Paddle::paddleWithTexture(paddleTexture);
	paddle->setPosition( CGPointMake(160, 15) );
	paddlesM->addObject( paddle );
	
	paddle = Paddle::paddleWithTexture( paddleTexture );
	paddle->setPosition( CGPointMake(160, 480 - kStatusBarHeight - 15) );
	paddlesM->addObject( paddle );
	
	paddle = Paddle::paddleWithTexture( paddleTexture );
	paddle->setPosition( CGPointMake(160, 100) );
	paddlesM->addObject( paddle );
	
	paddle = Paddle::paddleWithTexture( paddleTexture );
	paddle->setPosition( CGPointMake(160, 480 - kStatusBarHeight - 100) );
	paddlesM->addObject( paddle );
	
	m_paddles = paddlesM->copy();
	
    NSMutableArray<NSObject *>::NSMutableArrayIterator it;
	for(it = m_paddles->begin(); it != m_paddles->end(); it++)
	{
		paddle = (Paddle*)(*it);

		if(!paddle)
			break;

		addChild(paddle);
	}

	paddlesM->release();

	schedule( schedule_selector(PongLayer::doStep) );
}