Esempio n. 1
0
        public static void DrawRect(CCRect rect, CCColor4B color)
        {
            float x1 = rect.MinX;
            float y1 = rect.MinY;
            float x2 = rect.MaxX;
            float y2 = rect.MaxY;

            DrawLine(new CCPoint(x1, y1), new CCPoint(x2, y1), color);
            DrawLine(new CCPoint(x2, y1), new CCPoint(x2, y2), color);
            DrawLine(new CCPoint(x2, y2), new CCPoint(x1, y2), color);
            DrawLine(new CCPoint(x1, y2), new CCPoint(x1, y1), color);
        }
Esempio n. 2
0
        private bool InitWithTarget(CCNode pFollowedNode, CCRect rect)
        {
            Debug.Assert(pFollowedNode != null);

            m_pobFollowedNode = pFollowedNode;
            if (rect.Equals(CCRect.Zero))
            {
                m_bBoundarySet = false;
            }
            else
            {
                m_bBoundarySet = true;
            }

            m_bBoundaryFullyCovered = false;

            CCSize winSize = CCDirector.SharedDirector.WinSize;
            m_obFullScreenSize = (CCPoint)winSize;
            m_obHalfScreenSize = m_obFullScreenSize * 0.5f;

            if (m_bBoundarySet)
            {
                m_fLeftBoundary = -((rect.Origin.X + rect.Size.Width) - m_obFullScreenSize.X);
                m_fRightBoundary = -rect.Origin.X;
                m_fTopBoundary = -rect.Origin.Y;
                m_fBottomBoundary = -((rect.Origin.Y + rect.Size.Height) - m_obFullScreenSize.Y);

                if (m_fRightBoundary < m_fLeftBoundary)
                {
                    // screen width is larger than world's boundary width
                    //set both in the middle of the world
                    m_fRightBoundary = m_fLeftBoundary = (m_fLeftBoundary + m_fRightBoundary) / 2;
                }
                if (m_fTopBoundary < m_fBottomBoundary)
                {
                    // screen width is larger than world's boundary width
                    //set both in the middle of the world
                    m_fTopBoundary = m_fBottomBoundary = (m_fTopBoundary + m_fBottomBoundary) / 2;
                }

                if ((m_fTopBoundary == m_fBottomBoundary) && (m_fLeftBoundary == m_fRightBoundary))
                {
                    m_bBoundaryFullyCovered = true;
                }
            }

            return true;
        }
        public static CCRect CCRectApplyAffineTransform(CCRect rect, CCAffineTransform anAffineTransform)
        {
            float top = CCRect.CCRectGetMinY(rect);
            float left = CCRect.CCRectGetMinX(rect);
            float right = CCRect.CCRectGetMaxX(rect);
            float bottom = CCRect.CCRectGetMaxY(rect);

            CCPoint topLeft = CCPointApplyAffineTransform(new CCPoint(left, top), anAffineTransform);
            CCPoint topRight = CCPointApplyAffineTransform(new CCPoint(right, top), anAffineTransform);
            CCPoint bottomLeft = CCPointApplyAffineTransform(new CCPoint(left, bottom), anAffineTransform);
            CCPoint bottomRight = CCPointApplyAffineTransform(new CCPoint(right, bottom), anAffineTransform);

            float minX = Math.Min(Math.Min(topLeft.X, topRight.X), Math.Min(bottomLeft.X, bottomRight.X));
            float maxX = Math.Max(Math.Max(topLeft.X, topRight.X), Math.Max(bottomLeft.X, bottomRight.X));
            float minY = Math.Min(Math.Min(topLeft.Y, topRight.Y), Math.Min(bottomLeft.Y, bottomRight.Y));
            float maxY = Math.Max(Math.Max(topLeft.Y, topRight.Y), Math.Max(bottomLeft.Y, bottomRight.Y));

            return new CCRect(minX, minY, (maxX - minX), (maxY - minY));
        }
        public void Is_ContainsPoint_Robust()
        {
            CCRect vpRect = new CCRect(5.0f, -5.0f, 15.0f, 20.0f);
            CCSize vpSize = vpRect.Size;
            CC3Viewport vp = new CC3Viewport(vpRect);

            // General sanity test
            Assert.IsTrue(vp.ContainsPoint(vpRect.Origin + new CCPoint(vpSize.Width / 2.0f, vpSize.Height / 2.0f)));

            // Checking corners of viewport
            Assert.IsTrue(vp.ContainsPoint(vpRect.Origin));
            Assert.IsTrue(vp.ContainsPoint(vpRect.Origin + new CCPoint(vpSize.Width, 0.0f)));
            Assert.IsTrue(vp.ContainsPoint(vpRect.Origin + new CCPoint(0.0f, vpSize.Height)));
            Assert.IsTrue(vp.ContainsPoint(vpRect.Origin + new CCPoint(vpSize.Width, vpSize.Height)));

            // Test sensitivity to decimal changes in coordinates
            // Floats are cast as ints in viewport fields
            Assert.IsFalse(vp.ContainsPoint(vpRect.Origin + new CCPoint(-0.1f, 0.0f)));
            Assert.IsTrue(vp.ContainsPoint(vpRect.Origin + new CCPoint(0.1f, 0.0f)));
        }
Esempio n. 5
0
		 void InitCloud () {
			
			CCRect rect;
			switch(ran.Next()%3) {
			case 0:
                    rect = new CCRect(336, 16, 256, 108); 
				break;
			case 1:
                rect = new CCRect(336, 128, 257, 110); 
				break;
			default:
                rect = new CCRect(336, 240, 252, 119); 
				break;
			}	

			var batchNode = GetChildByTag((int)Tags.SpriteManager) as CCSpriteBatchNode;
			var cloud = new CCSprite(batchNode.Texture, rect);
			batchNode.AddChild(cloud,3,currentCloudTag);

			cloud.Opacity = 128;
		}
 public CCScale9SpriteFrame(CCSpriteFrame spriteFrame, CCRect capInsets)
 {
     InitWithSpriteFrame(spriteFrame, capInsets);
 }
Esempio n. 7
0
 public bool Equals(CCRect rect)
 {
     return Origin.Equals(rect.Origin) && Size.Equals(rect.Size);
 }
Esempio n. 8
0
        private CCSprite ReusedTileWithRect(CCRect rect)
        {
            if (m_pReusedTile == null)
            {
                m_pReusedTile = new CCSprite();
                m_pReusedTile.InitWithTexture(m_pobTextureAtlas.Texture, rect, false);
                m_pReusedTile.BatchNode = this;
            }
            else
            {
                // XXX HACK: Needed because if "batch node" is nil,
                // then the Sprite'squad will be reset
                m_pReusedTile.BatchNode = null;

                // Re-init the sprite
                m_pReusedTile.SetTextureRect(rect, false, rect.Size);

                // restore the batch node
                m_pReusedTile.BatchNode = this;
            }

            return m_pReusedTile;
        }
Esempio n. 9
0
        private void BeforeDraw()
        {
            m_bNoDrawChildren = false;

            if (m_childClippingMode == CCClipMode.Bounds)
            {
                // We always clip to the bounding box
                var rect = new CCRect(0, 0, m_tContentSize.Width, m_tContentSize.Height);
                var bounds = CCAffineTransform.Transform(rect, NodeToWorldTransform());

                var winSize = CCDirector.SharedDirector.WinSize;

                CCRect prevScissorRect;
                if (CCDrawManager.ScissorRectEnabled)
                {
                    prevScissorRect = CCDrawManager.ScissorRect;
                }
                else
                {
                    prevScissorRect = new CCRect(0, 0, winSize.Width, winSize.Height);
                }

                if (!bounds.IntersectsRect(prevScissorRect))
                {
                    m_bNoDrawChildren = true;
                    return;
                }

                float minX = Math.Max(bounds.MinX, prevScissorRect.MinX);
                float minY = Math.Max(bounds.MinY, prevScissorRect.MinY);
                float maxX = Math.Min(bounds.MaxX, prevScissorRect.MaxX);
                float maxY = Math.Min(bounds.MaxY, prevScissorRect.MaxY);
              
                if (CCDrawManager.ScissorRectEnabled)
                {
                    m_bRestoreScissor = true;
                }
                else
                {
                    CCDrawManager.ScissorRectEnabled = true;
                }

                m_tSaveScissorRect = prevScissorRect;

                CCDrawManager.SetScissorInPoints(minX, minY, maxX - minX, maxY - minY);
            }
            else if (m_childClippingMode == CCClipMode.BoundsWithRenderTarget)
            {
                m_tSaveScissorRect = CCDrawManager.ScissorRect;
                m_bRestoreScissor = CCDrawManager.ScissorRectEnabled;

                CCDrawManager.ScissorRectEnabled = false;

                CCDrawManager.PushMatrix();
                CCDrawManager.SetIdentityMatrix();

                m_pRenderTexture.BeginWithClear(0, 0, 0, 0);
            }
        }
Esempio n. 10
0
 public CCMaskedSprite(CCTexture2D texture, CCRect rect, byte[] mask)
     : base(texture, rect)
 {
     _MyMask = mask;
 }
Esempio n. 11
0
        private CCSprite ReusedTileWithRect(CCRect rect)
        {
            if (m_pReusedTile == null)
            {
                m_pReusedTile = new CCSprite();
                m_pReusedTile.InitWithTexture(m_pobTextureAtlas.Texture, rect, false);
                m_pReusedTile.BatchNode = this;
            }
            else
            {
                // XXX: should not be re-init. Potential memeory leak. Not following best practices
                // XXX: it shall call directory  [setRect:rect]
                m_pReusedTile.InitWithTexture(m_pobTextureAtlas.Texture, rect, false);

                // Since initWithTexture resets the batchNode, we need to re add it.
                // but should be removed once initWithTexture is not called again
                m_pReusedTile.BatchNode = this;
            }

            return m_pReusedTile;
        }
Esempio n. 12
0
        public void AddSpriteFramesWithDictionary(PlistDictionary pobDictionary, CCTexture2D pobTexture, string framePrefix)
        {
            /*
             * Supported Zwoptex Formats:
             *
             * ZWTCoordinatesFormatOptionXMLLegacy = 0, // Flash Version
             * ZWTCoordinatesFormatOptionXML1_0 = 1, // Desktop Version 0.0 - 0.4b
             * ZWTCoordinatesFormatOptionXML1_1 = 2, // Desktop Version 1.0.0 - 1.0.1
             * ZWTCoordinatesFormatOptionXML1_2 = 3, // Desktop Version 1.0.2+
             */

            PlistDictionary metadataDict = null;

            if (pobDictionary.ContainsKey("metadata"))
            {
                metadataDict = pobDictionary["metadata"].AsDictionary;
            }

            PlistDictionary framesDict = null;

            if (pobDictionary.ContainsKey("frames"))
            {
                framesDict = pobDictionary["frames"].AsDictionary;
            }

            int format = 0;

            // get the format
            if (metadataDict != null)
            {
                format = metadataDict["format"].AsInt;
            }

            // check the format
            if (format < 0 || format > 3)
            {
                throw (new NotSupportedException("PList format " + format + " is not supported."));
            }

            foreach (var pair in framesDict)
            {
                PlistDictionary frameDict   = pair.Value.AsDictionary;
                CCSpriteFrame   spriteFrame = null;

                if (format == 0)
                {
                    float x = 0f, y = 0f, w = 0f, h = 0f;
                    x = frameDict["x"].AsFloat;
                    y = frameDict["y"].AsFloat;
                    w = frameDict["width"].AsFloat;
                    h = frameDict["height"].AsFloat;
                    float ox = 0f, oy = 0f;
                    ox = frameDict["offsetX"].AsFloat;
                    oy = frameDict["offsetY"].AsFloat;
                    int ow = 0, oh = 0;
                    ow = frameDict["originalWidth"].AsInt;
                    oh = frameDict["originalHeight"].AsInt;
                    // check ow/oh
                    if (ow == 0 || oh == 0)
                    {
                        CCLog.Log(
                            "cocos2d: WARNING: originalWidth/Height not found on the CCSpriteFrame. AnchorPoint won't work as expected. Regenerate the .plist or check the 'format' metatag");
                    }
                    // abs ow/oh
                    ow = Math.Abs(ow);
                    oh = Math.Abs(oh);
                    // create frame
                    spriteFrame = new CCSpriteFrame(pobTexture,
                                                    new CCRect(x, y, w, h),
                                                    false,
                                                    new CCPoint(ox, oy),
                                                    new CCSize(ow, oh)
                                                    );
                }
                else if (format == 1 || format == 2)
                {
                    CCRect frame   = CCRect.Parse(frameDict["frame"].AsString);
                    bool   rotated = false;

                    // rotation
                    if (format == 2)
                    {
                        if (frameDict.ContainsKey("rotated"))
                        {
                            rotated = frameDict["rotated"].AsBool;
                        }
                    }

                    CCPoint offset     = CCPoint.Parse(frameDict["offset"].AsString);
                    CCSize  sourceSize = CCSize.Parse(frameDict["sourceSize"].AsString);

                    // create frame
                    spriteFrame = new CCSpriteFrame(pobTexture,
                                                    frame,
                                                    rotated,
                                                    offset,
                                                    sourceSize
                                                    );
                }
                else if (format == 3)
                {
                    // get values
                    CCSize  spriteSize       = CCSize.Parse(frameDict["spriteSize"].AsString);
                    CCPoint spriteOffset     = CCPoint.Parse(frameDict["spriteOffset"].AsString);
                    CCSize  spriteSourceSize = CCSize.Parse(frameDict["spriteSourceSize"].AsString);
                    CCRect  textureRect      = CCRect.Parse(frameDict["textureRect"].AsString);
                    bool    textureRotated   = false;
                    if (frameDict.ContainsKey("textureRotated"))
                    {
                        textureRotated = frameDict["textureRotated"].AsBool;
                    }

                    // get aliases
                    PlistArray aliases  = frameDict["aliases"].AsArray;
                    string     frameKey = pair.Key;

                    foreach (PlistObjectBase item2 in aliases)
                    {
                        string oneAlias = item2.AsString;
                        if (m_pSpriteFramesAliases.Keys.Contains(oneAlias))
                        {
                            if (m_pSpriteFramesAliases[oneAlias] != null)
                            {
                                CCLog.Log("cocos2d: WARNING: an alias with name {0} already exists", oneAlias);
                            }
                        }
                        if (!m_pSpriteFramesAliases.Keys.Contains(oneAlias))
                        {
                            m_pSpriteFramesAliases.Add(oneAlias, frameKey);
                        }
                    }

                    // create frame
                    spriteFrame = new CCSpriteFrame(pobTexture,
                                                    new CCRect(textureRect.Origin.X, textureRect.Origin.Y, spriteSize.Width, spriteSize.Height),
                                                    textureRotated,
                                                    spriteOffset,
                                                    spriteSourceSize);
                }

                // add sprite frame
                string key = framePrefix + pair.Key;
                if (!_AllowFrameOverwrite && m_pSpriteFrames.ContainsKey(key))
                {
                    CCLog.Log("Frame named " + key + " already exists in the animation cache. Not overwriting existing record.");
                }
                else if (_AllowFrameOverwrite || !m_pSpriteFrames.ContainsKey(key))
                {
                    m_pSpriteFrames[key] = spriteFrame;
                }
            }
        }
Esempio n. 13
0
        private void LoadCocos2DDictionary(PlistDictionary dict, CCTexture2D texture)
        {
            PlistDictionary metadataDict = null;

            if (dict.ContainsKey("metadata"))
            {
                metadataDict = dict["metadata"].AsDictionary;
            }

            PlistDictionary framesDict = null;

            if (dict.ContainsKey("frames"))
            {
                framesDict = dict["frames"].AsDictionary;
            }

            // get the format
            int format = 0;

            if (metadataDict != null)
            {
                format = metadataDict["format"].AsInt;
            }

            // check the format
            if (format < 0 || format > 3)
            {
                throw (new NotSupportedException("PList format " + format + " is not supported."));
            }

            foreach (var pair in framesDict)
            {
                PlistDictionary frameDict   = pair.Value.AsDictionary;
                CCSpriteFrame   spriteFrame = null;

                if (format == 0)
                {
                    float x = 0f, y = 0f, w = 0f, h = 0f;
                    x = frameDict["x"].AsFloat;
                    y = frameDict["y"].AsFloat;
                    w = frameDict["width"].AsFloat;
                    h = frameDict["height"].AsFloat;
                    float ox = 0f, oy = 0f;
                    ox = frameDict["offsetX"].AsFloat;
                    oy = frameDict["offsetY"].AsFloat;
                    int ow = 0, oh = 0;
                    ow = frameDict["originalWidth"].AsInt;
                    oh = frameDict["originalHeight"].AsInt;
                    // check ow/oh
                    if (ow == 0 || oh == 0)
                    {
                        CCLog.Log(
                            "cocos2d: WARNING: originalWidth/Height not found on the CCSpriteFrame. AnchorPoint won't work as expected. Regenerate the .plist or check the 'format' metatag");
                    }
                    // abs ow/oh
                    ow = Math.Abs(ow);
                    oh = Math.Abs(oh);

                    // create frame
                    spriteFrame = new CCSpriteFrame(
                        texture,
                        new CCRect(x, y, w, h),
                        false,
                        new CCPoint(ox, oy),
                        new CCSize(ow, oh)
                        );
                }
                else if (format == 1 || format == 2)
                {
                    var  frame   = CCRect.Parse(frameDict["frame"].AsString);
                    bool rotated = false;

                    // rotation
                    if (format == 2)
                    {
                        if (frameDict.ContainsKey("rotated"))
                        {
                            rotated = frameDict["rotated"].AsBool;
                        }
                    }

                    var offset     = CCPoint.Parse(frameDict["offset"].AsString);
                    var sourceSize = CCSize.Parse(frameDict["sourceSize"].AsString);

                    // create frame
                    spriteFrame = new CCSpriteFrame(texture, frame, rotated, offset, sourceSize);
                }
                else if (format == 3)
                {
                    var spriteSize       = CCSize.Parse(frameDict["spriteSize"].AsString);
                    var spriteOffset     = CCPoint.Parse(frameDict["spriteOffset"].AsString);
                    var spriteSourceSize = CCSize.Parse(frameDict["spriteSourceSize"].AsString);
                    var textureRect      = CCRect.Parse(frameDict["textureRect"].AsString);

                    bool textureRotated = false;

                    if (frameDict.ContainsKey("textureRotated"))
                    {
                        textureRotated = frameDict["textureRotated"].AsBool;
                    }

                    // get aliases
                    var aliases = frameDict["aliases"].AsArray;

                    for (int i = 0; i < aliases.Count; i++)
                    {
                        string oneAlias = aliases[i].AsString;

                        if (_spriteFramesAliases.ContainsKey(oneAlias))
                        {
                            if (_spriteFramesAliases[oneAlias] != null)
                            {
                                CCLog.Log("cocos2d: WARNING: an alias with name {0} already exists", oneAlias);
                            }
                        }

                        if (!_spriteFramesAliases.ContainsKey(oneAlias))
                        {
                            _spriteFramesAliases.Add(oneAlias, pair.Key);
                        }
                    }

                    // create frame
                    spriteFrame = new CCSpriteFrame(
                        texture,
                        new CCRect(textureRect.Origin.X, textureRect.Origin.Y, spriteSize.Width, spriteSize.Height),
                        textureRotated,
                        spriteOffset,
                        spriteSourceSize
                        );
                }

                _spriteFrames[pair.Key] = spriteFrame;
            }
        }
Esempio n. 14
0
        private void LoadAppleDictionary(PlistDictionary dict, CCTexture2D texture)
        {
            var version = dict.ContainsKey("version") ? dict ["version"].AsInt : 0;

            if (version != 1)
            {
                throw (new NotSupportedException("Binary PList version " + version + " is not supported."));
            }


            var images = dict.ContainsKey("images") ? dict ["images"].AsArray : null;

            foreach (var imageEntry in images)
            {
                // we only support one image for now
                var imageDict = imageEntry.AsDictionary;

                var path = imageDict ["path"].AsString;

                path = Path.Combine(plistFilePath, CCFileUtils.RemoveExtension(path));

                if (!CCTextureCache.SharedTextureCache.Contains(path))
                {
                    texture = CCTextureCache.SharedTextureCache.AddImage(path);
                }
                else
                {
                    texture = CCTextureCache.SharedTextureCache[path];
                }



                // size not used right now
                //var size = CCSize.Parse(imageDict ["size"].AsString);

                var subImages = imageDict ["subimages"].AsArray;

                foreach (var subImage in subImages)
                {
                    CCSpriteFrame spriteFrame = null;

                    var subImageDict  = subImage.AsDictionary;
                    var name          = subImageDict ["name"].AsString;
                    var alias         = subImageDict ["alias"].AsString;
                    var isFullyOpaque = true;

                    if (subImageDict.ContainsKey("isFullyOpaque"))
                    {
                        isFullyOpaque = subImageDict ["isFullyOpaque"].AsBool;
                    }

                    var textureRect  = CCRect.Parse(subImageDict ["textureRect"].AsString);
                    var spriteOffset = CCPoint.Parse(subImageDict ["spriteOffset"].AsString);

                    // We are going to override the sprite offset for now to be 0,0
                    // It seems the offset is calculated off of the original size but if
                    // we pass this offset it throws our center position calculations off.
                    spriteOffset = CCPoint.Zero;

                    var textureRotated = false;
                    if (subImageDict.ContainsKey("textureRotated"))
                    {
                        textureRotated = subImageDict ["textureRotated"].AsBool;
                    }
                    var spriteSourceSize = CCSize.Parse(subImageDict ["spriteSourceSize"].AsString);
                    var frameRect        = textureRect;
                    if (textureRotated)
                    {
                        frameRect = new CCRect(textureRect.Origin.X, textureRect.Origin.Y, textureRect.Size.Height, textureRect.Size.Width);
                    }

#if DEBUG
                    CCLog.Log("texture {0} rect {1} rotated {2} offset {3}, sourcesize {4}", name, textureRect, textureRotated, spriteOffset, spriteSourceSize);
#endif

                    // create frame
                    spriteFrame = new CCSpriteFrame(
                        texture,
                        frameRect,
                        textureRotated,
                        spriteOffset,
                        spriteSourceSize
                        );


                    _spriteFrames [name] = spriteFrame;
                }
            }
        }
Esempio n. 15
0
        private void LoadAppleDictionary(PlistDictionary dict, CCTexture2D texture)
        {
            var version = dict.ContainsKey("version") ? dict ["version"].AsInt : 0;

            if (version != 1)
            {
                throw (new NotSupportedException("Binary PList version " + version + " is not supported."));
            }


            var images = dict.ContainsKey("images") ? dict ["images"].AsArray : null;


            // we only support one image for now
            var imageDict = images [0].AsDictionary;

            var path = imageDict ["path"].AsString;

            // size not used right now
            //var size = CCSize.Parse(imageDict ["size"].AsString);

            var subImages = imageDict ["subimages"].AsArray;

            foreach (var subImage in subImages)
            {
                CCSpriteFrame spriteFrame = null;

                var subImageDict  = subImage.AsDictionary;
                var name          = subImageDict ["name"].AsString;
                var alias         = subImageDict ["alias"].AsString;
                var isFullyOpaque = true;

                if (subImageDict.ContainsKey("isFullyOpaque"))
                {
                    isFullyOpaque = subImageDict ["isFullyOpaque"].AsBool;
                }

                var textureRect  = CCRect.Parse(subImageDict ["textureRect"].AsString);
                var spriteOffset = CCPoint.Parse(subImageDict ["spriteOffset"].AsString);

                var textureRotated = false;
                if (subImageDict.ContainsKey("textureRotated"))
                {
                    textureRotated = subImageDict ["textureRotated"].AsBool;
                }
                var spriteSourceSize = CCSize.Parse(subImageDict ["spriteSourceSize"].AsString);
                var frameRect        = textureRect;
                if (textureRotated)
                {
                    frameRect = new CCRect(textureRect.Origin.X, textureRect.Origin.Y, textureRect.Size.Height, textureRect.Size.Width);
                }

#if DEBUG
                CCLog.Log("texture {0} rect {1} rotated {2} offset {3}, sourcesize {4}", name, textureRect, textureRotated, spriteOffset, spriteSourceSize);
#endif

                // create frame
                spriteFrame = new CCSpriteFrame(
                    texture,
                    frameRect,
                    textureRotated,
                    spriteOffset,
                    spriteSourceSize
                    );


                _spriteFrames[name] = spriteFrame;
            }
        }
Esempio n. 16
0
        private CCBKeyframe ReadKeyframe(CCBPropType type)
        {
            var keyframe = new CCBKeyframe();

            keyframe.Time = ReadFloat();

            var    easingType = (CCBKeyframeEasing)ReadInt(false);
            float  easingOpt  = 0;
            object value      = null;

            if (easingType == CCBKeyframeEasing.CubicIn ||
                easingType == CCBKeyframeEasing.CubicOut ||
                easingType == CCBKeyframeEasing.CubicInOut ||
                easingType == CCBKeyframeEasing.ElasticIn ||
                easingType == CCBKeyframeEasing.ElasticOut ||
                easingType == CCBKeyframeEasing.ElasticInOut)
            {
                easingOpt = ReadFloat();
            }
            keyframe.EasingType = easingType;
            keyframe.EasingOpt  = easingOpt;

            if (type == CCBPropType.Check)
            {
                value = new CCBValue(ReadBool());
            }
            else if (type == CCBPropType.Byte)
            {
                value = new CCBValue(ReadByte());
            }
            else if (type == CCBPropType.Color3)
            {
                byte r = ReadByte();
                byte g = ReadByte();
                byte b = ReadByte();

                var c = new CCColor3B(r, g, b);
                value = new CCColor3BWapper(c);
            }
            else if (type == CCBPropType.Degrees)
            {
                value = new CCBValue(ReadFloat());
            }
            else if (type == CCBPropType.ScaleLock || type == CCBPropType.Position)
            {
                float a = ReadFloat();
                float b = ReadFloat();

                value = new List <CCBValue>
                {
                    new CCBValue(a),
                    new CCBValue(b)
                };
            }
            else if (type == CCBPropType.SpriteFrame)
            {
                string spriteSheet = ReadCachedString();
                string spriteFile  = ReadCachedString();

                CCSpriteFrame spriteFrame;

                if (String.IsNullOrEmpty(spriteSheet))
                {
                    CCTexture2D texture = CCTextureCache.SharedTextureCache.AddImage(CCFileUtils.RemoveExtension(spriteFile));
                    var         bounds  = new CCRect(0, 0, texture.ContentSize.Width, texture.ContentSize.Height);
                    spriteFrame = new CCSpriteFrame(texture, bounds);
                }
                else
                {
                    CCSpriteFrameCache frameCache = CCSpriteFrameCache.SharedSpriteFrameCache;

                    // Load the sprite sheet only if it is not loaded
                    if (!mLoadedSpriteSheets.Contains(spriteSheet))
                    {
                        frameCache.AddSpriteFramesWithFile(spriteSheet);
                        mLoadedSpriteSheets.Add(spriteSheet);
                    }

                    spriteFrame = frameCache.SpriteFrameByName(spriteFile);
                }
                value = spriteFrame;
            }

            keyframe.Value = value;

            return(keyframe);
        }
Esempio n. 17
0
 public CCScale9SpriteFile(string file, CCRect rect, CCRect capInsets)
 {
     InitWithFile(file, rect, capInsets);
 }
Esempio n. 18
0
 public CCScale9SpriteFile(CCRect capInsets, string file)
 {
     InitWithFile(capInsets, file);
 }
Esempio n. 19
0
 public CCScale9SpriteFile(string file, CCRect rect)
 {
     InitWithFile(file, rect);
 }
Esempio n. 20
0
        private CCBKeyframe ReadKeyframe(CCBPropertyType type)
        {
            var keyframe = new CCBKeyframe();

            keyframe.Time = ReadFloat();

            var easingType = (CCBEasingType) ReadInt(false);
            float easingOpt = 0;
            object value = null;

            if (easingType == CCBEasingType.CubicIn
                || easingType == CCBEasingType.CubicOut
                || easingType == CCBEasingType.CubicInOut
                || easingType == CCBEasingType.ElasticIn
                || easingType == CCBEasingType.ElasticOut
                || easingType == CCBEasingType.ElasticInOut)
            {
                easingOpt = ReadFloat();
            }
            keyframe.EasingType = easingType;
            keyframe.EasingOpt = easingOpt;

            if (type == CCBPropertyType.Check)
            {
                value = new CCBValue(ReadBool());
            }
            else if (type == CCBPropertyType.Byte)
            {
                value = new CCBValue(ReadByte());
            }
            else if (type == CCBPropertyType.Color3)
            {
                byte r = ReadByte();
                byte g = ReadByte();
                byte b = ReadByte();

                var c = new CCColor3B(r, g, b);
                value = new CCColor3BWapper(c);
            }
            else if (type == CCBPropertyType.Degrees)
            {
                value = new CCBValue(ReadFloat());
            }
            else if (type == CCBPropertyType.ScaleLock || type == CCBPropertyType.Position || type == CCBPropertyType.FloatXY)
            {
                float a = ReadFloat();
                float b = ReadFloat();

                value = new List<CCBValue>
                    {
                        new CCBValue(a),
                        new CCBValue(b)
                    };
            }
            else if (type == CCBPropertyType.SpriteFrame)
            {
                string spriteSheet = ReadCachedString();
                string spriteFile = ReadCachedString();

                CCSpriteFrame spriteFrame;

                if (String.IsNullOrEmpty(spriteSheet))
                {
                    spriteFile = _CCBRootPath + spriteFile;

                    CCTexture2D texture = CCTextureCache.SharedTextureCache.AddImage(CCFileUtils.RemoveExtension(spriteFile));
                    var bounds = new CCRect(0, 0, texture.ContentSize.Width, texture.ContentSize.Height);
                    spriteFrame = new CCSpriteFrame(texture, bounds);
                }
                else
                {
                    spriteSheet = _CCBRootPath + spriteSheet;
                    CCSpriteFrameCache frameCache = CCSpriteFrameCache.SharedSpriteFrameCache;

                    // Load the sprite sheet only if it is not loaded            
                    if (!_loadedSpriteSheets.Contains(spriteSheet))
                    {
                        frameCache.AddSpriteFramesWithFile(spriteSheet);
                        _loadedSpriteSheets.Add(spriteSheet);
                    }

                    spriteFrame = frameCache.SpriteFrameByName(spriteFile);
                }
                value = spriteFrame;
            }

            keyframe.Value = value;

            return keyframe;
        }
Esempio n. 21
0
        public void Transform(ref CCRect rect)
        {
            float top = rect.MinY;
            float left = rect.MinX;
            float right = rect.MaxX;
            float bottom = rect.MaxY;

            CCPoint topLeft = new CCPoint(left, top);
            CCPoint topRight = new CCPoint(right, top);
            CCPoint bottomLeft = new CCPoint(left, bottom);
            CCPoint bottomRight = new CCPoint(right, bottom);

            Transform(ref topLeft);
            Transform(ref topRight);
            Transform(ref bottomLeft);
            Transform(ref bottomRight);

            float minX = Math.Min(Math.Min(topLeft.X, topRight.X), Math.Min(bottomLeft.X, bottomRight.X));
            float maxX = Math.Max(Math.Max(topLeft.X, topRight.X), Math.Max(bottomLeft.X, bottomRight.X));
            float minY = Math.Min(Math.Min(topLeft.Y, topRight.Y), Math.Min(bottomLeft.Y, bottomRight.Y));
            float maxY = Math.Max(Math.Max(topLeft.Y, topRight.Y), Math.Max(bottomLeft.Y, bottomRight.Y));

            rect.Origin.X = minX;
            rect.Origin.Y = minY;
            rect.Size.Width = maxX - minX;
            rect.Size.Height = maxY - minY;
        }
Esempio n. 22
0
 public bool IntersectsRect(CCRect rect)
 {
     return(!(MaxX < rect.MinX || rect.MaxX < MinX || MaxY < rect.MinY || rect.MaxY < MinY));
 }
Esempio n. 23
0
        private b2Body m_pBody; // strong ref

        public CCPhysicsSprite(CCTexture2D f, CCRect r)
            : base(f, r)
        {
        }
Esempio n. 24
0
        public void AddSpriteFrameWithTexture(CCTexture2D pobTexture, CCRect rect)
        {
            CCSpriteFrame pFrame = new CCSpriteFrame(pobTexture, rect);

            AddSpriteFrame(pFrame);
        }
		internal static CCSize MeasureString (string textg, CTFont font, CCRect rect)
		{

			var atts = buildAttributedString(textg, font);

			// for now just a line not sure if this is going to work
			CTLine line = new CTLine(atts);

			// Create and initialize some values from the bounds.
			nfloat ascent;
			nfloat descent;
			nfloat leading;
			double lineWidth = line.GetTypographicBounds(out ascent, out descent, out leading);

            var measure = new CCSize((float)(lineWidth + leading), (float)(ascent + descent));

			return measure;
		}
Esempio n. 26
0
        public override void NeedsLayout()
        {
            if (!m_bParentInited)
            {
                return;
            }
            // Hide the background and the label
            if (m_titleLabel != null)
            {
                m_titleLabel.Visible = false;
            }
            if (m_backgroundSprite != null)
            {
                m_backgroundSprite.Visible = false;
            }
            // Update anchor of all labels
            LabelAnchorPoint = m_labelAnchorPoint;

            // Update the label to match with the current state

            m_currentTitle      = GetTitleForState(m_eState);
            m_currentTitleColor = GetTitleColorForState(m_eState);

            TitleLabel = GetTitleLabelForState(m_eState);

            var label = (ICCLabelProtocol)m_titleLabel;

            if (label != null && !String.IsNullOrEmpty(m_currentTitle))
            {
                label.Label = (m_currentTitle);
            }

            var rgbaLabel = (ICCRGBAProtocol)m_titleLabel;

            if (rgbaLabel != null)
            {
                rgbaLabel.Color = m_currentTitleColor;
            }
            if (m_titleLabel != null)
            {
                m_titleLabel.Position = new CCPoint(ContentSize.Width / 2, ContentSize.Height / 2);
            }

            // Update the background sprite
            BackgroundSprite = GetBackgroundSpriteForState(m_eState);
            if (m_backgroundSprite != null)
            {
                m_backgroundSprite.Position = new CCPoint(ContentSize.Width / 2, ContentSize.Height / 2);
            }

            // Get the title label size
            CCSize titleLabelSize = CCSize.Zero;

            if (m_titleLabel != null)
            {
                titleLabelSize = m_titleLabel.BoundingBox.Size;
            }

            // Adjust the background image if necessary
            if (m_doesAdjustBackgroundImage)
            {
                // Add the margins
                if (m_backgroundSprite != null)
                {
                    m_backgroundSprite.ContentSize = new CCSize(titleLabelSize.Width + m_marginH * 2, titleLabelSize.Height + m_marginV * 2);
                }
            }
            else
            {
                //TODO: should this also have margins if one of the preferred sizes is relaxed?
                if (m_backgroundSprite != null)
                {
                    CCSize preferredSize = m_backgroundSprite.PreferredSize;
                    if (preferredSize.Width <= 0)
                    {
                        preferredSize.Width = titleLabelSize.Width;
                    }
                    if (preferredSize.Height <= 0)
                    {
                        preferredSize.Height = titleLabelSize.Height;
                    }

                    m_backgroundSprite.ContentSize = preferredSize;
                }
            }

            // Set the content size
            CCRect rectTitle = CCRect.Zero;

            if (m_titleLabel != null)
            {
                rectTitle = m_titleLabel.BoundingBox;
            }
            CCRect rectBackground = CCRect.Zero;

            if (m_backgroundSprite != null)
            {
                rectBackground = m_backgroundSprite.BoundingBox;
            }

            CCRect maxRect = CCControlUtils.CCRectUnion(rectTitle, rectBackground);

            ContentSize = new CCSize(maxRect.Size.Width, maxRect.Size.Height);

            if (m_titleLabel != null)
            {
                m_titleLabel.Position = new CCPoint(ContentSize.Width / 2, ContentSize.Height / 2);
                // Make visible label
                m_titleLabel.Visible = true;
            }

            if (m_backgroundSprite != null)
            {
                m_backgroundSprite.Position = new CCPoint(ContentSize.Width / 2, ContentSize.Height / 2);
                // Make visible the background
                m_backgroundSprite.Visible = true;
            }
        }
Esempio n. 27
0
 public CCMaskedSprite(string fileName, CCRect rect, byte[] mask)
     : base(fileName, rect)
 {
     _MyMask = mask;
 }
Esempio n. 28
0
 public bool IntersectsRect(ref CCRect rect)
 {
     return !(MaxX < rect.MinX || rect.MaxX < MinX || MaxY < rect.MinY || rect.MaxY < MinY);
 }
Esempio n. 29
0
        private CCSprite UpdateTileForGID(uint gid, CCPoint pos)
        {
            CCRect rect = m_pTileSet.RectForGID(gid);
            rect = new CCRect(rect.Origin.X / m_fContentScaleFactor, rect.Origin.Y / m_fContentScaleFactor, rect.Size.Width / m_fContentScaleFactor,
                              rect.Size.Height / m_fContentScaleFactor);
            var z = (int) (pos.X + pos.Y * m_tLayerSize.Width);

            CCSprite tile = ReusedTileWithRect(rect);

            SetupTileSprite(tile, pos, gid);

            // get atlas index
            int indexForZ = AtlasIndexForExistantZ(z);
            tile.AtlasIndex = indexForZ;
            tile.Dirty = true;
            tile.UpdateTransform();
            m_pTiles[z] = gid;

            return tile;
        }
Esempio n. 30
0
        public static bool ContainsPoint(ref CCRect rect, ref CCPoint point)
        {
            bool bRet = false;

            if (float.IsNaN(point.X))
            {
                point.X = 0;
            }

            if (float.IsNaN(point.Y))
            {
                point.Y = 0;
            }

            if (point.X >= rect.MinX && point.X <= rect.MaxX && point.Y >= rect.MinY &&
                point.Y <= rect.MaxY)
            {
                bRet = true;
            }

            return bRet;
        }
Esempio n. 31
0
 public void updateQuads(float dt)
 {
     m_nIndex = (m_nIndex + 1) % 4;
     var rect = new CCRect(m_nIndex * 32, 0, 32, 32);
     var system = (CCParticleSystemQuad) m_emitter;
     system.SetTextureWithRect(m_emitter.Texture, rect);
 }
Esempio n. 32
0
 public void AddSpriteFrameWithTexture(CCTexture2D pobTexture, CCRect rect)
 {
     CCSpriteFrame pFrame = new CCSpriteFrame(pobTexture, rect);
     AddSpriteFrame(pFrame);
 }
Esempio n. 33
0
        public CCRect Intersection(CCRect rect)
        {
            if (!IntersectsRect(rect))
            {
                return (Zero);
            }

            /*       +-------------+
             *       |             |
             *       |         +---+-----+
             * +-----+---+     |   |     |
             * |     |   |     |   |     |
             * |     |   |     +---+-----+
             * |     |   |         |
             * |     |   |         |
             * +-----+---+         |
             *       |             |
             *       +-------------+
             */
            float minx = 0, miny = 0, maxx = 0, maxy = 0;
            // X
            if (rect.MinX < MinX)
            {
                minx = MinX;
            }
            else if (rect.MinX < MaxX)
            {
                minx = rect.MinX;
            }
            if (rect.MaxX < MaxX)
            {
                maxx = rect.MaxX;
            }
            else if (rect.MaxX > MaxX)
            {
                maxx = MaxX;
            }
            //  Y
            if (rect.MinY < MinY)
            {
                miny = MinY;
            }
            else if (rect.MinY < MaxY)
            {
                miny = rect.MinY;
            }
            if (rect.MaxY < MaxY)
            {
                maxy = rect.MaxY;
            }
            else if (rect.MaxY > MaxY)
            {
                maxy = MaxY;
            }
            return new CCRect(minx, miny, maxx - minx, maxy - miny);
        }
 public CCScale9SpriteFrame(string spriteFrameName, CCRect capInsets)
 {
     InitWithSpriteFrameName(spriteFrameName, capInsets);
 }
Esempio n. 35
0
 public static bool Equal(ref CCRect rect1, ref CCRect rect2)
 {
     return rect1.Origin.Equals(rect2.Origin) && rect1.Size.Equals(rect2.Size);
 }
Esempio n. 36
0
 public void SetTextureRect(CCRect rect)
 {
     SetTextureRect(rect, false, rect.Size);
 }
Esempio n. 37
0
 public static bool IntersetsRect(ref CCRect rectA, ref CCRect rectB)
 {
     return
         !(rectA.MaxX < rectB.MinX || rectB.MaxX < rectA.MinX || rectA.MaxY < rectB.MinY ||
           rectB.MaxY < rectA.MinY);
 }
Esempio n. 38
0
        public void SetTextureRect(CCRect value, bool rotated, CCSize untrimmedSize)
        {
            m_bRectRotated = rotated;

            ContentSize = untrimmedSize;
            SetVertexRect(value);
            SetTextureCoords(value);

            CCPoint relativeOffset = m_obUnflippedOffsetPositionFromCenter;

            // issue #732
            if (m_bFlipX)
            {
                relativeOffset.X = -relativeOffset.X;
            }
            if (m_bFlipY)
            {
                relativeOffset.Y = -relativeOffset.Y;
            }

            m_obOffsetPosition.X = relativeOffset.X + (m_obContentSize.Width - m_obRect.Size.Width) / 2;
            m_obOffsetPosition.Y = relativeOffset.Y + (m_obContentSize.Height - m_obRect.Size.Height) / 2;

            // rendering using batch node
            if (m_pobBatchNode != null)
            {
                // update dirty_, don't update recursiveDirty_
                Dirty = true;
            }
            else
            {
                // self rendering

                // Atlas: Vertex
                float x1 = 0 + m_obOffsetPosition.X;
                float y1 = 0 + m_obOffsetPosition.Y;
                float x2 = x1 + m_obRect.Size.Width;
                float y2 = y1 + m_obRect.Size.Height;

                // Don't update Z.
                m_sQuad.BottomLeft.Vertices = CCTypes.Vertex3(x1, y1, 0);
                m_sQuad.BottomRight.Vertices = CCTypes.Vertex3(x2, y1, 0);
                m_sQuad.TopLeft.Vertices = CCTypes.Vertex3(x1, y2, 0);
                m_sQuad.TopRight.Vertices = CCTypes.Vertex3(x2, y2, 0);
            }
        }
Esempio n. 39
0
		public static CCRect CCRectUnion(CCRect src1, CCRect src2)
		{
			CCRect result;
    
			float x1 = Math.Min(src1.MinX, src2.MinX);
			float y1 = Math.Min(src1.MinY, src2.MinY);
			float x2 = Math.Max(src1.MaxX, src2.MaxX);
			float y2 = Math.Max(src1.MaxY, src2.MaxY);
    
			result.Origin = new CCPoint(x1,x2);
			result.Size = new CCSize(x2-x1, y2-y1);
			return result;
		}
Esempio n. 40
0
 // override this method to generate "double scale" sprites
 protected virtual void SetVertexRect(CCRect rect)
 {
     m_obRect = rect;
 }
Esempio n. 41
0
        public CCRect Transform(CCRect rect)
        {
            float top = rect.MinY;
            float left = rect.MinX;
            float right = rect.MaxX;
            float bottom = rect.MaxY;

            CCPoint topLeft = new CCPoint(left, top);  
            CCPoint topRight = new CCPoint(right, top);
            CCPoint bottomLeft = new CCPoint(left, bottom);
            CCPoint bottomRight = new CCPoint(right, bottom);

            Transform(ref topLeft);
            Transform(ref topRight);
            Transform(ref bottomLeft);
            Transform(ref bottomRight);

            float minX = Math.Min(Math.Min(topLeft.X, topRight.X), Math.Min(bottomLeft.X, bottomRight.X));
            float maxX = Math.Max(Math.Max(topLeft.X, topRight.X), Math.Max(bottomLeft.X, bottomRight.X));
            float minY = Math.Min(Math.Min(topLeft.Y, topRight.Y), Math.Min(bottomLeft.Y, bottomRight.Y));
            float maxY = Math.Max(Math.Max(topLeft.Y, topRight.Y), Math.Max(bottomLeft.Y, bottomRight.Y));

            return new CCRect(minX, minY, (maxX - minX), (maxY - minY));
        }
Esempio n. 42
0
        private void SetTextureCoords(CCRect rect)
        {
            rect = rect.PointsToPixels();

            CCTexture2D tex = m_pobBatchNode != null ? m_pobTextureAtlas.Texture : m_pobTexture;
            if (tex == null)
            {
                return;
            }

            float atlasWidth = tex.PixelsWide;
            float atlasHeight = tex.PixelsHigh;

            float left, right, top, bottom;

            if (m_bRectRotated)
            {
#if CC_FIX_ARTIFACTS_BY_STRECHING_TEXEL
                left = (2 * rect.Origin.X + 1) / (2 * atlasWidth);
                right = left + (rect.Size.Height * 2 - 2) / (2 * atlasWidth);
                top = (2 * rect.Origin.Y + 1) / (2 * atlasHeight);
                bottom = top + (rect.Size.Width * 2 - 2) / (2 * atlasHeight);
#else
                left = rect.Origin.X / atlasWidth;
                right = (rect.Origin.X + rect.Size.Height) / atlasWidth;
                top = rect.Origin.Y / atlasHeight;
                bottom = (rect.Origin.Y + rect.Size.Width) / atlasHeight;
#endif

                if (m_bFlipX)
                {
                    CCMacros.CCSwap(ref top, ref bottom);
                }

                if (m_bFlipY)
                {
                    CCMacros.CCSwap(ref left, ref right);
                }

                m_sQuad.BottomLeft.TexCoords.U = left;
                m_sQuad.BottomLeft.TexCoords.V = top;
                m_sQuad.BottomRight.TexCoords.U = left;
                m_sQuad.BottomRight.TexCoords.V = bottom;
                m_sQuad.TopLeft.TexCoords.U = right;
                m_sQuad.TopLeft.TexCoords.V = top;
                m_sQuad.TopRight.TexCoords.U = right;
                m_sQuad.TopRight.TexCoords.V = bottom;
            }
            else
            {
#if CC_FIX_ARTIFACTS_BY_STRECHING_TEXEL
                left = (2 * rect.Origin.X + 1) / (2 * atlasWidth);
                right = left + (rect.Size.Width * 2 - 2) / (2 * atlasWidth);
                top = (2 * rect.Origin.Y + 1) / (2 * atlasHeight);
                bottom = top + (rect.Size.Height * 2 - 2) / (2 * atlasHeight);
#else
                left = rect.Origin.X / atlasWidth;
                right = (rect.Origin.X + rect.Size.Width) / atlasWidth;
                top = rect.Origin.Y / atlasHeight;
                bottom = (rect.Origin.Y + rect.Size.Height) / atlasHeight;
#endif

                if (m_bFlipX)
                {
                    CCMacros.CCSwap(ref left, ref right);
                }

                if (m_bFlipY)
                {
                    CCMacros.CCSwap(ref top, ref bottom);
                }

                m_sQuad.BottomLeft.TexCoords.U = left;
                m_sQuad.BottomLeft.TexCoords.V = bottom;
                m_sQuad.BottomRight.TexCoords.U = right;
                m_sQuad.BottomRight.TexCoords.V = bottom;
                m_sQuad.TopLeft.TexCoords.U = left;
                m_sQuad.TopLeft.TexCoords.V = top;
                m_sQuad.TopRight.TexCoords.U = right;
                m_sQuad.TopRight.TexCoords.V = top;
            }
        }
Esempio n. 43
0
 public static CCRect Transform(CCRect rect, CCAffineTransform anAffineTransform)
 {
     return anAffineTransform.Transform(rect);
 }
Esempio n. 44
0
 public static CCRect Transform(CCRect rect, CCAffineTransform anAffineTransform)
 {
     return(anAffineTransform.Transform(rect));
 }