public override void update(float t) { // waits until enough time has passed for the next shake if (FloatUtils.EQ(shakeInterval, 0)) { } // shake every frame! else if (FloatUtils.Small(t, nextShake)) { return; // haven't reached the next shake point yet } else { nextShake += shakeInterval; // proceed with shake this time and increment for next shake goal } // calculate the dampening effect, if being used if (dampening) { float dFactor = (1 - t); amplitude.x = dFactor * startAmplitude.x; amplitude.y = dFactor * startAmplitude.y; } Vector2 newp = new Vector2((Random.Range(0, 100) / 100.0f * amplitude.x * 2) - amplitude.x, (Random.Range(0, 100) / 100.0f * amplitude.y * 2) - amplitude.y); // simultaneously un-move the last shake and move the next shake ((CCNode)_target).position = ((CCNode)_target).position - last + newp; // store the current shake value so it can be un-done last = newp; }
/** initializes the action with a set boundary */ public void initWithTarget(CCNode fNode, Rect rect) { base.init(); _followedNode = fNode; _boundarySet = true; _boundaryFullyCovered = false; Vector2 winSize = CCDirector.sharedDirector.winSize; _fullScreenSize = winSize; _halfScreenSize = _fullScreenSize * .5f; _leftBoundary = -((rect.position.x + rect.size.x) - _fullScreenSize.x); _rightBoundary = -rect.position.x; _topBoundary = -rect.position.y; _bottomBoundary = -((rect.position.y + rect.size.y) - _fullScreenSize.y); if (FloatUtils.Small(_rightBoundary, _leftBoundary)) { // screen width is larger than world's boundary width //set both in the middle of the world _rightBoundary = _leftBoundary = (_leftBoundary + _rightBoundary) / 2; } if (FloatUtils.Small(_topBoundary, _bottomBoundary)) { // screen width is larger than world's boundary width //set both in the middle of the world _topBoundary = _bottomBoundary = (_topBoundary + _bottomBoundary) / 2; } if (FloatUtils.EQ(_topBoundary, _bottomBoundary) && FloatUtils.EQ(_leftBoundary, _rightBoundary)) { _boundaryFullyCovered = true; } }
public override void update(float t) { float newT = 0; if (FloatUtils.EQ(t, 0) || FloatUtils.EQ(t, 1)) { newT = t; } else { t = t * 2; if (!FloatUtils.EQ(_period, 0)) { _period = 0.3f * 1.5f; } float s = _period / 4; t = t - 1; if (FloatUtils.Small(t, 0)) { newT = -0.5f * Mathf.Pow(2, 10 * t) * Mathf.Sin((t - s) * (Mathf.PI * 2) / _period); } else { newT = Mathf.Pow(2, -10 * t) * Mathf.Sin((t - s) * (Mathf.PI * 2) / _period) * 0.5f + 1; } } _inner.update(newT); }
public override void startWithTarget(object aTarget) { base.startWithTarget(aTarget); //Calculate angle _startAngle = ((CCNode)_target).rotation; if (FloatUtils.Big(_startAngle, 0)) { _startAngle = _startAngle % 360.0f; } else { _startAngle = _startAngle % -360.0f; } _diffAngle = _dstAngle - _startAngle; if (FloatUtils.Big(_diffAngle, 180)) { _diffAngle -= 360; } if (FloatUtils.Small(_diffAngle, -180)) { _diffAngle += 360; } }
public static bool RectIntersectsRect(Rect a, Rect b) { return(FloatUtils.Small(b.x, a.x + a.width) && FloatUtils.Small(a.x, (b.x + b.width)) && FloatUtils.Small(b.y, a.y + a.height) && FloatUtils.Small(a.y, b.y + b.height)); }
public override void update(float t) { t *= 2; if (FloatUtils.Small(t, 1)) { _inner.update(0.5f * Mathf.Pow(t, _rate)); } else { _inner.update(1.0f - 0.5f * Mathf.Pow(2 - t, _rate)); } }
public override void update(float t) { float overshoot = 1.70158f * 1.525f; t = t * 2; if (FloatUtils.Small(t, 1)) { _inner.update((t * t * ((overshoot + 1) * t - overshoot)) / 2); } else { t = t - 2; _inner.update((t * t * ((overshoot + 1) * t + overshoot)) / 2 + 1); } }
public override void update(float t) { // if t==1, ignore. Animation should finish with t==1 if (FloatUtils.Small(t, 1.0f)) { t *= _animation.loops; // new loop? If so, reset frame counter uint loopNumber = (uint)t; if (loopNumber > _executedLoops) { _nextFrame = 0; _executedLoops++; } // new t for animations t = (t % 1.0f); } List <CCAnimationFrame> frames = _animation.frames; uint numberOfFrames = (uint)frames.Count; CCSpriteFrame frameToDisplay = null; for (int i = _nextFrame; i < numberOfFrames; i++) { float splitTime = _splitTimes[i]; if (FloatUtils.ES(splitTime, t)) { CCAnimationFrame frame = frames[i]; frameToDisplay = frame.spriteFrame; ((CCSprite)_target).displayedFrame = frameToDisplay; NSDictionary dict = frame.userInfo; if (dict != null) { // NSNotificationCenter.defaultCenter.postNotification(CCAnimationFrameDisplayedNotification, _target, dict); _nextFrame = i + 1; } } // Issue 1438. Could be more than one frame per tick, due to low frame rate or frame delta < 1/FPS else { break; } } }
public override void update(float t) { // prevents rouding errors if (!FloatUtils.EQ(t, 1) && !FloatUtils.EQ(t, 0)) { t *= 2; if (FloatUtils.Small(t, 1)) { t = 0.5f * Mathf.Pow(2, 10 * (t - 1)); } else { t = 0.5f * (-Mathf.Pow(2, -10 * (t - 1)) + 2); } } _inner.update(t); }
protected float bounceTime(float t) { if (FloatUtils.Small(t, 1 / 2.75f)) { return(7.5625f * t * t); } else if (FloatUtils.Small(t, 2 / 2.75f)) { t -= 1.5f / 2.75f; return(7.5625f * t * t + 0.75f); } else if (FloatUtils.Small(t, 2.5f / 2.75f)) { t -= 2.25f / 2.75f; return(7.5625f * t * t + 0.9375f); } t -= 2.625f / 2.75f; return(7.5625f * t * t + 0.984375f); }
// Needed for BridgeSupport public override void update(float t) { if (FloatUtils.Small(t, 0.5f)) { t = Mathf.Pow(t * _intersetValue, _polynomialOrder); } else { if (_hasInflection) { t = Mathf.Pow((t - 1.0f) * _intersetValue, _polynomialOrder) + 1.0f; } else { t = -Mathf.Pow((t - 1.0f) * _intersetValue, _polynomialOrder) + 1.0f; } } _inner.update(t); }
public override void update(float t) { float newT; // prevents possible rounding errors if (FloatUtils.EQ(t, 0) || FloatUtils.EQ(t, 1)) { newT = t; } else if (FloatUtils.Small(t, 0.5f)) { t = t * 2; newT = (1 - bounceTime(1 - t)) * 0.5f; } else { newT = bounceTime(t * 2 - 1) * 0.5f + 0.5f; } _inner.update(newT); }
public override void update(float t) { int found = 0; float new_t = 0; CCAction action0 = _actions [0]; CCAction action1 = _actions [1]; if (FloatUtils.Small(t, _split)) { // action[0] found = 0; if (!FloatUtils.EQ(_split, 0)) { new_t = t / _split; } else { new_t = 1; } } else { // action[1] found = 1; if (FloatUtils.EQ(_split, 1)) { new_t = 1; } else { new_t = (t - _split) / (1 - _split); } } if (found == 1) { if (_last == -1) { // action[0] was skipped, execute it. action0.startWithTarget(_target); action0.update(1.0f); action0.stop(); } else if (_last == 0) { // switching to action 1. stop action 0. action0.update(1.0f); action0.stop(); } } else if (found == 0 && _last == 1) { // Reverse mode ? // XXX: Bug. this case doesn't contemplate when _last==-1, found=0 and in "reverse mode" // since it will require a hack to know if an action is on reverse mode or not. // "step" should be overriden, and the "reverseMode" value propagated to inner Sequences. action1.update(0); action1.stop(); } // Last action found and it is done. if (found == _last && _actions[found].isDone()) { return; } // New action. Start it. if (found != _last) { _actions[found].startWithTarget(_target); } _actions[found].update(new_t); _last = found; }
public override void ccTouchMoved(UITouch touch) { if (scrollTouch_ != touch) { return; } Vector2 touchPoint = this.convertTouchToNodeSpace(touch); touchPoint = this.convertToWorldSpace(touchPoint); // If finger is dragged for more distance then minimum - start sliding and cancel pressed buttons. // Of course only if we not already in sliding mode if ((state_ != kCCScrollLayerState.Sliding) && (Mathf.Abs(touchPoint.x - startSwipe_) >= this.minimumTouchLengthToSlide)) { state_ = kCCScrollLayerState.Sliding; // Avoid jerk after state change. startSwipe_ = touchPoint.x; if (this.stealTouches) { this.claimTouch(touch); } if (this.delegate_ != null) { this.delegate_.scrollLayerDraging(this); } } if (state_ == kCCScrollLayerState.Sliding) { float desiredX = (-currentScreen_ * (this.contentSize.x - this.pagesWidthOffset)) + touchPoint.x - startSwipe_; int page = this.pageNumberForPosition(new Vector2(desiredX, 0)); float offset = desiredX - this.positionForPageWithNumber(page).x; if ((page == 0 && FloatUtils.Big(offset, 0)) || (page == layers_.Count - 1 && FloatUtils.Small(offset, 0))) { offset -= marginOffset_ * offset / CCDirector.sharedDirector.winSize.x; } else { offset = 0; } this.position = new Vector2(desiredX - offset, 0); } }
public virtual void updateTransform() { if (_isUpdateTransformDirty) { //position // CGAffineTransform tmpAffine = nodeToParentTransform(); // Vector2 pInParent = CGAffineTransform.CGPointApplyAffineTransform(_anchorPointInPixels, tmpAffine); // Vector2 pInUIUnits = ccUtils.PixelsToUnits (pInParent); // transform.localPosition = new Vector3 (pInUIUnits.x, pInUIUnits.y, transform.localPosition.z); // if(_parent!=null && _parent.ignoreAnchorPointForPosition){ // CGAffineTransform tmpAffine = _parent.nodeToWorldTransform (); // Vector2 pInWorld = CGAffineTransform.CGPointApplyAffineTransform (_position, tmpAffine); // Vector2 pInUI = CCDirector.sharedDirector.convertToUI (pInWorld); // Vector2 pInUIUnits = ccUtils.PixelsToUnits (pInUI); // // transform.position = new Vector3 (pInUIUnits.x, pInUIUnits.y, 0); // // Vector3 localPos = transform.localPosition; // localPos.z = -_positionZ / UIWindow.PIXEL_PER_UNIT; // transform.localPosition = localPos; // }else{ // Vector2 pInParentAR = _position; // if(_parent==null) // pInParentAR = CCDirector.sharedDirector.convertToUI(pInParentAR); // else // pInParentAR -= _parent._anchorPointInPixels; // Vector2 pInUIUnits = ccUtils.PixelsToUnits (pInParentAR); // Vector3 pos = transform.localPosition; // pos.x = pInUIUnits.x; // pos.y = pInUIUnits.y; // pos.z = -_positionZ / UIWindow.PIXEL_PER_UNIT; // transform.localPosition = pos; // } Vector2 pInParentAR = _position; if (_parent != null && !_parent.ignoreAnchorPointForPosition) { pInParentAR -= _parent._anchorPointInPixels; } Vector2 pInUIUnits = ccUtils.PixelsToUnits(pInParentAR); Vector3 pos = transform.localPosition; pos.x = pInUIUnits.x; pos.y = pInUIUnits.y; pos.z = 0; transform.localPosition = pos; //rotation Vector3 rotation = transform.localEulerAngles; rotation.x = 0; rotation.z = -_rotation; rotation.y = 0; bool negativeScaleX = FloatUtils.Small(_scaleX, 0); bool negativeScaleY = FloatUtils.Small(_scaleY, 0); if (negativeScaleX && negativeScaleY) { rotation.z = 180 - _rotation; } else if (negativeScaleX) { rotation.y = 180; rotation.z = _rotation; } else if (negativeScaleY) { rotation.y = 180; rotation.z = _rotation + 180; } transform.localEulerAngles = rotation; //scale transform.localScale = new Vector3(Mathf.Abs(_scaleX), Mathf.Abs(_scaleY), transform.localScale.z); _isUpdateTransformDirty = false; } }