public virtual bool onTextFieldInsertText(CCTextFieldTTF pSender, string text, int nLen) { // if insert enter, treat as default to detach with ime if ("\n" == text) { return(false); } // if the textfield's char count more than m_nCharLimit, doesn't insert text anymore. if (pSender.CharCount >= m_nCharLimit) { return(true); } // create a insert text sprite and do some action CCLabelTTF label = CCLabelTTF.labelWithString(text, TextInputTestScene.FONT_NAME, TextInputTestScene.FONT_SIZE); this.addChild(label); ccColor3B color = new ccColor3B { r = 226, g = 121, b = 7 }; label.Color = color; // move the sprite from top to position CCPoint endPos = pSender.position; if (pSender.CharCount > 0) { endPos.x += pSender.contentSize.width / 2; } CCSize inputTextSize = label.contentSize; CCPoint beginPos = new CCPoint(endPos.x, CCDirector.sharedDirector().getWinSize().height - inputTextSize.height * 2); float duration = 0.5f; label.position = beginPos; label.scale = 8; CCAction seq = CCSequence.actions( CCSpawn.actions( CCMoveTo.actionWithDuration(duration, endPos), CCScaleTo.actionWithDuration(duration, 1), CCFadeOut.actionWithDuration(duration)), CCCallFuncN.actionWithTarget(this, callbackRemoveNodeWhenDidAction)); label.runAction(seq); return(false); }
public virtual bool onTextFieldDeleteBackward(CCTextFieldTTF pSender, string delText, int nLen) { // create a delete text sprite and do some action CCLabelTTF label = CCLabelTTF.labelWithString(delText, TextInputTestScene.FONT_NAME, TextInputTestScene.FONT_SIZE); this.addChild(label); // move the sprite to fly out CCPoint beginPos = pSender.position; CCSize textfieldSize = pSender.contentSize; CCSize labelSize = label.contentSize; beginPos.x += (textfieldSize.width - labelSize.width) / 2.0f; int RAND_MAX = 32767; Random rand = new Random(); CCSize winSize = CCDirector.sharedDirector().getWinSize(); CCPoint endPos = new CCPoint(-winSize.width / 4.0f, winSize.height * (0.5f + (float)rand.Next() / (2.0f * RAND_MAX))); float duration = 1; float rotateDuration = 0.2f; int repeatTime = 5; label.position = beginPos; CCAction seq = CCSequence.actions( CCSpawn.actions( CCMoveTo.actionWithDuration(duration, endPos), CCRepeat.actionWithAction( CCRotateBy.actionWithDuration(rotateDuration, (rand.Next() % 2 > 0) ? 360 : -360), (uint)repeatTime), CCFadeOut.actionWithDuration(duration)), CCCallFuncN.actionWithTarget(this, callbackRemoveNodeWhenDidAction)); label.runAction(seq); return(false); }