Small() public static method

public static Small ( float a, float b ) : bool
a float
b float
return bool
Ejemplo n.º 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;
            }
        }
Ejemplo n.º 2
0
        /** 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;
            }
        }
Ejemplo n.º 3
0
        protected virtual Vector3 calculateRotation()
        {
            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;
            }
            return(rotation);
        }
        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);
        }
Ejemplo n.º 5
0
        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;
        }
Ejemplo n.º 6
0
 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));
 }
Ejemplo n.º 7
0
 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));
     }
 }
Ejemplo n.º 8
0
        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);
            }
        }
Ejemplo n.º 9
0
        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);
        }
Ejemplo n.º 11
0
        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);
        }
Ejemplo n.º 12
0
        // 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);
        }
Ejemplo n.º 13
0
        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 void SendEvent(AnimationEvent evt)
        {
            if (_eventHandler != null)
            {
                AnimatorStateInfo evtInfo  = evt.animatorStateInfo;
                AnimatorStateInfo curInfo  = _animator.GetCurrentAnimatorStateInfo(0);
                AnimatorStateInfo nextInfo = _animator.GetNextAnimatorStateInfo(0);
                bool isInTransition        = _animator.IsInTransition(0);

                //skip previous events
                if (isInTransition)
                {
                    if (evtInfo.fullPathHash != nextInfo.fullPathHash)
                    {
                        return;
                    }

                    //skip previous events when curState == nextStateInfo and real time < evt time.
                    //it might has bug here
                    if (curInfo.fullPathHash == nextInfo.fullPathHash)
                    {
                        float evtSupposedTime = evt.time / evtInfo.length;
                        float evtRealTime     = (evtInfo.normalizedTime) % 1;
                        if (FloatUtils.Small(evtRealTime, evtSupposedTime))
                        {
                            return;
                        }
                    }
                }
                else
                {
                    if (evtInfo.fullPathHash != curInfo.fullPathHash)
                    {
                        return;
                    }
                }

                _eventHandler(evt);
            }
        }
Ejemplo n.º 15
0
        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);
            }
        }
Ejemplo n.º 16
0
        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;
        }
Ejemplo n.º 17
0
        static void CheckSemiTransparentSprite(NSDictionary dictionary, Texture2D texture)
        {
            NSDictionary metadataDict = dictionary.objectForKey <NSDictionary>("metadata");
            NSDictionary framesDict   = dictionary.objectForKey <NSDictionary>("frames");

            // get the format
            int format = 0;

            if (metadataDict != null)
            {
                format = metadataDict.objectForKey <int> ("format");
            }

            // get texture size
            Vector2 textureSize = new Vector2(texture.width, texture.height);

            // check the format
            NSUtils.Assert(format >= 0 && format <= 3, @"cocos2d: WARNING: format is not supported for CCSpriteFrameCache addSpriteFramesWithDictionary:texture:");

            // SpriteFrame info
            Rect rect           = new Rect();
            bool textureRotated = false;

            // add real frames
            var enumerator = framesDict.GetEnumerator();

            while (enumerator.MoveNext())
            {
                KeyValuePair <object, object> frameDictKeyValue = enumerator.Current;
                NSDictionary frameDict = (NSDictionary)frameDictKeyValue.Value;
                if (format == 0)
                {
                    float x  = frameDict.objectForKey <float>("x");
                    float y  = frameDict.objectForKey <float>("y");
                    float w  = frameDict.objectForKey <float>("width");
                    float h  = frameDict.objectForKey <float>("height");
                    int   ow = frameDict.objectForKey <int>("originalWidth");
                    int   oh = frameDict.objectForKey <int>("originalHeight");
                    // check ow/oh
                    if (ow == 0 || oh == 0)
                    {
                        CCDebug.Warning("cocos2d: WARNING: originalWidth/Height not found on the CCSpriteFrame. AnchorPoint won't work as expected. Regenerate the .plist");
                    }

                    // abs ow/oh
                    ow = Math.Abs(ow);
                    oh = Math.Abs(oh);

                    // set frame info
                    rect           = new Rect(x, y, w, h);
                    textureRotated = false;
                }
                else if (format == 1 || format == 2)
                {
                    Rect frame   = ccUtils.RectFromString(frameDict.objectForKey <string>("frame"));
                    bool rotated = false;

                    // rotation
                    if (format == 2)
                    {
                        rotated = frameDict.objectForKey <bool>("rotated");
                    }

                    // set frame info
                    rect           = frame;
                    textureRotated = rotated;
                }
                else if (format == 3)
                {
                    // get values
                    Vector2 spriteSize      = ccUtils.PointFromString(frameDict.objectForKey <string>("spriteSize"));
                    Rect    textureRect     = ccUtils.RectFromString(frameDict.objectForKey <string>("textureRect"));
                    bool    textureRotated_ = frameDict.objectForKey <bool>("textureRotated");


                    // set frame info
                    rect           = new Rect(textureRect.position.x, textureRect.position.y, spriteSize.x, spriteSize.y);
                    textureRotated = textureRotated_;
                }
                if (textureRotated)
                {
                    rect.size = new Vector2(rect.size.y, rect.size.x);
                }
                rect.y = textureSize.y - rect.y - rect.height;

                // add sprite frame
                int  rectX  = Mathf.RoundToInt(rect.xMin);
                int  rectY  = Mathf.RoundToInt(rect.yMin);
                int  rectW  = Mathf.RoundToInt(rect.width);
                int  rectH  = Mathf.RoundToInt(rect.height);
                bool isSemi = false;
                for (int x = 0; x < rectW; x++)
                {
                    for (int y = 0; y < rectH; y++)
                    {
                        Color color = texture.GetPixel(rectX + x, rectY + y);
                        if (FloatUtils.Big(color.a, 0) && FloatUtils.Small(color.a, 1))
                        {
                            isSemi = true;
                            break;
                        }
                    }
                    if (isSemi)
                    {
                        break;
                    }
                }
                frameDict.Add("semi", isSemi);
            }
        }
Ejemplo n.º 18
0
        public override void startWithTarget(object aTarget)
        {
            NSUtils.Assert(aTarget is CC3Node, "CC3Rotate only supports with CC3Node, and target is {0}.", aTarget);
            base.startWithTarget(aTarget);

            //Calculate angle
            CC3Node node = (CC3Node)_target;

            _startAngle = new Vector3(node.rotationX, node.rotationY, node.rotation);

            if (FloatUtils.Big(_startAngle.x, 0))
            {
                _startAngle.x = _startAngle.x % 360.0f;
            }
            else
            {
                _startAngle.x = _startAngle.x % -360.0f;
            }

            if (FloatUtils.Big(_startAngle.y, 0))
            {
                _startAngle.y = _startAngle.y % 360.0f;
            }
            else
            {
                _startAngle.y = _startAngle.y % -360.0f;
            }

            if (FloatUtils.Big(_startAngle.z, 0))
            {
                _startAngle.z = _startAngle.z % 360.0f;
            }
            else
            {
                _startAngle.z = _startAngle.z % -360.0f;
            }



            _diffAngle = _dstAngle - _startAngle;
            if (FloatUtils.Big(_diffAngle.x, 180))
            {
                _diffAngle.x -= 360;
            }
            if (FloatUtils.Small(_diffAngle.x, -180))
            {
                _diffAngle.x += 360;
            }

            if (FloatUtils.Big(_diffAngle.y, 180))
            {
                _diffAngle.y -= 360;
            }
            if (FloatUtils.Small(_diffAngle.y, -180))
            {
                _diffAngle.y += 360;
            }

            if (FloatUtils.Big(_diffAngle.z, 180))
            {
                _diffAngle.z -= 360;
            }
            if (FloatUtils.Small(_diffAngle.z, -180))
            {
                _diffAngle.z += 360;
            }
        }