public bool InitWithSpriteFrame(CCSpriteFrame spriteFrame, float delayUnits, PlistDictionary userInfo) { m_pSpriteFrame = spriteFrame; m_fDelayUnits = delayUnits; m_pUserInfo = userInfo; return true; }
CCSprite spriteWithSpriteFrame(CCSpriteFrame frame, bool forward) { CCSprite sel = new CCSprite(frame); if (sel != null) { RunAction(new CCMoveBy(0.8f, new CCPoint((forward) ? 600 : -600, 0))); } return sel; }
protected override void OnHandlePropTypeSpriteFrame(CCNode node, CCNode parent, string propertyName, CCSpriteFrame spriteFrame, CCBReader reader) { if (propertyName == PROPERTY_SPRITEFRAME) { ((CCScale9Sprite) node).InitWithSpriteFrame(spriteFrame); } else { base.OnHandlePropTypeSpriteFrame(node, parent, propertyName, spriteFrame, reader); } }
protected override void OnHandlePropTypeSpriteFrame(CCNode node, CCNode parent, string propertyName, CCSpriteFrame spriteFrame, CCBReader reader) { if (propertyName == PROPERTY_DISPLAYFRAME) { ((CCSprite) node).DisplayFrame = spriteFrame; } else { base.OnHandlePropTypeSpriteFrame(node, parent, propertyName, spriteFrame, reader); } }
void Active() { if (isActive) return; isActive = true; if (type == 0) { bf1 = CCApplication.SharedApplication.SpriteFrameCache["Image 904 at frame 10.png"];//, new CCRect(0, 0, 46, 21)); bf2 = CCApplication.SharedApplication.SpriteFrameCache["Image 905 at frame 10.png"];//, new CCRect(0, 0, 46, 22)); Schedule(TankFire, 2); } }
protected override void OnHandlePropTypeSpriteFrame(CCNode node, CCNode parent, string propertyName, CCSpriteFrame spriteFrame, CCBReader reader) { if (propertyName == PROPERTY_DISPLAYFRAME) { if (spriteFrame != null) { ((CCSprite) node).SpriteFrame = spriteFrame; } else { CCLog.Log("ERROR: SpriteFrame NULL"); } } else { base.OnHandlePropTypeSpriteFrame(node, parent, propertyName, spriteFrame, reader); } }
public SpriteAnimationSplit() { CCSize s = CCDirector.SharedDirector.WinSize; CCTexture2D texture = CCTextureCache.SharedTextureCache.AddImage("animations/dragon_animation"); // manually add frames to the frame cache CCSpriteFrame frame0 = new CCSpriteFrame(texture, new CCRect(132 * 0, 132 * 0, 132, 132)); CCSpriteFrame frame1 = new CCSpriteFrame(texture, new CCRect(132 * 1, 132 * 0, 132, 132)); CCSpriteFrame frame2 = new CCSpriteFrame(texture, new CCRect(132 * 2, 132 * 0, 132, 132)); CCSpriteFrame frame3 = new CCSpriteFrame(texture, new CCRect(132 * 3, 132 * 0, 132, 132)); CCSpriteFrame frame4 = new CCSpriteFrame(texture, new CCRect(132 * 0, 132 * 1, 132, 132)); CCSpriteFrame frame5 = new CCSpriteFrame(texture, new CCRect(132 * 1, 132 * 1, 132, 132)); // // Animation using Sprite BatchNode // CCSprite sprite = new CCSprite(frame0); sprite.Position = (new CCPoint(s.Width / 2 - 80, s.Height / 2)); AddChild(sprite); var animFrames = new List <CCSpriteFrame>(6); animFrames.Add(frame0); animFrames.Add(frame1); animFrames.Add(frame2); animFrames.Add(frame3); animFrames.Add(frame4); animFrames.Add(frame5); CCAnimation animation = new CCAnimation(animFrames, 0.2f); CCAnimate animate = new CCAnimate(animation); CCActionInterval seq = (CCActionInterval)(new CCSequence(animate, new CCFlipX(true), (CCFiniteTimeAction)animate.Copy(), new CCFlipX(false) )); sprite.RunAction(new CCRepeatForever(seq)); //animFrames->release(); // win32 : memory leak 2010-0415 }
public SpriteAnimationSplit() { CCSize s = CCDirector.sharedDirector().getWinSize(); CCTexture2D texture = CCTextureCache.sharedTextureCache().addImage("animations/images/dragon_animation"); // manually add frames to the frame cache CCSpriteFrame frame0 = CCSpriteFrame.frameWithTexture(texture, new CCRect(132 * 0, 132 * 0, 132, 132)); CCSpriteFrame frame1 = CCSpriteFrame.frameWithTexture(texture, new CCRect(132 * 1, 132 * 0, 132, 132)); CCSpriteFrame frame2 = CCSpriteFrame.frameWithTexture(texture, new CCRect(132 * 2, 132 * 0, 132, 132)); CCSpriteFrame frame3 = CCSpriteFrame.frameWithTexture(texture, new CCRect(132 * 3, 132 * 0, 132, 132)); CCSpriteFrame frame4 = CCSpriteFrame.frameWithTexture(texture, new CCRect(132 * 0, 132 * 1, 132, 132)); CCSpriteFrame frame5 = CCSpriteFrame.frameWithTexture(texture, new CCRect(132 * 1, 132 * 1, 132, 132)); // // Animation using Sprite BatchNode // CCSprite sprite = CCSprite.spriteWithSpriteFrame(frame0); sprite.position = (new CCPoint(s.width / 2 - 80, s.height / 2)); addChild(sprite); List <CCSpriteFrame> animFrames = new List <CCSpriteFrame>(6); animFrames.Add(frame0); animFrames.Add(frame1); animFrames.Add(frame2); animFrames.Add(frame3); animFrames.Add(frame4); animFrames.Add(frame5); CCAnimation animation = CCAnimation.animationWithFrames(animFrames, 0.2f); CCAnimate animate = CCAnimate.actionWithAnimation(animation, false); CCActionInterval seq = (CCActionInterval)(CCSequence.actions(animate, CCFlipX.actionWithFlipX(true), (CCFiniteTimeAction)animate.copy(), CCFlipX.actionWithFlipX(false) )); sprite.runAction(CCRepeatForever.actionWithAction(seq)); //animFrames->release(); // win32 : memory leak 2010-0415 }
// Sprite frame public CCScale9Sprite(CCSpriteFrame spriteFrame, CCRect capInsets) { var sprite = new CCSprite(spriteFrame); if (spriteFrame != null && spriteFrame.Texture != null) { UpdateWithSprite(sprite, spriteFrame.TextureRectInPixels, spriteFrame.IsRotated, spriteFrame.OffsetInPixels, spriteFrame.OriginalSizeInPixels, capInsets); // Reset insets insetLeft = 0; insetTop = 0; insetRight = 0; insetBottom = 0; } }
public SpriteOffsetAnchorSkew() { CCSpriteFrameCache cache = CCSpriteFrameCache.SharedSpriteFrameCache; cache.AddSpriteFrames("animations/grossini.plist"); cache.AddSpriteFrames("animations/grossini_gray.plist", "animations/grossini_gray"); sprites = new CCSprite[numOfSprites]; pointSprites = new CCSprite[numOfSprites]; var animFrames = new List <CCSpriteFrame>(); string tmp = ""; for (int j = 0; j < 14; j++) { tmp = string.Format("grossini_dance_{0:00}.png", j + 1); CCSpriteFrame frame = cache[tmp]; animFrames.Add(frame); } animation = new CCAnimation(animFrames, 0.3f); // Skew CCSkewBy skewX = new CCSkewBy(2, 45, 0); CCFiniteTimeAction skewX_back = (CCFiniteTimeAction)skewX.Reverse(); CCSkewBy skewY = new CCSkewBy(2, 0, 45); CCFiniteTimeAction skewY_back = (CCFiniteTimeAction)skewY.Reverse(); seq_skew = new CCSequence(skewX, skewX_back, skewY, skewY_back); for (int i = 0; i < numOfSprites; i++) { // Animation using Sprite batch sprites[i] = new CCSprite("grossini_dance_01.png"); AddChild(sprites[i], 0); pointSprites[i] = new CCSprite("Images/r1"); AddChild(pointSprites[i], 1); } }
public CocoPiece(Piece piece, CCSpriteFrame cCSpriteFrame) : base(cCSpriteFrame) { this.ScaleX = 118 / cCSpriteFrame.Texture.ContentSizeInPixels.Width + 0.1f; this.ScaleY = 118 / cCSpriteFrame.Texture.ContentSizeInPixels.Width + 0.1f; this.piece = piece; this.piece.PieceTaken += OnPieceTaken; this.piece.PositionUpdated += (s, p) => { this.Position = p.GetPoint(this.piece.Board.Size); }; AnchorPoint = CCPoint.AnchorMiddle; Position = this.GetPosition(); touchListener = new CCEventListenerTouchOneByOne(); touchListener.OnTouchMoved = Touch; touchListener.OnTouchBegan = ToucheBegan; touchListener.OnTouchEnded = TouchEnded; touchListener.OnTouchCancelled = TouchCanceled; AddEventListener(touchListener, this); }
public SpriteAnimationSplit() { var texture = CCTextureCache.SharedTextureCache.AddImage("animations/dragon_animation"); CCSize contentSizeInPixels = texture.ContentSizeInPixels; float height = contentSizeInPixels.Height / 4.0f; float heightOffset = height / 2.0f; float width = contentSizeInPixels.Width / 5.0f; // Manually add frames to the frame cache // The rects in pixels of each frame are determined from the textureatlas var frame0 = new CCSpriteFrame(texture, new CCRect(width * 0, heightOffset + height * 0, width, height)); var frame1 = new CCSpriteFrame(texture, new CCRect(width * 1, heightOffset + height * 0, width, height)); var frame2 = new CCSpriteFrame(texture, new CCRect(width * 2, heightOffset + height * 0, width, height)); var frame3 = new CCSpriteFrame(texture, new CCRect(width * 3, heightOffset + height * 0, width, height)); // Note: The height positioning below is a bit of voodoo because the sprite atlas isn't currently packed tightly // See the dragon_animation.png file var frame4 = new CCSpriteFrame(texture, new CCRect(width * 0, heightOffset * 1.6f + height * 1, width, height)); var frame5 = new CCSpriteFrame(texture, new CCRect(width * 1, heightOffset * 1.6f + height * 1, width, height)); // Animation using Sprite BatchNode sprite = new CCSprite(frame0); AddChild(sprite); var animFrames = new List <CCSpriteFrame>(6); animFrames.Add(frame0); animFrames.Add(frame1); animFrames.Add(frame2); animFrames.Add(frame3); animFrames.Add(frame4); animFrames.Add(frame5); CCAnimation animation = new CCAnimation(animFrames, 0.2f); CCAnimate animate = new CCAnimate(animation); seq = new CCSequence(animate, new CCFlipX(true), animate, new CCFlipX(false)); }
public static LHSprite nodeWithDictionary(PlistDictionary dict, CCNode prnt) { LHScene scene = ((LHNodeProtocol)prnt).getScene(); string imageFileName = dict ["imageFileName"].AsString; string relativeImagePath = dict ["relativeImagePath"].AsString; // string imagePath = LHUtils.imagePathWithFilename (imageFileName, relativeImagePath, scene.currentDeviceSuffix (false)); // string imageDevPath = LHUtils.imagePathWithFilename (imageFileName, relativeImagePath, scene.currentDeviceSuffix (true)); string imagePath = LHUtils.imagePathWithFilename(imageFileName, "", scene.currentDeviceSuffix(false)); string imageDevPath = LHUtils.imagePathWithFilename(imageFileName, "", scene.currentDeviceSuffix(true)); CCTexture2D texture = scene.textureWithImagePath(imagePath); CCSpriteFrame spriteFrame = null; string imageFilePath = imageDevPath; string spriteFrameName = dict["spriteName"].AsString; if (spriteFrameName != null) { LHSprite.cacheSpriteFramesInfo(imageDevPath, scene); spriteFrame = CCSpriteFrameCache.SharedSpriteFrameCache [spriteFrameName]; } else { //spriteFrame = [texture createSpriteFrame]; } LHSprite spr = new LHSprite(spriteFrame, dict, prnt, spriteFrameName, imageDevPath); return(spr); }
public SpriteHybrid() { // parents CCNode parent1 = new CCNode(); CCSprite parent2 = new CCSprite("animations/grossini"); AddChild(parent1, 0, (int)kTags.kTagNode); AddChild(parent2, 0, (int)kTags.kTagSpriteBatchNode); sprites = new CCSprite[numOfSprites]; CCSpriteFrameCache.SharedSpriteFrameCache.AddSpriteFrames("animations/grossini.plist"); // create 250 sprites // only show 80% of them for (int i = 0; i < numOfSprites; i++) { int spriteIdx = (int)(CCRandom.NextDouble() * 14); string str = ""; string temp = ""; if (spriteIdx + 1 < 10) { temp = "0" + (spriteIdx + 1); } else { temp = (spriteIdx + 1).ToString(); } str = string.Format("grossini_dance_{0}.png", temp); CCSpriteFrame frame = CCSpriteFrameCache.SharedSpriteFrameCache[str]; sprites[i] = new CCSprite(frame); parent1.AddChild(sprites[i], i, i); } usingSpriteBatchNode = false; }
public CCScale9SpriteFrame(CCSpriteFrame spriteFrame) : base(spriteFrame) { }
public void ShowWindow(CCSprite currentSprite, string folderName) { if (isModal) { return; } windowFrame = new CCSprite("BlankFrame") { PositionX = currentSprite.Position.X, PositionY = currentSprite.Position.Y, Tag = SpriteTypes.WindowTag }; var scaling = (spriteModelFactory.DynamicWidth * 0.1f) / windowFrame.ContentSize.Width; windowFrame.ContentSize = new CCSize(windowFrame.ContentSize.Width * scaling, windowFrame.ContentSize.Height * scaling); closeButton = new CCSprite("IconClose"); closeButton.ContentSize = new CCSize(windowFrame.ContentSize.Width * 0.075f, windowFrame.ContentSize.Width * 0.075f); closeButton.PositionX = windowFrame.ContentSize.Width - closeButton.ContentSize.Width / 2 - 3; closeButton.PositionY = windowFrame.ContentSize.Height - closeButton.ContentSize.Height / 2 - 3; closeButton.Tag = SpriteTypes.CloseWindowTag; AddEventListener(mListener.Copy(), closeButton); ScheduleOnce((dt) => { windowFrame.AddChild(closeButton, 1001, SpriteTypes.CloseWindowTag); lock (storedList) { var mEqualList = storedList.Where(l => l.FolderName == folderName).ToList(); for (var i = 0; i < mEqualList.Count; i++) { // Pull respective icon var mStoredIconRef = mEqualList[i]; var mSprite = mStoredIconRef.Sprite; var mContent = mSprite.GetChildByTag(SpriteTypes.ContentTag) as CCLabel; if (mContent != null) { var parentSprite = new CCSprite("BlankFrame"); parentSprite.ContentSize = new CCSize(windowFrame.ContentSize.Width * 0.25f, windowFrame.ContentSize.Height * 0.25f); var pSpacing = parentSprite.ContentSize.Width * 0.15f; var xSpacing = parentSprite.ContentSize.Width * ((i % 3)) + pSpacing * ((i % 3) + 1); var ySpacing = parentSprite.ContentSize.Height * ((i / 3)) + pSpacing * ((i / 3) + 1); parentSprite.PositionX = (parentSprite.ContentSize.Width * 0.5f) + xSpacing; parentSprite.PositionY = windowFrame.ContentSize.Height - (parentSprite.ContentSize.Height * 0.5f) - ySpacing; parentSprite.Tag = SpriteTypes.IconTag; mStoredIconRef.Sprite.ContentSize = parentSprite.ContentSize; mStoredIconRef.Sprite.PositionX = parentSprite.PositionX; mStoredIconRef.Sprite.PositionY = parentSprite.PositionY; byte[] bytes = Convert.FromBase64String(mStoredIconRef.Base64); var testTexture = new CCTexture2D(bytes); var testFrame = new CCSpriteFrame(testTexture, new CCRect(0, 0, testTexture.PixelsWide, testTexture.PixelsHigh)); var subIconFrame = new CCSprite(testFrame) { AnchorPoint = CCPoint.AnchorMiddle, ContentSize = new CCSize(parentSprite.ContentSize.Width * 0.75f, parentSprite.ContentSize.Height * 0.75f), PositionX = parentSprite.ContentSize.Width * 0.5f, PositionY = parentSprite.ContentSize.Height * 0.5f + parentSprite.ContentSize.Height * 0.075f, Tag = SpriteTypes.ImageTag }; var label = new CCLabel(mContent.Text, "Arial", 22, CCLabelFormat.SystemFont) { Scale = 0.25f * scaling, AnchorPoint = CCPoint.AnchorMiddle, HorizontalAlignment = CCTextAlignment.Center, VerticalAlignment = CCVerticalTextAlignment.Center, PositionX = parentSprite.ContentSize.Width * 0.5f, PositionY = parentSprite.ContentSize.Height * 0.075f, Color = CCColor3B.Black, Visible = mStoredIconRef.TextVisible, Tag = SpriteTypes.ContentTag }; parentSprite.AddChild(subIconFrame); AddEventListener(mListener.Copy(), parentSprite); windowFrame.AddChild(parentSprite, 1001, SpriteTypes.IconTag); parentSprite.AddChild(label); } } } AddEventListener(mListener.Copy(), windowFrame); tempWindow = new IconReference(windowFrame, "Window", 1f, true); iconList2.Add(tempWindow); AddChild(windowFrame, 1000, SpriteTypes.WindowTag); var moveAction = new CCMoveTo(0.2f, new CCPoint(spriteModelFactory.DynamicWidth / 2f, spriteModelFactory.DynamicHeight / 2f)); var dimension = Math.Min(spriteModelFactory.DynamicHeight, spriteModelFactory.DynamicWidth); var scale = (dimension / windowFrame.ContentSize.Width) * 0.9f; var scaleAction = new CCScaleTo(0.2f, scale); windowFrame.AddActions(false, moveAction, scaleAction); isModal = true; }, 0); }
public void DrawTexture(CCSpriteFrame spriteFrame, CCPoint position, CCSize size, float opacity) => DrawTexture(spriteFrame, position, size, CCColor3B.White, opacity);
public SpriteBatchNodeOffsetAnchorRotation() { CCSize s = CCDirector.sharedDirector().getWinSize(); for (int i = 0; i < 3; i++) { CCSpriteFrameCache cache = CCSpriteFrameCache.sharedSpriteFrameCache(); cache.addSpriteFramesWithFile("animations/grossini"); cache.addSpriteFramesWithFile("animations/grossini_gray", "animations/images/grossini_gray"); // // Animation using Sprite BatchNode // CCSprite sprite = CCSprite.spriteWithSpriteFrameName("grossini_dance_01.png"); sprite.position = (new CCPoint(s.width / 4 * (i + 1), s.height / 2)); CCSprite point = CCSprite.spriteWithFile("Images/r1"); point.scale = 0.25f; point.position = sprite.position; addChild(point, 200); switch (i) { case 0: sprite.anchorPoint = new CCPoint(0, 0); break; case 1: sprite.anchorPoint = new CCPoint(0.5f, 0.5f); break; case 2: sprite.anchorPoint = new CCPoint(1, 1); break; } point.position = sprite.position; CCSpriteBatchNode spritebatch = CCSpriteBatchNode.batchNodeWithFile("animations/images/grossini"); addChild(spritebatch); List <CCSpriteFrame> animFrames = new List <CCSpriteFrame>(14); string str = ""; for (int k = 0; k < 14; k++) { string temp = ""; if (k + 1 < 10) { temp = "0" + (k + 1); } else { temp = k + 1 + ""; } str = string.Format("grossini_dance_{0}.png", temp); CCSpriteFrame frame = cache.spriteFrameByName(str); animFrames.Add(frame); } CCAnimation animation = CCAnimation.animationWithFrames(animFrames); sprite.runAction(CCRepeatForever.actionWithAction(CCAnimate.actionWithAnimation(animation, false))); sprite.runAction(CCRepeatForever.actionWithAction(CCRotateBy.actionWithDuration(10, 360))); spritebatch.addChild(sprite, i); //animFrames.release(); // win32 : memory leak 2010-0415 } }
public void AddSpriteFrame(CCSpriteFrame pobFrame, string pszFrameName) { if (!_AllowFrameOverwrite && m_pSpriteFrames.ContainsKey(pszFrameName)) { throw (new ArgumentException("The frame named " + pszFrameName + " already exists.")); } m_pSpriteFrames[pszFrameName] = pobFrame; }
public void SetNormalSpriteFrame(CCSpriteFrame frame) { NormalImage = new CCSprite(frame); }
public void SetDisabledSpriteFrame(CCSpriteFrame frame) { DisabledImage = new CCSprite(frame); }
public AnimationCache() { var frameCache = CCSpriteFrameCache.SharedSpriteFrameCache; frameCache.AddSpriteFrames("animations/grossini.plist"); frameCache.AddSpriteFrames("animations/grossini_gray.plist"); frameCache.AddSpriteFrames("animations/grossini_blue.plist"); // // create animation "dance" // var animFrames = new List <CCSpriteFrame>(15); string str = ""; for (int i = 1; i < 15; i++) { str = string.Format("grossini_dance_{0:00}.png", i); CCSpriteFrame frame = CCSpriteFrameCache.SharedSpriteFrameCache[str]; animFrames.Add(frame); } CCAnimation animation = new CCAnimation(animFrames, 0.2f); // Add an animation to the Cache CCAnimationCache.SharedAnimationCache.AddAnimation(animation, "dance"); // // create animation "dance gray" // animFrames.Clear(); for (int i = 1; i < 15; i++) { str = String.Format("grossini_dance_gray_{0:00}.png", i); CCSpriteFrame frame = CCSpriteFrameCache.SharedSpriteFrameCache[str]; animFrames.Add(frame); } animation = new CCAnimation(animFrames, 0.2f); // Add an animation to the Cache CCAnimationCache.SharedAnimationCache.AddAnimation(animation, "dance_gray"); // // create animation "dance blue" // animFrames.Clear(); for (int i = 1; i < 4; i++) { str = String.Format("grossini_blue_{0:00}.png", i); CCSpriteFrame frame = CCSpriteFrameCache.SharedSpriteFrameCache[str]; animFrames.Add(frame); } animation = new CCAnimation(animFrames, 0.2f); // Add an animation to the Cache CCAnimationCache.SharedAnimationCache.AddAnimation(animation, "dance_blue"); CCAnimationCache animCache = CCAnimationCache.SharedAnimationCache; CCAnimation normal = animCache["dance"]; normal.RestoreOriginalFrame = true; CCAnimation dance_grey = animCache["dance_gray"]; dance_grey.RestoreOriginalFrame = true; CCAnimation dance_blue = animCache["dance_blue"]; dance_blue.RestoreOriginalFrame = true; CCAnimate animN = new CCAnimate(normal); CCAnimate animG = new CCAnimate(dance_grey); CCAnimate animB = new CCAnimate(dance_blue); seqAnimation = new CCSequence(animN, animG, animB); grossini = new CCSprite(); AddChild(grossini); }
public SpriteFrameTest() { CCSize s = CCDirector.sharedDirector().getWinSize(); // IMPORTANT: // The sprite frames will be cached AND RETAINED, and they won't be released unless you call // CCSpriteFrameCache::sharedSpriteFrameCache()->removeUnusedSpriteFrames); CCSpriteFrameCache cache = CCSpriteFrameCache.sharedSpriteFrameCache(); cache.addSpriteFramesWithFile("animations/grossini"); cache.addSpriteFramesWithFile("animations/grossini_gray", "animations/images/grossini_gray"); cache.addSpriteFramesWithFile("animations/grossini_blue", "animations/images/grossini_blue"); // // Animation using Sprite BatchNode // m_pSprite1 = CCSprite.spriteWithSpriteFrameName("grossini_dance_01.png"); m_pSprite1.position = (new CCPoint(s.width / 2 - 80, s.height / 2)); CCSpriteBatchNode spritebatch = CCSpriteBatchNode.batchNodeWithFile("animations/images/grossini"); spritebatch.addChild(m_pSprite1); addChild(spritebatch); List <CCSpriteFrame> animFrames = new List <CCSpriteFrame>(15); string str = ""; for (int i = 1; i < 15; i++) { string temp; if (i < 10) { temp = "0" + i; } else { temp = i.ToString(); } str = string.Format("grossini_dance_{0}.png", temp); CCSpriteFrame frame = cache.spriteFrameByName(str); animFrames.Add(frame); } CCAnimation animation = CCAnimation.animationWithFrames(animFrames); m_pSprite1.runAction(CCRepeatForever.actionWithAction(CCAnimate.actionWithAnimation(animation, false))); // to test issue #732, uncomment the following line m_pSprite1.IsFlipX = false; m_pSprite1.IsFlipY = false; // // Animation using standard Sprite // m_pSprite2 = CCSprite.spriteWithSpriteFrameName("grossini_dance_01.png"); m_pSprite2.position = (new CCPoint(s.width / 2 + 80, s.height / 2)); addChild(m_pSprite2); List <CCSpriteFrame> moreFrames = new List <CCSpriteFrame>(20); for (int i = 1; i < 15; i++) { string temp; if (i < 10) { temp = "0" + i; } else { temp = i.ToString(); } str = string.Format("grossini_dance_gray_{0}.png", temp); CCSpriteFrame frame = cache.spriteFrameByName(str); moreFrames.Add(frame); } for (int i = 1; i < 5; i++) { str = string.Format("grossini_blue_0{0}.png", i); CCSpriteFrame frame = cache.spriteFrameByName(str); moreFrames.Add(frame); } // append frames from another batch moreFrames.AddRange(animFrames); CCAnimation animMixed = CCAnimation.animationWithFrames(moreFrames); m_pSprite2.runAction(CCRepeatForever.actionWithAction(CCAnimate.actionWithAnimation(animMixed, false))); // to test issue #732, uncomment the following line m_pSprite2.IsFlipX = (false); m_pSprite2.IsFlipY = (false); schedule(startIn05Secs, 0.5f); m_nCounter = 0; }
public CCAnimationFrame(CCSpriteFrame spriteFrame, float delayUnits, object userInfo) { SpriteFrame = spriteFrame; DelayUnits = delayUnits; UserInfo = userInfo; }
public CCScale9Sprite(CCSpriteFrame spriteFrame) : this(spriteFrame, CCRect.Zero) { }
protected override void OnHandlePropTypeSpriteFrame(CCNode node, CCNode parent, string propertyName, CCSpriteFrame spriteFrame, CCBReader reader) { if (propertyName == PROPERTY_SPRITEFRAME) { ((CCScale9Sprite)node).InitWithSpriteFrame(spriteFrame); } else { base.OnHandlePropTypeSpriteFrame(node, parent, propertyName, spriteFrame, reader); } }
public MySprite1(CCSpriteFrame frame) : base(frame) { ivar = 10; }
protected override void OnHandlePropTypeSpriteFrame(CCNode node, CCNode parent, string propertyName, CCSpriteFrame spriteFrame, CCBReader reader) { if (propertyName == PROPERTY_DISPLAYFRAME) { ((CCSprite)node).DisplayFrame = spriteFrame; } else { base.OnHandlePropTypeSpriteFrame(node, parent, propertyName, spriteFrame, reader); } }
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; } } }
public CCScale9SpriteFrame(CCSpriteFrame spriteFrame, CCRect capInsets) : base(spriteFrame, capInsets) { }
public SpriteOffsetAnchorSkewScale() { CCSize s = CCDirector.sharedDirector().getWinSize(); for (int i = 0; i < 3; i++) { CCSpriteFrameCache cache = CCSpriteFrameCache.sharedSpriteFrameCache(); cache.addSpriteFramesWithFile("animations/grossini"); cache.addSpriteFramesWithFile("animations/grossini_gray", "animations/images/grossini_gray"); // // Animation using Sprite batch // CCSprite sprite = CCSprite.spriteWithSpriteFrameName("grossini_dance_01.png"); sprite.position = (new CCPoint(s.width / 4 * (i + 1), s.height / 2)); CCSprite point = CCSprite.spriteWithFile("Images/r1"); point.scale = 0.25f; point.position = sprite.position; addChild(point, 1); switch (i) { case 0: sprite.anchorPoint = new CCPoint(0, 0); break; case 1: sprite.anchorPoint = (new CCPoint(0.5f, 0.5f)); break; case 2: sprite.anchorPoint = (new CCPoint(1, 1)); break; } point.position = sprite.position; List <CCSpriteFrame> animFrames = new List <CCSpriteFrame>(); string tmp = ""; for (int j = 0; j < 14; j++) { string temp = ""; if (j + 1 < 10) { temp = "0" + (j + 1); } else { temp = (j + 1).ToString(); } tmp = string.Format("grossini_dance_{0}.png", temp); CCSpriteFrame frame = cache.spriteFrameByName(tmp); animFrames.Add(frame); } CCAnimation animation = CCAnimation.animationWithFrames(animFrames); sprite.runAction(CCRepeatForever.actionWithAction(CCAnimate.actionWithDuration(2.8f, animation, false))); animFrames = null; // Skew CCSkewBy skewX = CCSkewBy.actionWithDuration(2, 45, 0); CCActionInterval skewX_back = (CCActionInterval)skewX.reverse(); CCSkewBy skewY = CCSkewBy.actionWithDuration(2, 0, 45); CCActionInterval skewY_back = (CCActionInterval)skewY.reverse(); CCFiniteTimeAction seq_skew = CCSequence.actions(skewX, skewX_back, skewY, skewY_back); sprite.runAction(CCRepeatForever.actionWithAction((CCActionInterval)seq_skew)); // Scale CCScaleBy scale = CCScaleBy.actionWithDuration(2, 2); CCActionInterval scale_back = (CCActionInterval)scale.reverse(); CCFiniteTimeAction seq_scale = CCSequence.actions(scale, scale_back); sprite.runAction(CCRepeatForever.actionWithAction((CCActionInterval)seq_scale)); addChild(sprite, 0); } }
public SpriteFrameTest() { CCSize s = CCDirector.SharedDirector.WinSize; // IMPORTANT: // The sprite frames will be cached AND RETAINED, and they won't be released unless you call // CCSpriteFrameCache::sharedSpriteFrameCache()->removeUnusedSpriteFrames); CCSpriteFrameCache cache = CCSpriteFrameCache.SharedSpriteFrameCache; cache.AddSpriteFramesWithFile("animations/grossini.plist"); cache.AddSpriteFramesWithFile("animations/grossini_gray.plist", "animations/grossini_gray"); cache.AddSpriteFramesWithFile("animations/grossini_blue.plist", "animations/grossini_blue"); // // Animation using Sprite BatchNode // m_pSprite1 = new CCSprite("grossini_dance_01.png"); m_pSprite1.Position = (new CCPoint(s.Width / 2 - 80, s.Height / 2)); CCSpriteBatchNode spritebatch = new CCSpriteBatchNode("animations/grossini"); spritebatch.AddChild(m_pSprite1); AddChild(spritebatch); var animFrames = new List <CCSpriteFrame>(15); string str = ""; for (int i = 1; i < 15; i++) { str = string.Format("grossini_dance_{0:00}.png", i); CCSpriteFrame frame = cache.SpriteFrameByName(str); animFrames.Add(frame); } CCAnimation animation = new CCAnimation(animFrames, 0.3f); m_pSprite1.RunAction(new CCRepeatForever(new CCAnimate(animation))); // to test issue #732, uncomment the following line m_pSprite1.FlipX = false; m_pSprite1.FlipY = false; // // Animation using standard Sprite // m_pSprite2 = new CCSprite("grossini_dance_01.png"); m_pSprite2.Position = (new CCPoint(s.Width / 2 + 80, s.Height / 2)); AddChild(m_pSprite2); var moreFrames = new List <CCSpriteFrame>(20); for (int i = 1; i < 15; i++) { string temp; str = string.Format("grossini_dance_gray_{0:00}.png", i); CCSpriteFrame frame = cache.SpriteFrameByName(str); moreFrames.Add(frame); } for (int i = 1; i < 5; i++) { str = string.Format("grossini_blue_{0:00}.png", i); CCSpriteFrame frame = cache.SpriteFrameByName(str); moreFrames.Add(frame); } // append frames from another batch moreFrames.AddRange(animFrames); CCAnimation animMixed = new CCAnimation(moreFrames, 0.3f); m_pSprite2.RunAction(new CCRepeatForever(new CCAnimate(animMixed))); // to test issue #732, uncomment the following line m_pSprite2.FlipX = false; m_pSprite2.FlipY = false; Schedule(startIn05Secs, 0.5f); m_nCounter = 0; }
public void SetSelectedSpriteFrame(CCSpriteFrame frame) { SelectedImage = new CCSprite(frame); }
public SpriteBatchNodeChildren() { CCSize s = CCDirector.SharedDirector.WinSize; // parents CCSpriteBatchNode batch = new CCSpriteBatchNode("animations/grossini", 50); AddChild(batch, 0, (int)kTags.kTagSpriteBatchNode); CCSpriteFrameCache.SharedSpriteFrameCache.AddSpriteFramesWithFile("animations/grossini.plist"); CCSprite sprite1 = new CCSprite("grossini_dance_01.png"); sprite1.Position = (new CCPoint(s.Width / 3, s.Height / 2)); CCSprite sprite2 = new CCSprite("grossini_dance_02.png"); sprite2.Position = (new CCPoint(50, 50)); CCSprite sprite3 = new CCSprite("grossini_dance_03.png"); sprite3.Position = (new CCPoint(-50, -50)); batch.AddChild(sprite1); sprite1.AddChild(sprite2); sprite1.AddChild(sprite3); // BEGIN NEW CODE var animFrames = new List <CCSpriteFrame>(); string str = ""; for (int i = 1; i < 15; i++) { string temp = ""; if (i < 10) { temp = "0" + i; } else { temp = i.ToString(); } str = string.Format("grossini_dance_{0}.png", temp); CCSpriteFrame frame = CCSpriteFrameCache.SharedSpriteFrameCache.SpriteFrameByName(str); animFrames.Add(frame); } CCAnimation animation = new CCAnimation(animFrames, 0.2f); sprite1.RunAction(new CCRepeatForever(new CCAnimate(animation))); // END NEW CODE CCActionInterval action = new CCMoveBy(2, new CCPoint(200, 0)); CCActionInterval action_back = (CCActionInterval)action.Reverse(); CCActionInterval action_rot = new CCRotateBy(2, 360); CCActionInterval action_s = new CCScaleBy(2, 2); CCActionInterval action_s_back = (CCActionInterval)action_s.Reverse(); CCActionInterval seq2 = (CCActionInterval)action_rot.Reverse(); sprite2.RunAction(new CCRepeatForever(seq2)); sprite1.RunAction((CCAction)(new CCRepeatForever(action_rot))); sprite1.RunAction((CCAction)(new CCRepeatForever((CCActionInterval)(new CCSequence(action, action_back))))); sprite1.RunAction((CCAction)(new CCRepeatForever((CCActionInterval)(new CCSequence(action_s, action_s_back))))); }
public SpriteBatchNodeChildren() { CCSize s = CCDirector.sharedDirector().getWinSize(); // parents CCSpriteBatchNode batch = CCSpriteBatchNode.batchNodeWithFile("animations/images/grossini", 50); addChild(batch, 0, (int)kTags.kTagSpriteBatchNode); CCSpriteFrameCache.sharedSpriteFrameCache().addSpriteFramesWithFile("animations/grossini"); CCSprite sprite1 = CCSprite.spriteWithSpriteFrameName("grossini_dance_01.png"); sprite1.position = (new CCPoint(s.width / 3, s.height / 2)); CCSprite sprite2 = CCSprite.spriteWithSpriteFrameName("grossini_dance_02.png"); sprite2.position = (new CCPoint(50, 50)); CCSprite sprite3 = CCSprite.spriteWithSpriteFrameName("grossini_dance_03.png"); sprite3.position = (new CCPoint(-50, -50)); batch.addChild(sprite1); sprite1.addChild(sprite2); sprite1.addChild(sprite3); // BEGIN NEW CODE List <CCSpriteFrame> animFrames = new List <CCSpriteFrame>(); string str = ""; for (int i = 1; i < 15; i++) { string temp = ""; if (i < 10) { temp = "0" + i; } else { temp = i.ToString(); } str = string.Format("grossini_dance_{0}.png", temp); CCSpriteFrame frame = CCSpriteFrameCache.sharedSpriteFrameCache().spriteFrameByName(str); animFrames.Add(frame); } CCAnimation animation = CCAnimation.animationWithFrames(animFrames, 0.2f); sprite1.runAction(CCRepeatForever.actionWithAction(CCAnimate.actionWithAnimation(animation, false))); // END NEW CODE CCActionInterval action = CCMoveBy.actionWithDuration(2, new CCPoint(200, 0)); CCActionInterval action_back = (CCActionInterval)action.reverse(); CCActionInterval action_rot = CCRotateBy.actionWithDuration(2, 360); CCActionInterval action_s = CCScaleBy.actionWithDuration(2, 2); CCActionInterval action_s_back = (CCActionInterval)action_s.reverse(); CCActionInterval seq2 = (CCActionInterval)action_rot.reverse(); sprite2.runAction(CCRepeatForever.actionWithAction(seq2)); sprite1.runAction((CCAction)(CCRepeatForever.actionWithAction(action_rot))); sprite1.runAction((CCAction)(CCRepeatForever.actionWithAction((CCActionInterval)(CCSequence.actions(action, action_back))))); sprite1.runAction((CCAction)(CCRepeatForever.actionWithAction((CCActionInterval)(CCSequence.actions(action_s, action_s_back))))); }
protected override void OnHandlePropTypeSpriteFrame(CCNode node, CCNode parent, string propertyName, CCSpriteFrame spriteFrame, CCBReader reader) { if (propertyName == PROPERTY_BACKGROUNDSPRITEFRAME_NORMAL) { if (spriteFrame != null) { ((CCControlButton)node).SetBackgroundSpriteFrameForState(spriteFrame, CCControlState.Normal); } } else if (propertyName == PROPERTY_BACKGROUNDSPRITEFRAME_HIGHLIGHTED) { if (spriteFrame != null) { ((CCControlButton)node).SetBackgroundSpriteFrameForState(spriteFrame, CCControlState.Highlighted); } } else if (propertyName == PROPERTY_BACKGROUNDSPRITEFRAME_DISABLED) { if (spriteFrame != null) { ((CCControlButton)node).SetBackgroundSpriteFrameForState(spriteFrame, CCControlState.Disabled); } } else { base.OnHandlePropTypeSpriteFrame(node, parent, propertyName, spriteFrame, reader); } }
public AnimationCache() { var frameCache = CCSpriteFrameCache.SharedSpriteFrameCache; frameCache.AddSpriteFramesWithFile("animations/grossini.plist"); frameCache.AddSpriteFramesWithFile("animations/grossini_gray.plist"); frameCache.AddSpriteFramesWithFile("animations/grossini_blue.plist"); // // create animation "dance" // var animFrames = new List <CCSpriteFrame>(15); string str = ""; for (int i = 1; i < 15; i++) { str = string.Format("grossini_dance_{0:00}.png", i); CCSpriteFrame frame = CCSpriteFrameCache.SharedSpriteFrameCache.SpriteFrameByName(str); animFrames.Add(frame); } CCAnimation animation = new CCAnimation(animFrames, 0.2f); // Add an animation to the Cache CCAnimationCache.SharedAnimationCache.AddAnimation(animation, "dance"); // // create animation "dance gray" // animFrames.Clear(); for (int i = 1; i < 15; i++) { str = String.Format("grossini_dance_gray_{0:00}.png", i); CCSpriteFrame frame = CCSpriteFrameCache.SharedSpriteFrameCache.SpriteFrameByName(str); animFrames.Add(frame); } animation = new CCAnimation(animFrames, 0.2f); // Add an animation to the Cache CCAnimationCache.SharedAnimationCache.AddAnimation(animation, "dance_gray"); // // create animation "dance blue" // animFrames.Clear(); for (int i = 1; i < 4; i++) { str = String.Format("grossini_blue_{0:00}.png", i); CCSpriteFrame frame = CCSpriteFrameCache.SharedSpriteFrameCache.SpriteFrameByName(str); animFrames.Add(frame); } animation = new CCAnimation(animFrames, 0.2f); // Add an animation to the Cache CCAnimationCache.SharedAnimationCache.AddAnimation(animation, "dance_blue"); CCAnimationCache animCache = CCAnimationCache.SharedAnimationCache; CCAnimation normal = animCache.AnimationByName("dance"); normal.RestoreOriginalFrame = true; CCAnimation dance_grey = animCache.AnimationByName("dance_gray"); dance_grey.RestoreOriginalFrame = true; CCAnimation dance_blue = animCache.AnimationByName("dance_blue"); dance_blue.RestoreOriginalFrame = true; CCAnimate animN = new CCAnimate(normal); CCAnimate animG = new CCAnimate(dance_grey); CCAnimate animB = new CCAnimate(dance_blue); CCFiniteTimeAction seq = CCSequence.FromActions(animN, animG, animB); // create an sprite without texture CCSprite grossini = new CCSprite(); grossini.DisplayFrame = frameCache.SpriteFrameByName("grossini_dance_01.png"); CCSize winSize = CCDirector.SharedDirector.WinSize; grossini.Position = (new CCPoint(winSize.Width / 2, winSize.Height / 2)); AddChild(grossini); // run the animation grossini.RunAction(seq); }
protected override void OnHandlePropTypeSpriteFrame(CCNode node, CCNode parent, string propertyName, CCSpriteFrame spriteFrame, CCBReader reader) { if (propertyName == PROPERTY_BACKGROUNDSPRITEFRAME_NORMAL) { if (spriteFrame != null) { ((CCControlButton) node).SetBackgroundSpriteFrameForState(spriteFrame, CCControlState.Normal); } } else if (propertyName == PROPERTY_BACKGROUNDSPRITEFRAME_HIGHLIGHTED) { if (spriteFrame != null) { ((CCControlButton) node).SetBackgroundSpriteFrameForState(spriteFrame, CCControlState.Highlighted); } } else if (propertyName == PROPERTY_BACKGROUNDSPRITEFRAME_DISABLED) { if (spriteFrame != null) { ((CCControlButton) node).SetBackgroundSpriteFrameForState(spriteFrame, CCControlState.Disabled); } } else { base.OnHandlePropTypeSpriteFrame(node, parent, propertyName, spriteFrame, reader); } }
// Init calls that are called externally for objects that are already instantiated internal void InitWithSpriteFrame(CCSpriteFrame spriteFrame) { var sprite = new CCSprite(spriteFrame); if (spriteFrame != null && spriteFrame.Texture != null) { UpdateWithSprite(sprite, spriteFrame.TextureRectInPixels, spriteFrame.IsRotated, spriteFrame.OffsetInPixels, spriteFrame.OriginalSizeInPixels, capInsets); } }
public SpriteFrameTest() { CCSpriteFrameCache cache = CCSpriteFrameCache.SharedSpriteFrameCache; cache.AddSpriteFrames("animations/grossini.plist"); cache.AddSpriteFrames("animations/grossini_gray.plist", "animations/grossini_gray"); cache.AddSpriteFrames("animations/grossini_blue.plist", "animations/grossini_blue"); var animFrames = new List <CCSpriteFrame>(15); string str = ""; for (int i = 1; i < 15; i++) { str = string.Format("grossini_dance_{0:00}.png", i); CCSpriteFrame frame = cache[str]; animFrames.Add(frame); } animation = new CCAnimation(animFrames, 0.3f); var moreFrames = new List <CCSpriteFrame>(20); for (int i = 1; i < 15; i++) { string temp; str = string.Format("grossini_dance_gray_{0:00}.png", i); CCSpriteFrame frame = cache[str]; moreFrames.Add(frame); } for (int i = 1; i < 5; i++) { str = string.Format("grossini_blue_{0:00}.png", i); CCSpriteFrame frame = cache[str]; moreFrames.Add(frame); } // append frames from another batch moreFrames.AddRange(animFrames); animMixed = new CCAnimation(moreFrames, 0.3f); CCSprite spritebatch = new CCSprite("animations/grossini"); sprite1 = new CCSprite("grossini_dance_01.png"); AddChild(sprite1); // to test issue #732, uncomment the following line sprite1.FlipX = false; sprite1.FlipY = false; // Animation using standard Sprite sprite2 = new CCSprite("grossini_dance_01.png"); AddChild(sprite2); // to test issue #732, uncomment the following line sprite2.FlipX = false; sprite2.FlipY = false; }
public static CCSpriteFrame GetSpriteFrame(this ResourceType resourceType) { var rect = new CCRect(0, 0, 32, 32); switch (resourceType) { case Barrel: rect = rect.Add(new CCPoint(32 * 0, 32 * 0)); break; case Copper: rect = rect.Add(new CCPoint(32 * 1, 32 * 0)); break; case Diamond: rect = rect.Add(new CCPoint(32 * 2, 32 * 0)); break; case PureWater: rect = rect.Add(new CCPoint(32 * 3, 32 * 0)); break; case Water: rect = rect.Add(new CCPoint(32 * 3, 32 * 0)); break; case Brick: rect = rect.Add(new CCPoint(32 * 0, 32 * 1)); break; case Gold: rect = rect.Add(new CCPoint(32 * 1, 32 * 1)); break; case Tools: rect = rect.Add(new CCPoint(32 * 2, 32 * 1)); break; case WaterBarrel: rect = rect.Add(new CCPoint(32 * 3, 32 * 1)); break; case Circuit: rect = rect.Add(new CCPoint(32 * 0, 32 * 2)); break; case Iron: rect = rect.Add(new CCPoint(32 * 1, 32 * 2)); break; case Wood: rect = rect.Add(new CCPoint(32 * 2, 32 * 2)); break; case Glas: rect = rect.Add(new CCPoint(32 * 3, 32 * 2)); break; case Coal: rect = rect.Add(new CCPoint(32 * 0, 32 * 3)); break; case Paper: rect = rect.Add(new CCPoint(32 * 1, 32 * 3)); break; case Pottasche: rect = rect.Add(new CCPoint(32 * 2, 32 * 3)); break; case Sand: rect = rect.Add(new CCPoint(32 * 0, 32 * 4)); break; default: rect = rect.Add(new CCPoint(32 * 3, 32 * 3)); break; } var ccSpriteFrame = new CCSpriteFrame(new CCTexture2D("resourceSS"), rect); return(ccSpriteFrame); }
public SpriteBatchNodeOffsetAnchorScale() { CCSize s = CCDirector.SharedDirector.WinSize; for (int i = 0; i < 3; i++) { CCSpriteFrameCache cache = CCSpriteFrameCache.SharedSpriteFrameCache; cache.AddSpriteFramesWithFile("animations/grossini.plist"); cache.AddSpriteFramesWithFile("animations/grossini_gray.plist", "animations/grossini_gray"); // // Animation using Sprite BatchNode // CCSprite sprite = new CCSprite("grossini_dance_01.png"); sprite.Position = (new CCPoint(s.Width / 4 * (i + 1), s.Height / 2)); CCSprite point = new CCSprite("Images/r1"); point.Scale = 0.25f; point.Position = sprite.Position; AddChild(point, 200); switch (i) { case 0: sprite.AnchorPoint = new CCPoint(0, 0); break; case 1: sprite.AnchorPoint = new CCPoint(0.5f, 0.5f); break; case 2: sprite.AnchorPoint = new CCPoint(1, 1); break; } point.Position = sprite.Position; CCSpriteBatchNode spritesheet = new CCSpriteBatchNode("animations/grossini"); AddChild(spritesheet); var animFrames = new List <CCSpriteFrame>(14); string str = ""; for (int k = 0; k < 14; k++) { string temp = ""; if (k + 1 < 10) { temp = "0" + (k + 1); } else { temp = (k + 1).ToString(); } str = string.Format("grossini_dance_{0}.png", temp); CCSpriteFrame frame = cache.SpriteFrameByName(str); animFrames.Add(frame); } CCAnimation animation = new CCAnimation(animFrames, 0.3f); sprite.RunAction(new CCRepeatForever(new CCAnimate(animation))); CCActionInterval scale = new CCScaleBy(2, 2); CCActionInterval scale_back = (CCActionInterval)scale.Reverse(); CCActionInterval seq_scale = (CCActionInterval)(new CCSequence(scale, scale_back)); sprite.RunAction(new CCRepeatForever(seq_scale)); spritesheet.AddChild(sprite, i); //animFrames->release(); // win32 : memory leak 2010-0415 } }
internal GameObjectSprite(CCSpriteFrame spriteFrame) : base(spriteFrame) { Init(); }
public SpriteBatchNodeOffsetAnchorSkew() { CCSize s = CCDirector.SharedDirector.WinSize; for (int i = 0; i < 3; i++) { CCSpriteFrameCache cache = CCSpriteFrameCache.SharedSpriteFrameCache; cache.AddSpriteFramesWithFile("animations/grossini.plist"); cache.AddSpriteFramesWithFile("animations/grossini_gray.plist", "animations/grossini_gray"); // // Animation using Sprite batch // CCSprite sprite = new CCSprite("grossini_dance_01.png"); sprite.Position = (new CCPoint(s.Width / 4 * (i + 1), s.Height / 2)); CCSprite point = new CCSprite("Images/r1"); point.Scale = 0.25f; point.Position = sprite.Position; AddChild(point, 200); switch (i) { case 0: sprite.AnchorPoint = new CCPoint(0, 0); break; case 1: sprite.AnchorPoint = new CCPoint(0.5f, 0.5f); break; case 2: sprite.AnchorPoint = new CCPoint(1, 1); break; } point.Position = sprite.Position; CCSpriteBatchNode spritebatch = new CCSpriteBatchNode("animations/grossini"); AddChild(spritebatch); var animFrames = new List <CCSpriteFrame>(); string tmp = ""; for (int j = 0; j < 14; j++) { string temp = ""; if (j + 1 < 10) { temp = "0" + (j + 1); } else { temp = (j + 1).ToString(); } tmp = string.Format("grossini_dance_{0}.png", temp); CCSpriteFrame frame = cache.SpriteFrameByName(tmp); animFrames.Add(frame); } CCAnimation animation = new CCAnimation(animFrames, 0.3f); sprite.RunAction(new CCRepeatForever(new CCAnimate(animation))); animFrames = null; CCSkewBy skewX = new CCSkewBy(2, 45, 0); CCActionInterval skewX_back = (CCActionInterval)skewX.Reverse(); CCSkewBy skewY = new CCSkewBy(2, 0, 45); CCActionInterval skewY_back = (CCActionInterval)skewY.Reverse(); CCFiniteTimeAction seq_skew = CCSequence.FromActions(skewX, skewX_back, skewY, skewY_back); sprite.RunAction(new CCRepeatForever((CCActionInterval)seq_skew)); spritebatch.AddChild(sprite, i); } }