public static CCSize CCSizeApplyAffineTransform(CCSize size, CCAffineTransform t) { CCSize s = new CCSize(); s.width = (float)((double)t.a * size.width + (double)t.c * size.height); s.height = (float)((double)t.b * size.width + (double)t.d * size.height); return s; }
private Button resumeButton; // Button is just a custom class. Its just a layer with one menu button. public override bool init() { #region Default Code if (!base.init()) { return false; } this.m_bIsTouchEnabled = true; size = CCDirector.sharedDirector().getWinSize(); this.AddCloseButton(); this.AddLabel(); this.AddSpriteBackground(); #endregion // create new Layer. Add a Button to it. pauseLayer = CCLayerColor.layerWithColorWidthHeight(new ccColor4B(100, 0, 0, 150), 800, 480); resumeButton = new Button("Tap to Resume", this, this.resumeButtonClicked); resumeButton.position = new CCPoint(400, 240); pauseLayer.addChild(resumeButton); this.isTouchEnabled = true; return true; }
public void updateSize(CCPoint touchLocation) { CCSize s = CCDirector.SharedDirector.WinSize; CCSize newSize = new CCSize(Math.Abs(touchLocation.X - s.Width / 2) * 2, Math.Abs(touchLocation.Y - s.Height / 2) * 2); CCLayerColor l = (CCLayerColor)GetChildByTag(kTagLayer); l.ContentSize = newSize; }
public FloorLayer(Word p_Word) { base.init(); m_Size = CCDirector.sharedDirector().getWinSize(); this.isTouchEnabled = true; m_Word = p_Word; SayAction = new QuestionAction(m_Word); }
public static CCGrid3D Create(CCGridSize gridSize, CCSize size) { var pRet = new CCGrid3D(); if (pRet.InitWithSize(gridSize, size)) { return pRet; } return null; }
public void updateSize(CCTouch touch) { CCPoint touchLocation = touch.locationInView(touch.view()); touchLocation = CCDirector.sharedDirector().convertToGL(touchLocation); CCSize s = CCDirector.sharedDirector().getWinSize(); CCSize newSize = new CCSize(Math.Abs(touchLocation.x - s.width / 2) * 2, Math.Abs(touchLocation.y - s.height / 2) * 2); CCLayerColor l = (CCLayerColor)getChildByTag(kTagLayer); l.contentSize = newSize; }
/// <summary> /// creates a CCLabelTTF from a fontname, alignment, dimension and font size /// </summary> public static CCLabelTTF labelWithString(string label, CCSize dimensions, CCTextAlignment alignment, string fontName, float fontSize) { CCLabelTTF pRet = new CCLabelTTF(); if (pRet != null && pRet.initWithString(label, dimensions, alignment, fontName, fontSize)) { return pRet; } return null; }
/// <summary> /// 背景初始化 /// </summary> private void BackGroundInit(CCSize p_Size) { CCTexture2D backgroud = Media.PictureManager.GetCCTexture2DWithFile("image/BackGround"); CCSprite pSprite = CCSprite.spriteWithTexture(backgroud); // position the sprite on the center of the screen pSprite.position = new CCPoint(p_Size.width / 2, p_Size.height / 2); // add the sprite as a child to this layer this.addChild(pSprite, 0); }
public void showFont(string pFont) { CCSize s = CCDirector.SharedDirector.WinSize; var blockSize = new CCSize(s.Width / 3, 200); float fontSize = 26; RemoveChildByTag(kTagLabel1, true); RemoveChildByTag(kTagLabel2, true); RemoveChildByTag(kTagLabel3, true); RemoveChildByTag(kTagLabel4, true); CCLabelTTF top = new CCLabelTTF(pFont, pFont, 24); CCLabelTTF left = new CCLabelTTF("alignment left", pFont, fontSize, blockSize, CCTextAlignment.CCTextAlignmentLeft, FontTestScene.verticalAlignment[FontTestScene.vAlignIdx]); CCLabelTTF center = new CCLabelTTF("alignment center", pFont, fontSize, blockSize, CCTextAlignment.CCTextAlignmentCenter, FontTestScene.verticalAlignment[FontTestScene.vAlignIdx]); CCLabelTTF right = new CCLabelTTF("alignment right", pFont, fontSize, blockSize, CCTextAlignment.CCTextAlignmentRight, FontTestScene.verticalAlignment[FontTestScene.vAlignIdx]); CCLayerColor leftColor = new CCLayerColor(new CCColor4B(100, 100, 100, 255), blockSize.Width, blockSize.Height); CCLayerColor centerColor = new CCLayerColor(new CCColor4B(200, 100, 100, 255), blockSize.Width, blockSize.Height); CCLayerColor rightColor = new CCLayerColor(new CCColor4B(100, 100, 200, 255), blockSize.Width, blockSize.Height); leftColor.IgnoreAnchorPointForPosition = false; centerColor.IgnoreAnchorPointForPosition = false; rightColor.IgnoreAnchorPointForPosition = false; top.AnchorPoint = new CCPoint(0.5f, 1); left.AnchorPoint = new CCPoint(0, 0.5f); leftColor.AnchorPoint = new CCPoint(0, 0.5f); center.AnchorPoint = new CCPoint(0, 0.5f); centerColor.AnchorPoint = new CCPoint(0, 0.5f); right.AnchorPoint = new CCPoint(0, 0.5f); rightColor.AnchorPoint = new CCPoint(0, 0.5f); top.Position = new CCPoint(s.Width / 2, s.Height - 20); left.Position = new CCPoint(0, s.Height / 2); leftColor.Position = left.Position; center.Position = new CCPoint(blockSize.Width, s.Height / 2); centerColor.Position = center.Position; right.Position = new CCPoint(blockSize.Width * 2, s.Height / 2); rightColor.Position = right.Position; AddChild(leftColor, -1); AddChild(left, 0, kTagLabel1); AddChild(rightColor, -1); AddChild(right, 0, kTagLabel2); AddChild(centerColor, -1); AddChild(center, 0, kTagLabel3); AddChild(top, 0, kTagLabel4); }
protected override void OnHandlePropTypeSize(CCNode node, CCNode parent, string propertyName, CCSize pSize, CCBReader reader) { if (propertyName == PROPERTY_CONTENTSIZE) { ((CCScrollView) node).ViewSize = pSize; } else { base.OnHandlePropTypeSize(node, parent, propertyName, pSize, reader); } }
////////////////////////////////////////////////////////////////////////// // initialize ////////////////////////////////////////////////////////////////////////// /** initializes the CCTextFieldTTF with a font name, alignment, dimension and font size */ public bool initWithPlaceHolder(string placeholder, CCSize dimensions, CCTextAlignment alignment, string fontName, float fontSize) { if (placeholder != null) { //CC_SAFE_DELETE(m_pPlaceHolder); m_pPlaceHolder = placeholder; } return cclabelttf.initWithString(m_pPlaceHolder, dimensions, alignment, fontName, fontSize); //throw new NotFiniteNumberException(); }
public bool InitWithTileFile(string tile, string mapFile, int tileWidth, int tileHeight) { LoadTgAfile(mapFile); CalculateItemsToRender(); if (base.InitWithTileFile(tile, tileWidth, tileHeight, m_nItemsToRender)) { m_tColor = CCTypes.CCWhite; m_pPosToAtlasIndex = new Dictionary<CCGridSize, int>(); UpdateAtlasValues(); ContentSize = new CCSize(m_pTGAInfo.width * m_uItemWidth, m_pTGAInfo.height * m_uItemHeight); return true; } return false; }
/// <summary> /// initializes the CCLabelTTF with a font name, alignment, dimension and font size /// </summary> public bool initWithString(string label, CCSize dimensions, CCTextAlignment alignment, string fontName, float fontSize) { Debug.Assert(label != null); if (init()) { m_tDimensions = new CCSize(dimensions.width * CCDirector.sharedDirector().ContentScaleFactor, dimensions.height * CCDirector.sharedDirector().ContentScaleFactor); m_eAlignment = alignment; m_pFontName = fontName; m_fFontSize = fontSize * CCDirector.sharedDirector().ContentScaleFactor; this.setString(label); return true; } return false; }
//char * description(); ////////////////////////////////////////////////////////////////////////// // static constructor ////////////////////////////////////////////////////////////////////////// /** creates a CCTextFieldTTF from a fontname, alignment, dimension and font size */ public static CCTextFieldTTF textFieldWithPlaceHolder(string placeholder, CCSize dimensions, CCTextAlignment alignment, string fontName, float fontSize) { CCTextFieldTTF pRet = new CCTextFieldTTF(); if (pRet != null && pRet.initWithPlaceHolder("", dimensions, alignment, fontName, fontSize)) { //pRet->autorelease(); if (placeholder != null) { pRet.PlaceHolder = placeholder; } return pRet; } //CC_SAFE_DELETE(pRet); return null; throw new NotFiniteNumberException(); }
public static CCSize CCSizeFromString(string pszContent) { CCSize ret = new CCSize(); do { List<string> strs = new List<string>(); if (!CCUtils.SplitWithForm(pszContent, strs)) break; float width = CCUtils.CCParseFloat(strs[0]); float height = CCUtils.CCParseFloat(strs[1]); ret = new CCSize(width, height); } while (false); return ret; }
/// <summary> /// 获取均分屏幕的尺寸 默认屏幕宽800 高480 /// </summary> /// <param name="p_Width">800</param> /// <param name="p_Height">480</param> /// <param name="p_AverageNumber">均分</param> /// <returns></returns> public static CCSize MathSize(Int32 p_Width, Int32 p_Height, Int32 p_AverageNumber,Int32 p_While) { CCSize size = new CCSize(); size.width = p_Width / ((p_AverageNumber / 2)==1?2:(p_AverageNumber / 2)); if (p_AverageNumber / 2 > 1) { size.height = p_Height / 2; } else { size.height = p_Height; } size.width -= p_While*2; size.height -= p_While * 2; return size; }
public static CCPoint GetAbsolutePosition(CCPoint pt, kCCBPositionType nType, CCSize containerSize, string pPropName) { CCPoint absPt = new CCPoint(0, 0); if (nType == kCCBPositionType.kCCBPositionTypeRelativeBottomLeft) { absPt = pt; } else if (nType == kCCBPositionType.kCCBPositionTypeRelativeTopLeft) { absPt.X = pt.X; absPt.Y = containerSize.Height - pt.Y; } else if (nType == kCCBPositionType.kCCBPositionTypeRelativeTopRight) { absPt.X = containerSize.Width - pt.X; absPt.Y = containerSize.Height - pt.Y; } else if (nType == kCCBPositionType.kCCBPositionTypeRelativeBottomRight) { absPt.X = containerSize.Width - pt.X; absPt.Y = pt.Y; } else if (nType == kCCBPositionType.kCCBPositionTypePercent) { absPt.X = (int) (containerSize.Width * pt.X / 100.0f); absPt.Y = (int) (containerSize.Height * pt.Y / 100.0f); } else if (nType == kCCBPositionType.kCCBPositionTypeMultiplyResolution) { float resolutionScale = CCBReader.ResolutionScale; absPt.X = pt.X * resolutionScale; absPt.Y = pt.Y * resolutionScale; } return absPt; }
/// <summary> /// Implement CCDirector and CCScene init code here. /// </summary> /// <returns> /// true Initialize success, app continue. /// false Initialize failed, app terminate. /// </returns> public override bool applicationDidFinishLaunching() { //initialize director CCDirector pDirector = CCDirector.sharedDirector(); pDirector.setOpenGLView(); //turn on display FPS pDirector.DisplayFPS = true; // pDirector->setDeviceOrientation(kCCDeviceOrientationLandscapeLeft); // set FPS. the default value is 1.0/60 if you don't call this pDirector.animationInterval = 1.0 / 60; screenSize = CCDirector.sharedDirector().getWinSize(); // create a scene. it's an autorelease object CCScene loadScene = new StartScene(game); //run pDirector.runWithScene(loadScene); return true; }
public LabelTTFTest() { var blockSize = new CCSize(200, 160); CCSize s = CCDirector.SharedDirector.WinSize; CCLayerColor colorLayer = new CCLayerColor(new CCColor4B(100, 100, 100, 255), blockSize.Width, blockSize.Height); colorLayer.AnchorPoint = new CCPoint(0, 0); colorLayer.Position = new CCPoint((s.Width - blockSize.Width) / 2, (s.Height - blockSize.Height) / 2); AddChild(colorLayer); CCMenuItemFont.FontSize = 30; CCMenu menu = new CCMenu( new CCMenuItemFont("Left", setAlignmentLeft), new CCMenuItemFont("Center", setAlignmentCenter), new CCMenuItemFont("Right", setAlignmentRight) ); menu.AlignItemsVerticallyWithPadding(4); menu.Position = new CCPoint(50, s.Height / 2 - 20); AddChild(menu); menu = new CCMenu( new CCMenuItemFont("Top", setAlignmentTop), new CCMenuItemFont("Middle", setAlignmentMiddle), new CCMenuItemFont("Bottom", setAlignmentBottom) ); menu.AlignItemsVerticallyWithPadding(4); menu.Position = new CCPoint(s.Width - 50, s.Height / 2 - 20); AddChild(menu); m_plabel = null; m_eHorizAlign = CCTextAlignment.CCTextAlignmentLeft; m_eVertAlign = CCVerticalTextAlignment.CCVerticalTextAlignmentTop; updateAlignment(); }
///<summary> /// Initializes a texture from a string with dimensions, alignment, font name and font size /// </summary> public bool initWithString(string text, CCSize dimensions, CCTextAlignment alignment, string fontName, float fontSize, Color fgColor, Color bgColor) { if (dimensions.width < 0 || dimensions.height < 0) { return false; } if (string.IsNullOrEmpty(text)) { return false; } SpriteFont font = null; try { font = CCApplication.sharedApplication().content.Load<SpriteFont>(@"fonts/" + fontName); } catch (Exception) { if (fontName.EndsWith(".spritefont", StringComparison.OrdinalIgnoreCase)) { fontName = fontName.Substring(0, fontName.Length - 11); font = CCApplication.sharedApplication().content.Load<SpriteFont>(@"fonts/" + fontName); } } if (CCSize.CCSizeEqualToSize(dimensions, new CCSize())) { Vector2 temp = font.MeasureString(text); dimensions.width = temp.X; dimensions.height = temp.Y; } Vector2 origin; if (CCTextAlignment.CCTextAlignmentRight == alignment) { origin = new Vector2(-(dimensions.width - font.MeasureString(text).X), 0); } else if (CCTextAlignment.CCTextAlignmentCenter == alignment) { origin = new Vector2(-(dimensions.width - font.MeasureString(text).X) / 2.0f, 0); } else { origin = new Vector2(0, 0); } float scale = 1.0f;//need refer fontSize; try { CCApplication app = CCApplication.sharedApplication(); //* for render to texture RenderTarget2D renderTarget = new RenderTarget2D(app.graphics.GraphicsDevice, (int)dimensions.width, (int)dimensions.height); app.graphics.GraphicsDevice.SetRenderTarget(renderTarget); app.graphics.GraphicsDevice.Clear(bgColor); app.spriteBatch.Begin(); app.spriteBatch.DrawString(font, text, new Vector2(0, 0), fgColor, 0.0f, origin, scale, SpriteEffects.None, 0.0f); app.spriteBatch.End(); app.graphics.GraphicsDevice.SetRenderTarget(null); // to copy the rendered target data to a plain texture(to the memory) Color[] colors1D = new Color[renderTarget.Width * renderTarget.Height]; renderTarget.GetData(colors1D); texture2D = new Texture2D(app.GraphicsDevice, renderTarget.Width, renderTarget.Height); texture2D.SetData(colors1D); return initWithTexture(texture2D); } catch (Exception ex) { System.Diagnostics.Debug.WriteLine(ex.ToString()); } return (false); }
public override void initScenes() { CCSize winSize = CCDirector.sharedDirector().getWinSize(); this.m_pInScene.position = new CCPoint(0f, winSize.height); }
public void reshapeProjection(CCSize newWindowSize) { this.m_obWinSizeInPoints = CCApplication.sharedApplication().getSize(); this.m_obWinSizeInPixels = new CCSize(this.m_obWinSizeInPoints.width * this.m_fContentScaleFactor, this.m_obWinSizeInPoints.height * this.m_fContentScaleFactor); this.Projection = this.m_eProjection; }
/// <summary> /// Initializes a CCSpriteFrame with a texture, rect, rotated, offset and originalSize in pixels. /// The originalSize is the size in points of the frame before being trimmed. /// </summary> public bool initWithTexture(CCTexture2D pobTexture, CCRect rect, bool rotated, CCPoint offset, CCSize originalSize) { m_pobTexture = pobTexture; m_obRectInPixels = rect; m_obRect = ccMacros.CC_RECT_PIXELS_TO_POINTS(rect); m_bRotated = rotated; m_obOffsetInPixels = offset; m_obOriginalSizeInPixels = originalSize; return(true); }
public void ReshapeProjection(CCSize newWindowSize) { m_obWinSizeInPoints = DrawManager.Size; m_obWinSizeInPixels = new CCSize(m_obWinSizeInPoints.Width * m_fContentScaleFactor, m_obWinSizeInPoints.Height * m_fContentScaleFactor); Projection = m_eProjection; }
public override void startWithTarget(CCNode pTarget) { base.startWithTarget(pTarget); m_winSize = CCDirector.sharedDirector().winSizeInPixels; }
public override void blit() { int n = m_sGridSize.x * m_sGridSize.y; // Default GL states: GL_TEXTURE_2D, GL_VERTEX_ARRAY, GL_COLOR_ARRAY, GL_TEXTURE_COORD_ARRAY // Needed states: GL_TEXTURE_2D, GL_VERTEX_ARRAY, GL_TEXTURE_COORD_ARRAY // Unneeded states: GL_COLOR_ARRAY //glDisableClientState(GL_COLOR_ARRAY); //glVertexPointer(3, GL_FLOAT, 0, m_pVertices); //glTexCoordPointer(2, GL_FLOAT, 0, m_pTexCoordinates); //glDrawElements(GL_TRIANGLES, (GLsizei)n * 6, GL_UNSIGNED_SHORT, m_pIndices); //// restore default GL state //glEnableClientState(GL_COLOR_ARRAY); CCApplication app = CCApplication.sharedApplication(); CCSize size = CCDirector.sharedDirector().getWinSize(); //app.basicEffect.World = app.worldMatrix *TransformUtils.CGAffineToMatrix( this.nodeToWorldTransform()); app.basicEffect.Texture = this.m_pTexture.getTexture2D(); app.basicEffect.TextureEnabled = true; app.GraphicsDevice.BlendState = BlendState.AlphaBlend; app.basicEffect.VertexColorEnabled = true; List <VertexPositionColorTexture> vertices = new List <VertexPositionColorTexture>(); for (int i = 0; i < n; i++) { ccQuad3 quad = this.m_pVertices[i]; ccQuad2 texQuad = this.m_pTexCoordinates[i]; if (quad != null) { VertexPositionColorTexture vt = new VertexPositionColorTexture(); vt.Position = new Vector3(quad.bl.x, quad.bl.y, quad.bl.z); vt.Color = Color.White; vt.TextureCoordinate = new Vector2(texQuad.bl.x, texQuad.bl.y); vertices.Add(vt); vt = new VertexPositionColorTexture(); vt.Position = new Vector3(quad.br.x, quad.br.y, quad.br.z); vt.Color = Color.White; vt.TextureCoordinate = new Vector2(texQuad.br.x, texQuad.br.y); vertices.Add(vt); vt = new VertexPositionColorTexture(); vt.Position = new Vector3(quad.tl.x, quad.tl.y, quad.tl.z); vt.Color = Color.White; vt.TextureCoordinate = new Vector2(texQuad.tl.x, texQuad.tl.y); vertices.Add(vt); vt = new VertexPositionColorTexture(); vt.Position = new Vector3(quad.tr.x, quad.tr.y, quad.tr.z); vt.Color = Color.White; vt.TextureCoordinate = new Vector2(texQuad.tr.x, texQuad.tr.y); vertices.Add(vt); } } foreach (var pass in app.basicEffect.CurrentTechnique.Passes) { pass.Apply(); app.GraphicsDevice.DrawUserIndexedPrimitives <VertexPositionColorTexture>( PrimitiveType.TriangleList, vertices.ToArray(), 0, vertices.Count, this.m_pIndices, 0, this.m_pIndices.Length / 3); } }
/// <summary> /// returns the action that will be performed by the incomming and outgoing scene /// </summary> /// <returns></returns> public override CCActionInterval action() { CCSize s = Director.SharedDirector.DesignSize; return(CCMoveBy.actionWithDuration(m_fDuration, new CCPoint(0, s.Height - 0.5f))); }
/// <summary> /// initializes the scenes /// </summary> public override void initScenes() { CCSize s = Director.SharedDirector.DesignSize; m_pInScene.Position = new CCPoint(0, -(s.Height - 0.5f)); }
// the XML parser calls here with all the elements public void startElement(object ctx, string name, string[] atts) { CCTMXMapInfo pTMXMapInfo = this; string elementName = name; Dictionary <string, string> attributeDict = new Dictionary <string, string>(); if (atts != null && atts[0] != null) { for (int i = 0; i + 1 < atts.Length; i += 2) { string key = atts[i]; string value = atts[i + 1]; attributeDict.Add(key, value); } } if (elementName == "map") { string version = attributeDict["version"]; if (version != "1.0") { CCLog.Log("cocos2d: TMXFormat: Unsupported TMX version: {0}", version); } string orientationStr = attributeDict["orientation"]; if (orientationStr == "orthogonal") { pTMXMapInfo.Orientation = (int)(CCTMXOrientatio.CCTMXOrientationOrtho); } else if (orientationStr == "isometric") { pTMXMapInfo.Orientation = (int)(CCTMXOrientatio.CCTMXOrientationIso); } else if (orientationStr == "hexagonal") { pTMXMapInfo.Orientation = (int)(CCTMXOrientatio.CCTMXOrientationHex); } else { CCLog.Log("cocos2d: TMXFomat: Unsupported orientation: {0}", pTMXMapInfo.Orientation); } CCSize sMapSize = new CCSize(); sMapSize.width = ccUtils.ccParseFloat(attributeDict["width"]); sMapSize.height = ccUtils.ccParseFloat(attributeDict["height"]); pTMXMapInfo.MapSize = sMapSize; CCSize sTileSize = new CCSize(); sTileSize.width = ccUtils.ccParseFloat(attributeDict["tilewidth"]); sTileSize.height = ccUtils.ccParseFloat(attributeDict["tileheight"]); pTMXMapInfo.TileSize = sTileSize; // The parent element is now "map" pTMXMapInfo.ParentElement = (int)TMXProperty.TMXPropertyMap; } else if (elementName == "tileset") { // If this is an external tileset then start parsing that if (attributeDict.Keys.Contains("source")) { string externalTilesetFilename = attributeDict["source"]; externalTilesetFilename = CCFileUtils.fullPathFromRelativeFile(externalTilesetFilename, pTMXMapInfo.TMXFileName); pTMXMapInfo.parseXMLFile(externalTilesetFilename); } else { CCTMXTilesetInfo tileset = new CCTMXTilesetInfo(); tileset.m_sName = attributeDict["name"]; tileset.m_uFirstGid = ccUtils.ccParseInt(attributeDict["firstgid"]); if (attributeDict.Keys.Contains("spacing")) { tileset.m_uSpacing = ccUtils.ccParseInt(attributeDict["spacing"]); } if (attributeDict.Keys.Contains("margin")) { tileset.m_uMargin = ccUtils.ccParseInt(attributeDict["margin"]); } CCSize s = new CCSize(); s.width = ccUtils.ccParseFloat(attributeDict["tilewidth"]); s.height = ccUtils.ccParseFloat(attributeDict["tileheight"]); tileset.m_tTileSize = s; pTMXMapInfo.Tilesets.Add(tileset); } } else if (elementName == "tile") { CCTMXTilesetInfo info = pTMXMapInfo.Tilesets.LastOrDefault(); Dictionary <string, string> dict = new Dictionary <string, string>(); pTMXMapInfo.ParentGID = (info.m_uFirstGid + ccUtils.ccParseInt(attributeDict["id"])); pTMXMapInfo.TileProperties.Add(pTMXMapInfo.ParentGID, dict); pTMXMapInfo.ParentElement = (int)TMXProperty.TMXPropertyTile; } else if (elementName == "layer") { CCTMXLayerInfo layer = new CCTMXLayerInfo(); layer.m_sName = attributeDict["name"]; CCSize s = new CCSize(); s.width = ccUtils.ccParseFloat(attributeDict["width"]); s.height = ccUtils.ccParseFloat(attributeDict["height"]); layer.m_tLayerSize = s; layer.m_pTiles = new int[(int)s.width * (int)s.height]; if (attributeDict.Keys.Contains("visible")) { string visible = attributeDict["visible"]; layer.m_bVisible = !(visible == "0"); } else { layer.m_bVisible = true; } if (attributeDict.Keys.Contains("opacity")) { string opacity = attributeDict["opacity"]; layer.m_cOpacity = (byte)(255 * ccUtils.ccParseFloat(opacity)); } else { layer.m_cOpacity = 255; } float x = attributeDict.Keys.Contains("x") ? ccUtils.ccParseFloat(attributeDict["x"]) : 0; float y = attributeDict.Keys.Contains("y") ? ccUtils.ccParseFloat(attributeDict["y"]) : 0; layer.m_tOffset = new CCPoint(x, y); pTMXMapInfo.Layers.Add(layer); // The parent element is now "layer" pTMXMapInfo.ParentElement = (int)TMXProperty.TMXPropertyLayer; } else if (elementName == "objectgroup") { CCTMXObjectGroup objectGroup = new CCTMXObjectGroup(); objectGroup.GroupName = attributeDict["name"]; CCPoint positionOffset = new CCPoint(); if (attributeDict.ContainsKey("x")) { positionOffset.x = ccUtils.ccParseFloat(attributeDict["x"]) * pTMXMapInfo.TileSize.width; } if (attributeDict.ContainsKey("y")) { positionOffset.y = ccUtils.ccParseFloat(attributeDict["y"]) * pTMXMapInfo.TileSize.height; } objectGroup.PositionOffset = positionOffset; pTMXMapInfo.ObjectGroups.Add(objectGroup); // The parent element is now "objectgroup" pTMXMapInfo.ParentElement = (int)TMXProperty.TMXPropertyObjectGroup; } else if (elementName == "image") { CCTMXTilesetInfo tileset = pTMXMapInfo.Tilesets.LastOrDefault(); // build full path string imagename = attributeDict["source"]; tileset.m_sSourceImage = CCFileUtils.fullPathFromRelativeFile(imagename, pTMXMapInfo.TMXFileName); } else if (elementName == "data") { string encoding = attributeDict.ContainsKey("encoding") ? attributeDict["encoding"] : ""; string compression = attributeDict.ContainsKey("compression") ? attributeDict["compression"] : ""; if (encoding == "base64") { int layerAttribs = pTMXMapInfo.LayerAttribs; pTMXMapInfo.LayerAttribs = layerAttribs | (int)TMXLayerAttrib.TMXLayerAttribBase64; pTMXMapInfo.StoringCharacters = true; if (compression == "gzip") { layerAttribs = pTMXMapInfo.LayerAttribs; pTMXMapInfo.LayerAttribs = layerAttribs | (int)TMXLayerAttrib.TMXLayerAttribGzip; } else if (compression == "zlib") { layerAttribs = pTMXMapInfo.LayerAttribs; pTMXMapInfo.LayerAttribs = layerAttribs | (int)TMXLayerAttrib.TMXLayerAttribZlib; } Debug.Assert(compression == "" || compression == "gzip" || compression == "zlib", "TMX: unsupported compression method"); } Debug.Assert(pTMXMapInfo.LayerAttribs != (int)TMXLayerAttrib.TMXLayerAttribNone, "TMX tile map: Only base64 and/or gzip/zlib maps are supported"); } else if (elementName == "object") { char[] buffer = new char[32]; CCTMXObjectGroup objectGroup = pTMXMapInfo.ObjectGroups.LastOrDefault(); // The value for "type" was blank or not a valid class name // Create an instance of TMXObjectInfo to store the object and its properties Dictionary <string, string> dict = new Dictionary <string, string>(); // Set the name of the object to the value for "name" string key = "name"; string value = attributeDict.ContainsKey("name") ? attributeDict["name"] : ""; dict.Add(key, value); // Assign all the attributes as key/name pairs in the properties dictionary key = "type"; value = attributeDict.ContainsKey("type") ? attributeDict["type"] : ""; dict.Add(key, value); int x = ccUtils.ccParseInt(attributeDict["x"]) + (int)objectGroup.PositionOffset.x; key = "x"; value = x.ToString(); dict.Add(key, value); int y = ccUtils.ccParseInt(attributeDict["y"]) + (int)objectGroup.PositionOffset.y; // Correct y position. (Tiled uses Flipped, cocos2d uses Standard) y = (int)(pTMXMapInfo.MapSize.height * pTMXMapInfo.TileSize.height) - y - (attributeDict.ContainsKey("height") ? ccUtils.ccParseInt(attributeDict["height"]) : 0); key = "y"; value = y.ToString(); dict.Add(key, value); key = "width"; value = attributeDict.ContainsKey("width") ? attributeDict["width"] : ""; dict.Add(key, value); key = "height"; value = attributeDict.ContainsKey("height") ? attributeDict["height"] : ""; dict.Add(key, value); // Add the object to the objectGroup objectGroup.Objects.Add(dict); // The parent element is now "object" pTMXMapInfo.ParentElement = (int)TMXProperty.TMXPropertyObject; } else if (elementName == "property") { if (pTMXMapInfo.ParentElement == (int)TMXProperty.TMXPropertyNone) { CCLog.Log("TMX tile map: Parent element is unsupported. Cannot add property named '{0}' with value '{1}'", attributeDict["name"], attributeDict["value"]); } else if (pTMXMapInfo.ParentElement == (int)TMXProperty.TMXPropertyMap) { // The parent element is the map string value = attributeDict["value"]; string key = attributeDict["name"]; pTMXMapInfo.Properties.Add(key, value); } else if (pTMXMapInfo.ParentElement == (int)TMXProperty.TMXPropertyLayer) { // The parent element is the last layer CCTMXLayerInfo layer = pTMXMapInfo.Layers.LastOrDefault(); string value = attributeDict["value"]; string key = attributeDict["name"]; // Add the property to the layer layer.Properties.Add(key, value); } else if (pTMXMapInfo.ParentElement == (int)TMXProperty.TMXPropertyObjectGroup) { // The parent element is the last object group CCTMXObjectGroup objectGroup = pTMXMapInfo.ObjectGroups.LastOrDefault(); string value = attributeDict["value"]; string key = attributeDict["name"]; objectGroup.Properties.Add(key, value); } else if (pTMXMapInfo.ParentElement == (int)TMXProperty.TMXPropertyObject) { // The parent element is the last object CCTMXObjectGroup objectGroup = pTMXMapInfo.ObjectGroups.LastOrDefault(); Dictionary <string, string> dict = objectGroup.Objects.LastOrDefault(); string propertyName = attributeDict["name"]; string propertyValue = attributeDict["value"]; dict.Add(propertyName, propertyValue); } else if (pTMXMapInfo.ParentElement == (int)TMXProperty.TMXPropertyTile) { Dictionary <string, string> dict = pTMXMapInfo.TileProperties[pTMXMapInfo.ParentGID]; string propertyName = attributeDict["name"]; string propertyValue = attributeDict["value"]; dict.Add(propertyName, propertyValue); } } if (attributeDict != null) { attributeDict = null; } }
void graphics_DeviceCreated(object sender, EventArgs e) { m_rcViewPort = new Rectangle(0, 0, graphics.GraphicsDevice.Viewport.Width, graphics.GraphicsDevice.Viewport.Height); _size = new CCSize(graphics.GraphicsDevice.Viewport.Width, graphics.GraphicsDevice.Viewport.Height); }
public override void initScenes() { CCSize s = CCDirector.sharedDirector().getWinSize(); m_pInScene.position = new CCPoint(0, s.height); }
/// <summary> /// returns the content size of the texture in points /// </summary> public CCSize getContentSize() { CCSize ret = new CCSize(); ret.width = m_tContentSize.width / ccMacros.CC_CONTENT_SCALE_FACTOR(); ret.height = m_tContentSize.height / ccMacros.CC_CONTENT_SCALE_FACTOR(); return ret; }
public CCNode() { // Only initialize the members that are not default value. m_fScaleX = 1.0f; m_fScaleY = 1.0f; m_tPosition = new CCPoint(); m_tPositionInPixels = new CCPoint(); m_bIsVisible = true; m_tAnchorPoint = new CCPoint(); m_tAnchorPointInPixels = new CCPoint(); m_tContentSize = new CCSize(); m_tContentSizeInPixels = new CCSize(); m_bIsRelativeAnchorPoint = true; m_nTag = kCCNodeTagInvalid; m_bIsTransformDirty = true; m_bIsInverseDirty = true; m_pChildren = new List<CCNode>(); #if CC_NODE_TRANSFORM_USING_AFFINE_MATRIX m_bIsTransformGLDirty = true; #endif }
public void alignItemsInColumns(params int[] columns) { int num; int[] numArray = columns; int num1 = -5; int num2 = 0; int num3 = 0; int num4 = 0; if (this.m_pChildren != null && this.m_pChildren.Count > 0) { foreach (CCNode mPChild in this.m_pChildren) { if (mPChild == null) { continue; } num = numArray[num2]; float single = mPChild.contentSize.height; num3 = (int)(((float)num3 >= single ? (float)num3 : single)); num4++; if (num4 < num) { continue; } num1 = num1 + num3 + 5; num4 = 0; num3 = 0; num2++; } } CCSize winSize = CCDirector.sharedDirector().getWinSize(); num2 = 0; num3 = 0; num = 0; float single1 = 0f; float single2 = 0f; float single3 = (float)(num1 / 2); if (this.m_pChildren != null && this.m_pChildren.Count > 0) { foreach (CCNode cCPoint in this.m_pChildren) { if (cCPoint == null) { continue; } if (num == 0) { num = numArray[num2]; if (num == 0) { throw new ArgumentException("Can not have a zero column size for a row."); } single1 = (winSize.width - 10f) / (float)num; single2 = single1 / 2f; } float single4 = cCPoint.contentSize.height * cCPoint.scaleY; num3 = (int)(((float)num3 >= single4 ? (float)num3 : single4)); cCPoint.position = new CCPoint(5f + single2 - (winSize.width - 10f) / 2f, single3 - cCPoint.contentSize.height * cCPoint.scaleY / 2f); single2 = single2 + single1; num4++; if (num4 < num) { continue; } single3 = single3 - (float)(num3 + 5); num4 = 0; num = 0; num3 = 0; num2++; } } }
public void setString(string label) { int len = label.Length; if (len > m_pTextureAtlas.TotalQuads) { m_pTextureAtlas.resizeCapacity(len); } this.children.Clear(); m_sString = label; this.updateAtlasValues(); CCSize s = new CCSize(); s.width = (float)(len * m_uItemWidth); s.height = (float)(m_uItemHeight); this.contentSizeInPixels = s; m_uQuadsToDraw = len; }
public void alignItemsInRows(params int[] rows) { int num; int[] numArray = rows; List <int> nums = new List <int>(); List <int> nums1 = new List <int>(); int num1 = -10; int num2 = -5; int num3 = 0; int num4 = 0; int num5 = 0; if (this.m_pChildren != null && this.m_pChildren.Count > 0) { foreach (CCNode mPChild in this.m_pChildren) { if (mPChild == null) { continue; } num = numArray[num3]; float single = mPChild.contentSize.width * mPChild.scaleX; num4 = (int)(((float)num4 >= single ? (float)num4 : single)); num2 = num2 + (int)(mPChild.contentSize.height * mPChild.scaleY + 5f); num5++; if (num5 < num) { continue; } nums.Add(num4); nums1.Add(num2); num1 = num1 + num4 + 10; num5 = 0; num4 = 0; num2 = -5; num3++; } } CCSize winSize = CCDirector.sharedDirector().getWinSize(); num3 = 0; num4 = 0; num = 0; float single1 = (float)(-num1 / 2); float item = 0f; if (this.m_pChildren != null && this.m_pChildren.Count > 0) { foreach (CCNode cCPoint in this.m_pChildren) { if (cCPoint == null) { continue; } if (num == 0) { num = numArray[num3]; item = (float)nums1[num3]; } float single2 = cCPoint.contentSize.width * cCPoint.scaleX; num4 = (int)(((float)num4 >= single2 ? (float)num4 : single2)); cCPoint.position = new CCPoint(single1 + (float)(nums[num3] / 2), item - winSize.height / 2f); item = item - (cCPoint.contentSize.height * cCPoint.scaleY + 10f); num5++; if (num5 < num) { continue; } single1 = single1 + (float)(num4 + 5); num5 = 0; num = 0; num4 = 0; num3++; } } }
public override void onEnter() { // todo: CCLayerColor hasn't been implemented base.onEnter(); m_tamara.removeFromParentAndCleanup(true); m_grossini.removeFromParentAndCleanup(true); m_kathia.removeFromParentAndCleanup(true); CCSize boxSize = new CCSize(100.0f, 100.0f); CCLayerColor box = CCLayerColor.layerWithColor(new ccColor4B(255, 255, 0, 255)); box.anchorPoint = new CCPoint(0, 0); box.position = new CCPoint(190, 110); box.contentSize = boxSize; CCLayerColor uL = CCLayerColor.layerWithColor(new ccColor4B(255, 0, 0, 255)); box.addChild(uL); uL.contentSize = new CCSize(markrside, markrside); uL.position = new CCPoint(0.0f, boxSize.height - markrside); uL.anchorPoint = new CCPoint(0, 0); CCLayerColor uR = CCLayerColor.layerWithColor(new ccColor4B(0, 0, 255, 255)); box.addChild(uR); uR.contentSize = new CCSize(markrside, markrside); uR.position = new CCPoint(boxSize.width - markrside, boxSize.height - markrside); uR.anchorPoint = new CCPoint(0, 0); addChild(box); CCActionInterval actionTo = CCSkewTo.actionWithDuration(2, 0.0f, 2.0f); CCActionInterval rotateTo = CCRotateTo.actionWithDuration(2, 61.0f); CCActionInterval actionScaleTo = CCScaleTo.actionWithDuration(2, -0.44f, 0.47f); CCActionInterval actionScaleToBack = CCScaleTo.actionWithDuration(2, 1.0f, 1.0f); CCActionInterval rotateToBack = CCRotateTo.actionWithDuration(2, 0); CCActionInterval actionToBack = CCSkewTo.actionWithDuration(2, 0, 0); box.runAction(CCSequence.actions(actionTo, actionToBack)); box.runAction(CCSequence.actions(rotateTo, rotateToBack)); box.runAction(CCSequence.actions(actionScaleTo, actionScaleToBack)); }
public CCSize(CCSize copy) { this.width = copy.width; this.height = copy.height; }
public CCPoint convertToUI(CCPoint obPoint) { CCSize mObWinSizeInPoints = this.m_obWinSizeInPoints; return(new CCPoint(obPoint.x, mObWinSizeInPoints.height - obPoint.y)); }
/** Quickly convert CCSize to a CCPoint * @since v0.99.1 */ public static CCPoint ccpFromSize(CCSize s) { return(ccp(s.Width, s.Height)); }
/// <summary> /// Adds multiple Sprite Frames with a dictionary. The texture will be associated with the created sprite frames. /// </summary> public void addSpriteFramesWithDictionary(Dictionary <string, Object> pobDictionary, CCTexture2D pobTexture) { /* * 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+ */ Dictionary <string, Object> metadataDict = null; if (pobDictionary.Keys.Contains("metadata")) { metadataDict = (Dictionary <string, Object>)pobDictionary["metadata"]; } Dictionary <string, Object> framesDict = null; if (pobDictionary.Keys.Contains("frames")) { framesDict = (Dictionary <string, Object>)pobDictionary["frames"]; } int format = 0; // get the format if (metadataDict != null) { format = ccUtils.ccParseInt(metadataDict["format"].ToString()); } // check the format Debug.Assert(format >= 0 && format <= 3); foreach (var key in framesDict.Keys) { Dictionary <string, Object> frameDict = framesDict[key] as Dictionary <string, Object>; CCSpriteFrame spriteFrame = new CCSpriteFrame(); if (format == 0) { float x = ccUtils.ccParseFloat(frameDict["x"].ToString()); float y = ccUtils.ccParseFloat(frameDict["y"].ToString()); float w = ccUtils.ccParseFloat(frameDict["width"].ToString()); float h = ccUtils.ccParseFloat(frameDict["height"].ToString()); float ox = ccUtils.ccParseFloat(frameDict["offsetX"].ToString()); float oy = ccUtils.ccParseFloat(frameDict["offsetY"].ToString()); int ow = ccUtils.ccParseInt(frameDict["originalWidth"].ToString()); int oh = ccUtils.ccParseInt(frameDict["originalHeight"].ToString()); // 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. Regenrate the .plist"); } // abs ow/oh ow = Math.Abs(ow); oh = Math.Abs(oh); // create frame spriteFrame = new CCSpriteFrame(); spriteFrame.initWithTexture(pobTexture, new CCRect(x, y, w, h), false, new CCPoint(ox, oy), new CCSize((float)ow, (float)oh) ); } else if (format == 1 || format == 2) { CCRect frame = CCNS.CCRectFromString(frameDict["frame"].ToString()); bool rotated = false; // rotation if (format == 2) { if (frameDict.Keys.Contains("rotated")) { rotated = ccUtils.ccParseInt(valueForKey("rotated", frameDict)) == 0 ? false : true; } } CCPoint offset = CCNS.CCPointFromString(valueForKey("offset", frameDict)); CCSize sourceSize = CCNS.CCSizeFromString(valueForKey("sourceSize", frameDict)); // create frame spriteFrame = new CCSpriteFrame(); spriteFrame.initWithTexture(pobTexture, frame, rotated, offset, sourceSize ); } else if (format == 3) { // get values CCSize spriteSize = CCNS.CCSizeFromString(valueForKey("spriteSize", frameDict)); CCPoint spriteOffset = CCNS.CCPointFromString(valueForKey("spriteOffset", frameDict)); CCSize spriteSourceSize = CCNS.CCSizeFromString(valueForKey("spriteSourceSize", frameDict)); CCRect textureRect = CCNS.CCRectFromString(valueForKey("textureRect", frameDict)); bool textureRotated = false; if (frameDict.Keys.Contains("textureRotated")) { textureRotated = ccUtils.ccParseInt(valueForKey("textureRotated", frameDict)) == 0 ? false : true; } // get aliases var list = frameDict["aliases"]; List <object> aliases = (frameDict["aliases"] as List <object>); string frameKey = key; foreach (var item2 in aliases) { string oneAlias = item2.ToString(); 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(frameKey)) { m_pSpriteFramesAliases.Add(frameKey, oneAlias); } } // create frame spriteFrame = new CCSpriteFrame(); spriteFrame.initWithTexture(pobTexture, new CCRect(textureRect.origin.x, textureRect.origin.y, spriteSize.width, spriteSize.height), textureRotated, spriteOffset, spriteSourceSize); } // add sprite frame if (!m_pSpriteFrames.Keys.Contains(key)) { m_pSpriteFrames.Add(key, spriteFrame); } } }
public virtual CCActionInterval action() { CCSize winSize = CCDirector.sharedDirector().getWinSize(); return(CCMoveBy.actionWithDuration(this.m_fDuration, new CCPoint(winSize.width - 0.5f, 0f))); }
/// <summary> /// initializes the scenes /// </summary> public virtual void initScenes() { CCSize s = Director.SharedDirector.DesignSize; m_pInScene.Position = new CCPoint(-(s.Width - 0.5f), 0); }
public override void onEnter() { base.onEnter(); // create a transparent color layer // in which we are going to add our rendertextures ccColor4B color = new ccColor4B(0, 0, 0, 0); CCSize size = CCDirector.sharedDirector().getWinSize(); //CCLayerColor layer = CCLayerColor.layerWithColor(color); CCLayer layer = new CCLayer(); // create the first render texture for inScene CCRenderTexture inTexture = CCRenderTexture.renderTextureWithWidthAndHeight((int)size.width, (int)size.height); if (null == inTexture) { return; } inTexture.Sprite.anchorPoint = new CCPoint(0.5f, 0.5f); inTexture.position = new CCPoint(size.width / 2, size.height / 2); inTexture.anchorPoint = new CCPoint(0.5f, 0.5f); // render inScene to its texturebuffer inTexture.begin(); m_pInScene.visit(); inTexture.end(); // create the second render texture for outScene CCRenderTexture outTexture = CCRenderTexture.renderTextureWithWidthAndHeight((int)size.width, (int)size.height); outTexture.Sprite.anchorPoint = new CCPoint(0.5f, 0.5f); outTexture.position = new CCPoint(size.width / 2, size.height / 2); outTexture.anchorPoint = new CCPoint(0.5f, 0.5f); // render outScene to its texturebuffer outTexture.begin(); m_pOutScene.visit(); outTexture.end(); // create blend functions ccBlendFunc blend1 = new ccBlendFunc(OGLES.GL_ONE, OGLES.GL_ONE); // inScene will lay on background and will not be used with alpha ccBlendFunc blend2 = new ccBlendFunc(OGLES.GL_SRC_ALPHA, OGLES.GL_ONE_MINUS_SRC_ALPHA); // we are going to blend outScene via alpha // set blendfunctions inTexture.Sprite.BlendFunc = blend1; outTexture.Sprite.BlendFunc = blend2; // add render textures to the layer layer.addChild(inTexture); layer.addChild(outTexture); // initial opacity: inTexture.Sprite.Opacity = 255; outTexture.Sprite.Opacity = 255; // create the blend action CCAction layerAction = CCSequence.actions ( CCFadeTo.actionWithDuration(m_fDuration, 0), CCCallFunc.actionWithTarget(this, (base.hideOutShowIn)), CCCallFunc.actionWithTarget(this, (base.finish)) ); //// run the blend action outTexture.Sprite.runAction(layerAction); // add the layer (which contains our two rendertextures) to the scene addChild(layer, 2, kSceneFade); }
public override void startWithTarget(CCNode pTarget) { base.startWithTarget(pTarget); this.m_winSize = CCDirector.sharedDirector().winSizeInPixels; }
/// <summary> /// returns the action that will be performed by the incomming and outgoing scene /// </summary> /// <returns></returns> public virtual CCActionInterval action() { CCSize s = Director.SharedDirector.DesignSize; return(CCMoveBy.actionWithDuration(m_fDuration, new CCPoint(s.Width - 0.5f, 0))); }
public bool initWithTexture(Texture2D texture, CCSize contentSize) { bool result = initWithTexture(texture); ContentSizeInPixels = contentSize; return (result); }
public void updateTransform() { if (this.m_bDirty) { if (!base.m_bIsVisible) { this.m_sQuad.br.vertices = this.m_sQuad.tl.vertices = this.m_sQuad.tr.vertices = this.m_sQuad.bl.vertices = new ccVertex3F(0f, 0f, 0f); this.m_pobTextureAtlas.updateQuad(this.m_sQuad, this.m_uAtlasIndex); } else { CCAffineTransform transform; if ((base.m_pParent == null) || (base.m_pParent == this.m_pobBatchNode)) { float num = -ccMacros.CC_DEGREES_TO_RADIANS(base.m_fRotation); float num2 = (float)Math.Cos((double)num); float num3 = (float)Math.Sin((double)num); transform = CCAffineTransform.CCAffineTransformMake(num2 * base.m_fScaleX, num3 * base.m_fScaleX, -num3 * base.m_fScaleY, num2 * base.m_fScaleY, base.m_tPositionInPixels.x, base.m_tPositionInPixels.y); if ((base.m_fSkewX > 0f) || (base.m_fSkewY > 0f)) { transform = CCAffineTransform.CCAffineTransformConcat(CCAffineTransform.CCAffineTransformMake(1f, (float)Math.Tan((double)ccMacros.CC_DEGREES_TO_RADIANS(base.m_fSkewY)), (float)Math.Tan((double)ccMacros.CC_DEGREES_TO_RADIANS(base.m_fSkewX)), 1f, 0f, 0f), transform); } transform = CCAffineTransform.CCAffineTransformTranslate(transform, -base.m_tAnchorPointInPixels.x, -base.m_tAnchorPointInPixels.y); } else { transform = CCAffineTransform.CCAffineTransformMakeIdentity(); ccHonorParentTransform honorParentTransform = ccHonorParentTransform.CC_HONOR_PARENT_TRANSFORM_ALL; for (CCNode node = this; ((node != null) && (node is CCSprite)) && (node != this.m_pobBatchNode); node = node.parent) { transformValues_ tv = new transformValues_(); ((CCSprite)node).getTransformValues(tv); if (!tv.visible) { this.m_sQuad.br.vertices = this.m_sQuad.tl.vertices = this.m_sQuad.tr.vertices = this.m_sQuad.bl.vertices = new ccVertex3F(0f, 0f, 0f); this.m_pobTextureAtlas.updateQuad(this.m_sQuad, this.m_uAtlasIndex); this.m_bDirty = this.m_bRecursiveDirty = false; return; } CCAffineTransform t = CCAffineTransform.CCAffineTransformMakeIdentity(); if (honorParentTransform != ((ccHonorParentTransform)0)) { t = CCAffineTransform.CCAffineTransformTranslate(t, tv.pos.x, tv.pos.y); } if (honorParentTransform != ((ccHonorParentTransform)0)) { t = CCAffineTransform.CCAffineTransformRotate(t, -ccMacros.CC_DEGREES_TO_RADIANS(tv.rotation)); } if (honorParentTransform != ((ccHonorParentTransform)0)) { t = CCAffineTransform.CCAffineTransformConcat(CCAffineTransform.CCAffineTransformMake(1f, (float)Math.Tan((double)ccMacros.CC_DEGREES_TO_RADIANS(tv.skew.y)), (float)Math.Tan((double)ccMacros.CC_DEGREES_TO_RADIANS(tv.skew.x)), 1f, 0f, 0f), t); } if (honorParentTransform != ((ccHonorParentTransform)0)) { t = CCAffineTransform.CCAffineTransformScale(t, tv.scale.x, tv.scale.y); } t = CCAffineTransform.CCAffineTransformTranslate(t, -tv.ap.x, -tv.ap.y); transform = CCAffineTransform.CCAffineTransformConcat(transform, t); honorParentTransform = ((CCSprite)node).honorParentTransform; } } CCSize size = this.m_obRectInPixels.size; float x = this.m_obOffsetPositionInPixels.x; float y = this.m_obOffsetPositionInPixels.y; float num6 = x + size.width; float num7 = y + size.height; float tx = transform.tx; float ty = transform.ty; float a = transform.a; float b = transform.b; float d = transform.d; float num13 = -transform.c; float inx = ((x * a) - (y * num13)) + tx; float iny = ((x * b) + (y * d)) + ty; float num16 = ((num6 * a) - (y * num13)) + tx; float num17 = ((num6 * b) + (y * d)) + ty; float num18 = ((num6 * a) - (num7 * num13)) + tx; float num19 = ((num6 * b) + (num7 * d)) + ty; float num20 = ((x * a) - (num7 * num13)) + tx; float num21 = ((x * b) + (num7 * d)) + ty; this.m_sQuad.bl.vertices = new ccVertex3F(inx, iny, base.m_fVertexZ); this.m_sQuad.br.vertices = new ccVertex3F(num16, num17, base.m_fVertexZ); this.m_sQuad.tl.vertices = new ccVertex3F(num20, num21, base.m_fVertexZ); this.m_sQuad.tr.vertices = new ccVertex3F(num18, num19, base.m_fVertexZ); this.m_pobTextureAtlas.updateQuad(this.m_sQuad, this.m_uAtlasIndex); this.m_bDirty = this.m_bRecursiveDirty = false; } } }
public override bool initWithTotalParticles(uint numberOfParticles) { if (base.initWithTotalParticles(numberOfParticles)) { // duration Duration = (float)eParticleShowingProperty.kCCParticleDurationInfinity; EmitterMode = (int)eParticleMode.kCCParticleModeGravity; // Gravity Mode: gravity modeA.gravity = new CCPoint(10, -10); // Gravity Mode: radial modeA.radialAccel = 0; modeA.radialAccelVar = 1; // Gravity Mode: tagential modeA.tangentialAccel = 0; modeA.tangentialAccelVar = 1; // Gravity Mode: speed of particles modeA.speed = 130; modeA.speedVar = 30; // angle Angle = -90; AngleVar = 5; // emitter position CCSize winSize = CCDirector.sharedDirector().getWinSize(); this.position = new CCPoint(winSize.width / 2, winSize.height); PosVar = new CCPoint(winSize.width / 2, 0); // life of particles Life = 4.5f; LifeVar = 0; // size, in pixels StartSize = 4.0f; StartSizeVar = 2.0f; EndSize = (float)eParticleShowingProperty.kCCParticleStartSizeEqualToEndSize; // emits per second EmissionRate = 20; // color of particles StartColor.r = 0.7f; StartColor.g = 0.8f; StartColor.b = 1.0f; StartColor.a = 1.0f; StartColorVar.r = 0.0f; StartColorVar.g = 0.0f; StartColorVar.b = 0.0f; StartColorVar.a = 0.0f; EndColor.r = 0.7f; EndColor.g = 0.8f; EndColor.b = 1.0f; EndColor.a = 0.5f; EndColorVar.r = 0.0f; EndColorVar.g = 0.0f; EndColorVar.b = 0.0f; EndColorVar.a = 0.0f; // additive this.IsBlendAdditive = false; return(true); } return(false); }
public void addSpriteFramesWithDictionary(Dictionary <string, object> pobDictionary, CCTexture2D pobTexture) { Dictionary <string, object> item = null; if (pobDictionary.Keys.Contains <string>("metadata")) { item = (Dictionary <string, object>)pobDictionary["metadata"]; } Dictionary <string, object> strs = null; if (pobDictionary.Keys.Contains <string>("frames")) { strs = (Dictionary <string, object>)pobDictionary["frames"]; } int num = 0; if (item != null) { num = ccUtils.ccParseInt(item["format"].ToString()); } foreach (string key in strs.Keys) { Dictionary <string, object> item1 = strs[key] as Dictionary <string, object>; CCSpriteFrame cCSpriteFrame = new CCSpriteFrame(); if (num == 0) { float single = ccUtils.ccParseFloat(item1["x"].ToString()); float single1 = ccUtils.ccParseFloat(item1["y"].ToString()); float single2 = ccUtils.ccParseFloat(item1["width"].ToString()); float single3 = ccUtils.ccParseFloat(item1["height"].ToString()); float single4 = ccUtils.ccParseFloat(item1["offsetX"].ToString()); float single5 = ccUtils.ccParseFloat(item1["offsetY"].ToString()); int num1 = ccUtils.ccParseInt(item1["originalWidth"].ToString()); int num2 = ccUtils.ccParseInt(item1["originalHeight"].ToString()); if (num1 == 0 || num2 == 0) { CCLog.Log("cocos2d: WARNING: originalWidth/Height not found on the CCSpriteFrame. AnchorPoint won't work as expected. Regenrate the .plist"); } num1 = Math.Abs(num1); num2 = Math.Abs(num2); cCSpriteFrame = new CCSpriteFrame(); cCSpriteFrame.initWithTexture(pobTexture, new CCRect(single, single1, single2, single3), false, new CCPoint(single4, single5), new CCSize((float)num1, (float)num2)); } else if (num == 1 || num == 2) { CCRect cCRect = CCNS.CCRectFromString(item1["frame"].ToString()); bool flag = false; if (num == 2 && item1.Keys.Contains <string>("rotated")) { flag = (ccUtils.ccParseInt(this.valueForKey("rotated", item1)) == 0 ? false : true); } CCPoint cCPoint = CCNS.CCPointFromString(this.valueForKey("offset", item1)); CCSize cCSize = CCNS.CCSizeFromString(this.valueForKey("sourceSize", item1)); cCSpriteFrame = new CCSpriteFrame(); cCSpriteFrame.initWithTexture(pobTexture, cCRect, flag, cCPoint, cCSize); } else if (num == 3) { CCSize cCSize1 = CCNS.CCSizeFromString(this.valueForKey("spriteSize", item1)); CCPoint cCPoint1 = CCNS.CCPointFromString(this.valueForKey("spriteOffset", item1)); CCSize cCSize2 = CCNS.CCSizeFromString(this.valueForKey("spriteSourceSize", item1)); CCRect cCRect1 = CCNS.CCRectFromString(this.valueForKey("textureRect", item1)); bool flag1 = false; if (item1.Keys.Contains <string>("textureRotated")) { flag1 = (ccUtils.ccParseInt(this.valueForKey("textureRotated", item1)) == 0 ? false : true); } object obj = item1["aliases"]; List <object> objs = item1["aliases"] as List <object>; string str = key; foreach (object obj1 in objs) { string str1 = obj1.ToString(); if (this.m_pSpriteFramesAliases.Keys.Contains <string>(str1) && this.m_pSpriteFramesAliases[str1] != null) { CCLog.Log("cocos2d: WARNING: an alias with name {0} already exists", new object[] { str1 }); } if (this.m_pSpriteFramesAliases.Keys.Contains <string>(str)) { continue; } this.m_pSpriteFramesAliases.Add(str, str1); } cCSpriteFrame = new CCSpriteFrame(); cCSpriteFrame.initWithTexture(pobTexture, new CCRect(cCRect1.origin.x, cCRect1.origin.y, cCSize1.width, cCSize1.height), flag1, cCPoint1, cCSize2); } if (this.m_pSpriteFrames.Keys.Contains <string>(key)) { continue; } this.m_pSpriteFrames.Add(key, cCSpriteFrame); } }
public bool UpdateWithBatchNode(CCSpriteBatchNode batchnode, CCRect rect, bool rotated, CCRect capInsets) { byte opacity = m_cOpacity; CCColor3B color = m_tColor; // Release old sprites RemoveAllChildrenWithCleanup(true); if (scale9Image != batchnode) { scale9Image = batchnode; } scale9Image.RemoveAllChildrenWithCleanup(true); m_capInsets = capInsets; // If there is no given rect if (rect.Equals(CCRect.Zero)) { // Get the texture size as original CCSize textureSize = scale9Image.TextureAtlas.Texture.ContentSize; rect = new CCRect(0, 0, textureSize.Width, textureSize.Height); } // Set the given rect's size as original size m_spriteRect = rect; m_originalSize = rect.Size; m_preferredSize = m_originalSize; m_capInsetsInternal = capInsets; // Get the image edges float l = rect.Origin.X; float t = rect.Origin.Y; float h = rect.Size.Height; float w = rect.Size.Width; // If there is no specified center region if (m_capInsetsInternal.Equals(CCRect.Zero)) { // Apply the 3x3 grid format if (rotated) { m_capInsetsInternal = new CCRect(l + h / 3, t + w / 3, w / 3, h / 3); } else { m_capInsetsInternal = new CCRect(l + w / 3, t + h / 3, w / 3, h / 3); } } // // Set up the image // if (rotated) { // Sprite frame is rotated // Centre centre = new CCSprite(); centre.InitWithTexture(scale9Image.Texture, m_capInsetsInternal, true); scale9Image.AddChild(centre, 0, (int) Positions.pCentre); // Bottom bottom = new CCSprite(); bottom.InitWithTexture(scale9Image.Texture, new CCRect(l, m_capInsetsInternal.Origin.Y, m_capInsetsInternal.Size.Width, m_capInsetsInternal.Origin.X - l), rotated ); scale9Image.AddChild(bottom, 1, (int) Positions.pBottom); // Top top = new CCSprite(); top.InitWithTexture(scale9Image.Texture, new CCRect(m_capInsetsInternal.Origin.X + m_capInsetsInternal.Size.Height, m_capInsetsInternal.Origin.Y, m_capInsetsInternal.Size.Width, h - m_capInsetsInternal.Size.Height - (m_capInsetsInternal.Origin.X - l)), rotated ); scale9Image.AddChild(top, 1, (int) Positions.pTop); // Right right = new CCSprite(); right.InitWithTexture(scale9Image.Texture, new CCRect(m_capInsetsInternal.Origin.X, m_capInsetsInternal.Origin.Y + m_capInsetsInternal.Size.Width, w - (m_capInsetsInternal.Origin.Y - t) - m_capInsetsInternal.Size.Width, m_capInsetsInternal.Size.Height), rotated ); scale9Image.AddChild(right, 1, (int) Positions.pRight); // Left left = new CCSprite(); left.InitWithTexture(scale9Image.Texture, new CCRect(m_capInsetsInternal.Origin.X, t, m_capInsetsInternal.Origin.Y - t, m_capInsetsInternal.Size.Height), rotated ); scale9Image.AddChild(left, 1, (int) Positions.pLeft); // Top right topRight = new CCSprite(); topRight.InitWithTexture(scale9Image.Texture, new CCRect(m_capInsetsInternal.Origin.X + m_capInsetsInternal.Size.Height, m_capInsetsInternal.Origin.Y + m_capInsetsInternal.Size.Width, w - (m_capInsetsInternal.Origin.Y - t) - m_capInsetsInternal.Size.Width, h - m_capInsetsInternal.Size.Height - (m_capInsetsInternal.Origin.X - l)), rotated ); scale9Image.AddChild(topRight, 2, (int) Positions.pTopRight); // Top left topLeft = new CCSprite(); topLeft.InitWithTexture(scale9Image.Texture, new CCRect(m_capInsetsInternal.Origin.X + m_capInsetsInternal.Size.Height, t, m_capInsetsInternal.Origin.Y - t, h - m_capInsetsInternal.Size.Height - (m_capInsetsInternal.Origin.X - l)), rotated ); scale9Image.AddChild(topLeft, 2, (int) Positions.pTopLeft); // Bottom right bottomRight = new CCSprite(); bottomRight.InitWithTexture(scale9Image.Texture, new CCRect(l, m_capInsetsInternal.Origin.Y + m_capInsetsInternal.Size.Width, w - (m_capInsetsInternal.Origin.Y - t) - m_capInsetsInternal.Size.Width, m_capInsetsInternal.Origin.X - l), rotated ); scale9Image.AddChild(bottomRight, 2, (int) Positions.pBottomRight); // Bottom left bottomLeft = new CCSprite(); bottomLeft.InitWithTexture(scale9Image.Texture, new CCRect(l, t, m_capInsetsInternal.Origin.Y - t, m_capInsetsInternal.Origin.X - l), rotated ); scale9Image.AddChild(bottomLeft, 2, (int) Positions.pBottomLeft); } else { // Sprite frame is not rotated // Centre centre = new CCSprite(); centre.InitWithTexture(scale9Image.Texture, m_capInsetsInternal, rotated); scale9Image.AddChild(centre, 0, (int) Positions.pCentre); // Top top = new CCSprite(); top.InitWithTexture(scale9Image.Texture, new CCRect(m_capInsetsInternal.Origin.X, t, m_capInsetsInternal.Size.Width, m_capInsetsInternal.Origin.Y - t), rotated ); scale9Image.AddChild(top, 1, (int) Positions.pTop); // Bottom bottom = new CCSprite(); bottom.InitWithTexture(scale9Image.Texture, new CCRect(m_capInsetsInternal.Origin.X, m_capInsetsInternal.Origin.Y + m_capInsetsInternal.Size.Height, m_capInsetsInternal.Size.Width, h - (m_capInsetsInternal.Origin.Y - t + m_capInsetsInternal.Size.Height)), rotated); scale9Image.AddChild(bottom, 1, (int) Positions.pBottom); // Left left = new CCSprite(); left.InitWithTexture(scale9Image.Texture, new CCRect( l, m_capInsetsInternal.Origin.Y, m_capInsetsInternal.Origin.X - l, m_capInsetsInternal.Size.Height), rotated); scale9Image.AddChild(left, 1, (int) Positions.pLeft); // Right right = new CCSprite(); right.InitWithTexture(scale9Image.Texture, new CCRect( m_capInsetsInternal.Origin.X + m_capInsetsInternal.Size.Width, m_capInsetsInternal.Origin.Y, w - (m_capInsetsInternal.Origin.X - l + m_capInsetsInternal.Size.Width), m_capInsetsInternal.Size.Height), rotated); scale9Image.AddChild(right, 1, (int) Positions.pRight); // Top left topLeft = new CCSprite(); topLeft.InitWithTexture(scale9Image.Texture, new CCRect( l, t, m_capInsetsInternal.Origin.X - l, m_capInsetsInternal.Origin.Y - t), rotated); scale9Image.AddChild(topLeft, 2, (int) Positions.pTopLeft); // Top right topRight = new CCSprite(); topRight.InitWithTexture(scale9Image.Texture, new CCRect( m_capInsetsInternal.Origin.X + m_capInsetsInternal.Size.Width, t, w - (m_capInsetsInternal.Origin.X - l + m_capInsetsInternal.Size.Width), m_capInsetsInternal.Origin.Y - t), rotated); scale9Image.AddChild(topRight, 2, (int) Positions.pTopRight); // Bottom left bottomLeft = new CCSprite(); bottomLeft.InitWithTexture(scale9Image.Texture, new CCRect( l, m_capInsetsInternal.Origin.Y + m_capInsetsInternal.Size.Height, m_capInsetsInternal.Origin.X - l, h - (m_capInsetsInternal.Origin.Y - t + m_capInsetsInternal.Size.Height)), rotated); scale9Image.AddChild(bottomLeft, 2, (int) Positions.pBottomLeft); // Bottom right bottomRight = new CCSprite(); bottomRight.InitWithTexture(scale9Image.Texture, new CCRect( m_capInsetsInternal.Origin.X + m_capInsetsInternal.Size.Width, m_capInsetsInternal.Origin.Y + m_capInsetsInternal.Size.Height, w - (m_capInsetsInternal.Origin.X - l + m_capInsetsInternal.Size.Width), h - (m_capInsetsInternal.Origin.Y - t + m_capInsetsInternal.Size.Height)), rotated); scale9Image.AddChild(bottomRight, 2, (int) Positions.pBottomRight); } ContentSize = rect.Size; AddChild(scale9Image); if (m_bSpritesGenerated) { // Restore color and opacity Opacity = opacity; Color = color; } m_bSpritesGenerated = true; return true; }
public void set2DProjection() { CCSize cCSize = CCDirector.sharedDirector().winSizeInPixels; }
public override bool initWithTotalParticles(uint numberOfParticles) { if (base.initWithTotalParticles(numberOfParticles)) { // duration Duration = (float)eParticleShowingProperty.kCCParticleDurationInfinity; // Emitter mode: Gravity Mode EmitterMode = (int)eParticleMode.kCCParticleModeGravity; // Gravity Mode: gravity modeA.gravity = new CCPoint(0, 0); // Gravity Mode: radial acceleration modeA.radialAccel = 0; modeA.radialAccelVar = 0; // Gravity Mode: speed of particles modeA.speed = 25; modeA.speedVar = 10; // angle Angle = 90; AngleVar = 5; // emitter position CCSize winSize = CCDirector.sharedDirector().getWinSize(); this.position = new CCPoint(winSize.width / 2, 0); PosVar = new CCPoint(20, 0); // life of particles Life = 4; LifeVar = 1; // size, in pixels StartSize = 60.0f; StartSizeVar = 10.0f; EndSize = (float)eParticleShowingProperty.kCCParticleStartSizeEqualToEndSize; // emits per frame EmissionRate = TotalParticles / Life; // color of particles StartColor.r = 0.8f; StartColor.g = 0.8f; StartColor.b = 0.8f; StartColor.a = 1.0f; StartColorVar.r = 0.02f; StartColorVar.g = 0.02f; StartColorVar.b = 0.02f; StartColorVar.a = 0.0f; EndColor.r = 0.0f; EndColor.g = 0.0f; EndColor.b = 0.0f; EndColor.a = 1.0f; EndColorVar.r = 0.0f; EndColorVar.g = 0.0f; EndColorVar.b = 0.0f; EndColorVar.a = 0.0f; // additive this.IsBlendAdditive = false; return(true); } return(false); }
public void set3DProjection() { CCSize cCSize = CCDirector.sharedDirector().displaySizeInPixels; }
public virtual bool Init() { // scenes m_pRunningScene = null; m_pNextScene = null; m_pNotificationNode = null; m_dOldAnimationInterval = m_dAnimationInterval = 1.0 / kDefaultFPS; // Set default projection (3D) m_eProjection = ccDirectorProjection.kCCDirectorProjectionDefault; // projection delegate if "Custom" projection is used m_pProjectionDelegate = null; // FPS m_fAccumDt = 0.0f; m_fFrameRate = 0.0f; m_pFPSLabel = null; m_pSPFLabel = null; m_pDrawsLabel = null; m_bDisplayStats = false; m_uTotalFrames = m_uFrames = 0; // paused ? m_bPaused = false; // purge ? m_bPurgeDirecotorInNextLoop = false; m_obWinSizeInPixels = m_obWinSizeInPoints = CCSize.Zero; //m_pobOpenGLView = null; m_fContentScaleFactor = 1.0f; // scheduler m_pScheduler = new CCScheduler(); // action manager m_pActionManager = new CCActionManager(); m_pScheduler.ScheduleUpdateForTarget(m_pActionManager, CCScheduler.kCCPrioritySystem, false); // touchDispatcher m_pTouchDispatcher = new CCTouchDispatcher(); m_pTouchDispatcher.Init(); // KeypadDispatcher m_pKeypadDispatcher = new CCKeypadDispatcher(); // Accelerometer #if !PSM &&!NETFX_CORE m_pAccelerometer = new CCAccelerometer(); #endif // create autorelease pool //CCPoolManager::sharedPoolManager()->push(); m_NeedsInit = false; return true; }
public override void draw() { CCSize s = CCDirector.sharedDirector().getWinSize(); //ccDrawLine(new CCPoint(0, s.height / 2), new CCPoint(s.width, s.height / 2)); //ccDrawLine(new CCPoint(s.width / 2, 0), new CCPoint(s.width / 2, s.height)); }
public void SetOpenGlView() { // set size m_obWinSizeInPoints = DrawManager.Size; m_obWinSizeInPixels = new CCSize(m_obWinSizeInPoints.Width * m_fContentScaleFactor, m_obWinSizeInPoints.Height * m_fContentScaleFactor); //createStatsLabel(); SetGlDefaultValues(); CCApplication.SharedApplication.TouchDelegate = m_pTouchDispatcher; m_pTouchDispatcher.IsDispatchEvents = true; }
public override CCActionInterval action() { CCSize winSize = CCDirector.sharedDirector().getWinSize(); return(CCMoveBy.actionWithDuration(this.m_fDuration, new CCPoint(0f, -(winSize.height - 0.5f)))); }
public virtual void initScenes() { CCSize winSize = CCDirector.sharedDirector().getWinSize(); this.m_pInScene.position = new CCPoint(-(winSize.width - 0.5f), 0f); }
/// <summary> /// Create a CCSpriteFrame with a texture, rect, rotated, offset and originalSize in pixels. /// The originalSize is the size in points of the frame before being trimmed. /// </summary> public static CCSpriteFrame frameWithTexture(CCTexture2D pobTexture, CCRect rect, bool rotated, CCPoint offset, CCSize originalSize) { CCSpriteFrame pSpriteFrame = new CCSpriteFrame(); pSpriteFrame.initWithTexture(pobTexture, rect, rotated, offset, originalSize); return(pSpriteFrame); }