public virtual bool onTextFieldDeleteBackward(CCTextFieldTTF pSender, string delText, int nLen) { // create a delete text sprite and do some action CCLabelTTF label = new CCLabelTTF(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; CCRandom rand = new CCRandom(); CCSize winSize = CCDirector.SharedDirector.WinSize; CCPoint endPos = new CCPoint(-winSize.Width / 4.0f, winSize.Height * (0.5f + (float)CCRandom.Next() / (2.0f * RAND_MAX))); float duration = 1; float rotateDuration = 0.2f; int repeatTime = 5; label.Position = beginPos; CCAction seq = CCSequence.FromActions( CCSpawn.FromActions( new CCMoveTo(duration, endPos), new CCRepeat( new CCRotateBy(rotateDuration, (CCRandom.Next() % 2 > 0) ? 360 : -360), (uint)repeatTime), new CCFadeOut(duration)), new CCCallFuncN(callbackRemoveNodeWhenDidAction)); label.RunAction(seq); return(false); }
private void InitParticle(ref CCParticle particle) { // timeToLive // no negative life. prevent division by 0 particle.timeToLive = Math.Max(0, m_fLife + m_fLifeVar * CCRandom.Float_Minus1_1()); // position particle.pos.X = m_tSourcePosition.X + m_tPosVar.X * CCRandom.Float_Minus1_1(); particle.pos.Y = m_tSourcePosition.Y + m_tPosVar.Y * CCRandom.Float_Minus1_1(); // Color CCColor4F start; start.R = MathHelper.Clamp(m_tStartColor.R + m_tStartColorVar.R * CCRandom.Float_Minus1_1(), 0, 1); start.G = MathHelper.Clamp(m_tStartColor.G + m_tStartColorVar.G * CCRandom.Float_Minus1_1(), 0, 1); start.B = MathHelper.Clamp(m_tStartColor.B + m_tStartColorVar.B * CCRandom.Float_Minus1_1(), 0, 1); start.A = MathHelper.Clamp(m_tStartColor.A + m_tStartColorVar.A * CCRandom.Float_Minus1_1(), 0, 1); CCColor4F end; end.R = MathHelper.Clamp(m_tEndColor.R + m_tEndColorVar.R * CCRandom.Float_Minus1_1(), 0, 1); end.G = MathHelper.Clamp(m_tEndColor.G + m_tEndColorVar.G * CCRandom.Float_Minus1_1(), 0, 1); end.B = MathHelper.Clamp(m_tEndColor.B + m_tEndColorVar.B * CCRandom.Float_Minus1_1(), 0, 1); end.A = MathHelper.Clamp(m_tEndColor.A + m_tEndColorVar.A * CCRandom.Float_Minus1_1(), 0, 1); particle.color = start; particle.deltaColor.R = (end.R - start.R) / particle.timeToLive; particle.deltaColor.G = (end.G - start.G) / particle.timeToLive; particle.deltaColor.B = (end.B - start.B) / particle.timeToLive; particle.deltaColor.A = (end.A - start.A) / particle.timeToLive; // size float startS = m_fStartSize + m_fStartSizeVar * CCRandom.Float_Minus1_1(); startS = Math.Max(0, startS); // No negative value particle.size = startS; if (m_fEndSize == kCCParticleStartSizeEqualToEndSize) { particle.deltaSize = 0; } else { float endS = m_fEndSize + m_fEndSizeVar * CCRandom.Float_Minus1_1(); endS = Math.Max(0, endS); // No negative values particle.deltaSize = (endS - startS) / particle.timeToLive; } // rotation float startA = m_fStartSpin + m_fStartSpinVar * CCRandom.Float_Minus1_1(); float endA = m_fEndSpin + m_fEndSpinVar * CCRandom.Float_Minus1_1(); particle.rotation = startA; particle.deltaRotation = (endA - startA) / particle.timeToLive; // position if (m_ePositionType == CCPositionType.Free) { particle.startPos = ConvertToWorldSpace(CCPoint.Zero); } else if (m_ePositionType == CCPositionType.Relative) { particle.startPos = m_obPosition; } // direction float a = MathHelper.ToRadians(m_fAngle + m_fAngleVar * CCRandom.Float_Minus1_1()); // Mode Gravity: A if (m_nEmitterMode == CCEmitterMode.Gravity) { var v = new CCPoint(CCMathHelper.Cos(a), CCMathHelper.Sin(a)); float s = modeA.speed + modeA.speedVar * CCRandom.Float_Minus1_1(); // direction particle.modeA.dir = v * s; // radial accel particle.modeA.radialAccel = modeA.radialAccel + modeA.radialAccelVar * CCRandom.Float_Minus1_1(); // tangential accel particle.modeA.tangentialAccel = modeA.tangentialAccel + modeA.tangentialAccelVar * CCRandom.Float_Minus1_1(); // rotation is dir if (modeA.rotationIsDir) { particle.rotation = -MathHelper.ToDegrees(CCPoint.ToAngle(particle.modeA.dir)); } } // Mode Radius: B else { // Set the default diameter of the particle from the source position float startRadius = modeB.startRadius + modeB.startRadiusVar * CCRandom.Float_Minus1_1(); float endRadius = modeB.endRadius + modeB.endRadiusVar * CCRandom.Float_Minus1_1(); particle.modeB.radius = startRadius; if (modeB.endRadius == kCCParticleStartRadiusEqualToEndRadius) { particle.modeB.deltaRadius = 0; } else { particle.modeB.deltaRadius = (endRadius - startRadius) / particle.timeToLive; } particle.modeB.angle = a; particle.modeB.degreesPerSecond = MathHelper.ToRadians(modeB.rotatePerSecond + modeB.rotatePerSecondVar * CCRandom.Float_Minus1_1()); } }
public virtual bool onTextFieldDeleteBackward(CCTextFieldTTF pSender, string delText, int nLen) { // create a delete text sprite and do some action CCLabelTTF label = new CCLabelTTF(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; CCRandom rand = new CCRandom(); CCSize winSize = CCDirector.SharedDirector.WinSize; CCPoint endPos = new CCPoint(-winSize.Width / 4.0f, winSize.Height * (0.5f + (float)CCRandom.Next() / (2.0f * RAND_MAX))); float duration = 1; float rotateDuration = 0.2f; int repeatTime = 5; label.Position = beginPos; CCAction seq = new CCSequence( new CCSpawn( new CCMoveTo (duration, endPos), new CCRepeat ( new CCRotateBy (rotateDuration, (CCRandom.Next() % 2 > 0) ? 360 : -360), (uint)repeatTime), new CCFadeOut (duration)), new CCCallFuncN(callbackRemoveNodeWhenDidAction)); label.RunAction(seq); return false; }