Пример #1
0
        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;
            }
        }
Пример #2
0
 protected void setupTimer(float interval, uint repeat, float delay)
 {
     _elapsed    = -1;
     _interval   = interval;
     _delay      = delay;
     _useDelay   = FloatUtils.Big(_delay, 0);
     _repeat     = repeat;
     _runForever = _repeat == CCScheduler.kCCRepeatForever;
 }
Пример #3
0
 public override void update(float t)
 {
     if (!this.isDone())
     {
         float slice = 1.0f / _times;
         float m     = t % slice;
         (_target as CCNode).visible = FloatUtils.Big(m, slice / 2);
     }
 }
Пример #4
0
 /** triggers the timer */
 public void update(float dt)
 {
     if (FloatUtils.EQ(_elapsed, -1))
     {
         _elapsed        = 0;
         _nTimesExecuted = 0;
     }
     else
     {
         if (_runForever && !_useDelay)
         {
             //standard timer usage
             _elapsed += dt;
             if (FloatUtils.EB(_elapsed, _interval))
             {
                 trigger();
                 _elapsed = 0;
             }
         }
         else
         {
             //advanced usage
             _elapsed += dt;
             if (_useDelay)
             {
                 if (FloatUtils.EB(_elapsed, _delay))
                 {
                     trigger();
                     _elapsed         = _elapsed - _delay;
                     _nTimesExecuted += 1;
                     _useDelay        = false;
                 }
             }
             else
             {
                 if (FloatUtils.EB(_elapsed, _interval))
                 {
                     trigger();
                     _elapsed         = 0;
                     _nTimesExecuted += 1;
                 }
             }
             if (!_runForever && FloatUtils.Big(_nTimesExecuted, _repeat))
             {
                 cancel();
             }
         }
     }
 }
        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);
            }
        }
Пример #6
0
 void showState()
 {
     if (_displayStats)
     {
         _frames++;
         _accumDt += _dt;
         if (FloatUtils.Big(_accumDt, ccConfig.CC_DIRECTOR_STATS_INTERVAL))
         {
             _frameRate = _frames / _accumDt;
             _frames    = 0;
             _accumDt   = 0;
         }
         _ccNumberOfDrawsToShow = _ccNumberOfDraws;
     }
     _ccNumberOfDraws = 0;
 }
Пример #7
0
        // issue #80. Instead of hooking step:, hook update: since it can be called by any
        // container action like CCRepeat, CCSequence, CCEase, etc..
        public override void update(float dt)
        {
            if (FloatUtils.EB(dt, _nextDt))
            {
                while (FloatUtils.Big(dt, _nextDt) && _total < _times)
                {
                    _innerAction.update(1.0f);
                    _total++;

                    _innerAction.stop();
                    _innerAction.startWithTarget(_target);
                    _nextDt += _innerAction.duration / _duration;
                }

                // fix for issue #1288, incorrect end value of repeat
                if (FloatUtils.EB(dt, 1.0f) && _total < _times)
                {
                    _total++;
                }

                // don't set a instantaction back or update it, it has no use because it has no duration
                if (!_isActionInstant)
                {
                    if (_total == _times)
                    {
                        _innerAction.update(1);
                        _innerAction.stop();
                    }
                    else
                    {
                        // issue #390 prevent jerk, use right update
                        _innerAction.update(dt - (_nextDt - _innerAction.duration / _duration));
                    }
                }
            }
            else
            {
                _innerAction.update((dt * _times) % 1.0f);
            }
        }
Пример #8
0
        public void initWithAction(CCActionFiniteTime one, CCActionFiniteTime two)
        {
            NSUtils.Assert(one != null && two != null, "Sequence: arguments must be non-nil");
            NSUtils.Assert(one != _one && one != _two, "Spawn: reinit using same parameters is not supported");
            NSUtils.Assert(two != _two && two != _one, "Spawn: reinit using same parameters is not supported");

            float d1 = one.duration;
            float d2 = two.duration;

            base.initWithDuration(Mathf.Max(d1, d2));
            _one = one;
            _two = two;

            if (FloatUtils.Big(d1, d2))
            {
                _two = CCSequence.Actions(two, new CCDelayTime(d1 - d2));
            }
            else if (d1 < d2)
            {
                _one = CCSequence.Actions(one, new CCDelayTime(d2 - d1));
            }
        }
Пример #9
0
        // Helper
        protected bool updateTexture()
        {
            if (FloatUtils.EQ(_dimensions.x, 0) || FloatUtils.EQ(_dimensions.y, 0))
            {
                _content.mesh.text = _text;
                Bounds  localBounds = getLocalbounds();
                Vector2 textSize    = ccUtils.UnitsToPixels(localBounds.size);
                this.contentSize = textSize;
            }
            else
            {
                string finalText         = "";
                string originalText      = _text;
                int    preEmptyCharIndex = -1;
                for (int i = 1; i <= originalText.Length; i++)
                {
                    char c = originalText[i - 1];
                    if (char.IsWhiteSpace(c))
                    {
                        preEmptyCharIndex = i - 1;
                    }
                    string tmpStr = originalText.Substring(0, i);
                    if (c == '\n')
                    {
                        finalText   += tmpStr;
                        originalText = originalText.Substring(i);
                        i            = 0;
                    }

                    _content.mesh.text = tmpStr;
                    Bounds  localBounds = getLocalbounds();
                    Vector2 csize       = ccUtils.UnitsToPixels(localBounds.size);
                    if (FloatUtils.Big(csize.x, _dimensions.x))
                    {
                        if (preEmptyCharIndex == -1)
                        {
                            tmpStr = originalText.Substring(0, i);
                        }
                        else
                        {
                            tmpStr            = originalText.Substring(0, preEmptyCharIndex);
                            i                 = preEmptyCharIndex + 1;
                            preEmptyCharIndex = -1;
                        }
                        finalText += tmpStr;
                        if (i < originalText.Length)
                        {
                            finalText   += "\n";
                            originalText = originalText.Substring(i);
                            i            = 0;
                        }
                    }
                    else if (i == originalText.Length)
                    {
                        tmpStr     = originalText.Substring(0, i);
                        finalText += tmpStr;
                        break;
                    }

//					string tmpStr = originalText.Substring(0, i);
//					_content.mesh.text = tmpStr;
//					Vector2 csize = _content.renderer.bounds.size;
//					csize = ccUtils.UnitsToPixels(csize);
//					if(FloatUtils.Small(csize.x , _dimensions.x) || i==1){
//						tmpStr = originalText.Substring(0, i);
//						finalText += tmpStr;
//						if(i<originalText.Length){
//							finalText += "\n";
//							originalText = originalText.Substring(i);
//							i = originalText.Length+1;
//						}else{
//							break;
//						}
//					}
                }
                _content.mesh.text = finalText;
                this.contentSize   = _dimensions;
            }
            _isContentDirty = true;

            return(true);
        }