void HelloWorld::createSprite()
{
  // ask director the window size
  CCSize size = CCDirector::sharedDirector()->getWinSize();
  
  CCTexture2D* texture = CCTextureCache::sharedTextureCache()->addImage("ic_paintroid_logo.png");
  
  TouchSprite* pSprite = new TouchSprite(this);
  pSprite->initWithTexture(texture);
  
  // position the sprite on the center of the screen
  //pSprite->setPosition( ccp(size.width/2, size.height/2) );
  
  int startPos = (int)std::rand() % (int)size.height;
  pSprite->setPosition( ccp(0, startPos) );
  
  // add the sprite as a child to this layer
  this->addChild(pSprite, 0);
  
  CCFiniteTimeAction* actionMove = CCMoveTo::actionWithDuration((rand() % 3) + 2, ccp(size.width, startPos));
  pSprite->runAction(actionMove);
  
  CCFiniteTimeAction* moveFinished = CCCallFuncN::actionWithTarget(this, callfuncN_selector(HelloWorld::moveFinished));
  pSprite->runAction(CCSequence::actions(actionMove, moveFinished, NULL));
}
示例#2
0
void GamePlay::onTouchMoved(Touch *touch, Event *unused_event) {
	if (gameState == Playing) {
		for (int i = 0; i < SUM_NUM; i++) {
			TouchSprite* test = (TouchSprite*) this->getChildByTag(
					TAG_NUMBER + i);
			if (test->isTouch == true)
				test->setPosition(touch->getLocation());
		}
	}
}
示例#3
0
void GamePlay::onTouchEnded(Touch *touch, Event *unused_event) {
//touch end number button
	if (gameState == Playing) {
		for (int i = 0; i < SUM_NUM; i++) {
			TouchSprite* test = (TouchSprite*) this->getChildByTag(
					TAG_NUMBER + i);
			if (test->isTouch == true) {
				//in frame
				for (int j = 0; j < SUM_NUM; j++) {
					TouchSprite* frame = (TouchSprite*) this->getChildByTag(
							TAG_FRAME_PLAY + j);
					if (frame->isTouchingSprite(touch)
							&& frame->isFixed == false) {
						//di chuyen den o da co so
						if (frame->score != 0 && frame->score != (i + 1)) {
							TouchSprite* transform =
									(TouchSprite*) this->getChildByTag(
											TAG_NUMBER + (frame->score) - 1);
							if (test->posframe != NULL
									&& test->posframe->score != 0) {
								auto actionTo = MoveTo::create(0.2,
										test->posframe->getPosition());
								transform->runAction(actionTo);
								transform->posframe = test->posframe;
								test->posframe->score = frame->score;
							} else {
								auto actionTo =
										MoveTo::create(0.2,
												frameReady[(frame->score - 1)]->getPosition());
								transform->runAction(actionTo);
								transform->posframe = NULL;
							}
						} else {
							//set lai gia tri frame da chuyen
							if (test->posframe != NULL) {
								test->posframe->score = 0;
							}
						}

						//set gia tri frame moi
						frame->score = i + 1;
						auto actionTo = MoveTo::create(0.2,
								frame->getPosition());
						test->isTouch = false;
						test->posframe = frame;
						test->runAction(actionTo);
						test->setZOrder(10);
						if (onSound)
							CocosDenshion::SimpleAudioEngine::sharedEngine()->playEffect(
									"sound/tapNumber.mp3");
						return;
					}
				}

				//out frame
				test->setPosition(touch->getLocation());
				test->isTouch = false;
				test->setZOrder(10);

				//set frame score = 0
				if (test->posframe != NULL) {
					test->posframe->score = 0;
					test->posframe = NULL;
				}
			}
		}
	}
}