bool CCNewGame :: init () {
bool bRet = false;
do
{
CC_BREAK_IF (! CCLayer :: init ());
/ / Add the protagonist wizard
CCTexture2D * pTextTure = CCTextureCache :: sharedTextureCache () -> addImage ("dragon.png");
this-> m_pSpriteBatch = CCSpriteBatchNode :: createWithTexture (pTextTure, 10);
this-> addChild (m_pSpriteBatch, 1,1);
this-> m_pFlyActionArray = CCArray :: create ();
for (int i = 0; i <8; i + +) {
CCAnimation * pAnimation = CCAnimation :: create ();
CC_BREAK_IF (! PAnimation);
pAnimation-> setDelayPerUnit (0.15f);
for (int j = 0; j <10; j + +) {
CCSpriteFrame * frame = CCSpriteFrame :: createWithTexture (this-> m_pSpriteBatch-> getTexture (),
CCRectMake (75 * j, 70 * i, 75,70));
CC_BREAK_IF (! Frame);
pAnimation-> addSpriteFrame (frame);
}
CCAnimate * anim = CCAnimate :: create (pAnimation);
this-> m_pFlyAction = CCRepeatForever :: create (anim);
this-> m_pFlyActionArray-> addObject (m_pFlyAction);
}
CCSpriteFrame * frame1 = CCSpriteFrame :: createWithTexture (this-> m_pSpriteBatch-> getTexture ()
, CCRectMake (75 * 0,70 * 0,75,70));
CC_BREAK_IF (! Frame1);
this-> m_pDragon = CCSprite :: createWithSpriteFrame (frame1);
this-> m_pDragon-> setPosition (ccp (160,240));
this-> m_pFlyAction = (CCAction *) m_pFlyActionArray-> objectAtIndex (0);
this-> m_pDragon-> runAction (m_pFlyAction);
this-> addChild (m_pDragon, 0,123);
this-> setTouchEnabled (true);
bRet = true;
} While (0);
return bRet;
}
void CCNewGame :: ccTouchEnded (CCTouch * pTouch, CCEvent * pEvent) {
CCPoint p = pTouch-> getLocation ();
CCPoint nowPoint = this-> getChildByTag (123) -> getPosition ();
CCPoint moveVector = ccpSub (p, nowPoint);
float distance = ccpLength (moveVector);
float moveAngle = ccpToAngle (moveVector);
float cocosAngle = CC_RADIANS_TO_DEGREES (-1 * moveAngle);
float moveDuration = distance / (480.0/3.0);
cocosAngle + = 23;
if (cocosAngle <0) {
cocosAngle + = 360;
}
int animNum = (int) ((cocosAngle) / 45);
this-> getChildByTag (123) -> stopAction (this-> m_pFlyAction);
this-> m_pFlyAction = (CCAction *) this-> m_pFlyActionArray-> objectAtIndex (animNum) ;/ / / error is this step
this-> getChildByTag (123) -> runAction (this-> m_pFlyAction);
this-> getChildByTag (123) -> runAction (CCMoveTo :: create (moveDuration, p));
}
Reply:
Mainly on the screen dragon, dragon animation a total of eight, just put an animation to 8, to CCArry stored inside the init () method can be used inside the how, but one to ccTouchEnd () inside on the error , member objects in ccTouch () which can be called ah, but why memory overflow, it can be debugged, I do screen, want to fly to stop running, it should be a memory problem. seeking answers
Reply:
It should be because you created in the init array inside without retain, you can try to retain what
Reply:
For ah, did not apply for memory space, so the memory crash, and later somehow, just think of it today, ask questions, knot posted ha ~
No comments:
Post a Comment