public BMFontUnicode() { var data = CCFileUtils.GetFileData("fonts/strings.plist"); PlistDocument doc = new PlistDocument(data); var strings = doc.Root as PlistDictionary; string chinese = strings["chinese1"].AsString; string japanese = strings["japanese"].AsString; string spanish = strings["spanish"].AsString; CCSize s = CCDirector.SharedDirector.WinSize; CCLabelBMFont label1 = new CCLabelBMFont(spanish, "fonts/arial-unicode-26.fnt", 200, CCTextAlignment.Left); AddChild(label1); label1.Position = new CCPoint(s.Width / 2, s.Height / 4 * 3); CCLabelBMFont label2 = new CCLabelBMFont(chinese, "fonts/arial-unicode-26.fnt"); AddChild(label2); label2.Position = new CCPoint(s.Width / 2, s.Height / 4 * 2); CCLabelBMFont label3 = new CCLabelBMFont(japanese, "fonts/arial-unicode-26.fnt"); AddChild(label3); label3.Position = new CCPoint(s.Width / 2, s.Height / 4 * 1); }
private static void LoadFile() { Stream _stream = CCFileUtils.GetFileStream(__FILEPATH); StreamReader _sr = new StreamReader(_stream); List <string[]> _strList = new List <string[]>(); // 剔除注释 string _str = _sr.ReadLine(); while (_str != null) { string[] _list = ParseStr(_str); if (_list != null) { // 合法字符入表 _strList.Add(_list); } _str = _sr.ReadLine(); } // 根据表入dic if (_strList.Count > 0) { m_dic.Clear(); int _count = _strList.Count; for (int i = 0; i < _count; i++) { int _j = 0; CStringText _text = new CStringText(); // Key _text.m_key = _strList[i][_j]; _j++; _text.m_str = _strList[i][_j]; if (!m_dic.ContainsKey(_text.m_key)) { m_dic.Add(_text.m_key, _text); } else { // 报错 } } } else { // 报错 } }
void PreloadTexture(string path) { if (CCTextureCache.SharedTextureCache.Contains(path)) { return; } using (var fs = CCFileUtils.GetFileStream(path + ".xnb")) { new CCTexture2D(fs); } }
public CocosDenshionTest() { m_pItmeMenu = null; m_tBeginPos = new CCPoint(0, 0); m_nSoundId = 0; string[] testItems = { "play background music", "stop background music", "pause background music", "resume background music", "rewind background music", "is background music playing", "play effect", "play effect repeatly", "stop effect", "unload effect", "add background music volume", "sub background music volume", "add effects volume", "sub effects volume" }; // add menu items for tests m_pItmeMenu = CCMenu.menuWithItems(null); CCSize s = CCDirector.sharedDirector().getWinSize(); m_nTestCount = testItems.Count <string>(); for (int i = 0; i < m_nTestCount; ++i) { CCLabelTTF label = CCLabelTTF.labelWithString(testItems[i], "Arial", 24); CCMenuItemLabel pMenuItem = CCMenuItemLabel.itemWithLabel(label, this, new SEL_MenuHandler(menuCallback)); m_pItmeMenu.addChild(pMenuItem, i + 10000); pMenuItem.position = new CCPoint(s.width / 2, (s.height - (i + 1) * LINE_SPACE)); } m_pItmeMenu.contentSize = new CCSize(s.width, (m_nTestCount + 1) * LINE_SPACE); m_pItmeMenu.position = new CCPoint(0, 0); addChild(m_pItmeMenu); this.isTouchEnabled = true; // preload background music and effect SimpleAudioEngine.sharedEngine().preloadBackgroundMusic(CCFileUtils.fullPathFromRelativePath(MUSIC_FILE)); SimpleAudioEngine.sharedEngine().preloadEffect(CCFileUtils.fullPathFromRelativePath(EFFECT_FILE)); // set default volume SimpleAudioEngine.sharedEngine().setEffectsVolume(0.5f); SimpleAudioEngine.sharedEngine().setBackgroundMusicVolume(0.5f); }
public CocosDenshionTest() { m_pItmeMenu = null; m_tBeginPos = new CCPoint(0, 0); m_nSoundId = 0; string[] testItems = { "play background music", "stop background music", "pause background music", "resume background music", "rewind background music", "is background music playing", "play effect", "play effect repeatly", "stop effect", "unload effect", "add background music volume", "sub background music volume", "add effects volume", "sub effects volume" }; // add menu items for tests m_pItmeMenu = new CCMenu(null); CCSize s = CCDirector.SharedDirector.WinSize; m_nTestCount = testItems.Count <string>(); for (int i = 0; i < m_nTestCount; ++i) { CCLabelTTF label = new CCLabelTTF(testItems[i], "arial", 24); CCMenuItemLabel pMenuItem = new CCMenuItemLabel(label, menuCallback); m_pItmeMenu.AddChild(pMenuItem, i + 10000); pMenuItem.Position = new CCPoint(s.Width / 2, (s.Height - (i + 1) * LINE_SPACE)); } m_pItmeMenu.ContentSize = new CCSize(s.Width, (m_nTestCount + 1) * LINE_SPACE); m_pItmeMenu.Position = new CCPoint(0, 0); AddChild(m_pItmeMenu); this.TouchEnabled = true; // preload background music and effect CCSimpleAudioEngine.SharedEngine.PreloadBackgroundMusic(CCFileUtils.FullPathFromRelativePath(MUSIC_FILE)); CCSimpleAudioEngine.SharedEngine.PreloadEffect(CCFileUtils.FullPathFromRelativePath(EFFECT_FILE)); // set default volume CCSimpleAudioEngine.SharedEngine.EffectsVolume = 0.5f; CCSimpleAudioEngine.SharedEngine.BackgroundMusicVolume = 0.5f; }
public TMXIsoZorderFromStream() : base(new System.IO.StreamReader(CCFileUtils.GetFileStream("TileMaps/iso-test-zorder1.tmx"))) { m_tamara = new CCSprite(pathSister1); tileLayersContainer.AddChild(m_tamara, tileMap.Children.Count); tileLayersContainer.Position = new CCPoint(-50.0f, -50.0f); m_tamara.AnchorPoint = CCPoint.Zero; m_tamara.RepeatForever(move, back); Schedule(repositionSprite); }
private void InitializeMap() { string mapText = CCFileUtils.GetFileData(filename: "map.txt"); #if __IOS__ string[] stringSeparators = new string[] { "\n" }; #else string[] stringSeparators = new string[] { "\r\n" }; #endif string[] lines = mapText.Split(stringSeparators, StringSplitOptions.None); string[] dimension = lines[0].Split(' '); Cols = int.Parse(dimension[0]); Rows = int.Parse(dimension[1]); gameMap = new MapEntity[Rows, Cols]; for (int i = 2; i < lines.Length; i++) { var items = lines[i].Split(' '); for (int j = 0; j < items.Length; j++) { switch (items[j]) { case "W": gameMap[j, i - 2] = new Wall(j, i - 2); break; case "I": gameMap[j, i - 2] = new EntryField(j, i - 2, this); break; case "F": gameMap[j, i - 2] = new Field(j, i - 2); break; case "O": gameMap[j, i - 2] = new ExitField(j, i - 2); break; } } } for (int i = 0; i < Rows; i++) { for (int j = 0; j < Cols; j++) { AddChild(gameMap[j, i]); } } }
public CocosDenshionTest() { testMenu = null; beginPos = new CCPoint(0, 0); soundId = 0; string[] testItems = { "Play background music", "Stop background music", "Pause background music", "Resume background music", "Rewind background music", "Is background music playing", "Play effect", "Play effect repeatly", "Stop effect", "Unload effect", "Add background music volume", "Sub background music volume", "Add effects volume", "Sub effects volume" }; testMenu = new CCMenu(null); testMenuItems = new List <CCMenuItem>(); for (int i = 0; i < testItems.Count(); ++i) { CCLabelTtf label = new CCLabelTtf(testItems[i], "arial", 24); CCMenuItemLabelTTF menuItem = new CCMenuItemLabelTTF(label, MenuCallback); testMenu.AddChild(menuItem, i + 10000); testMenuItems.Add(menuItem); } AddChild(testMenu); // preload background music and effect CCSimpleAudioEngine.SharedEngine.PreloadBackgroundMusic(CCFileUtils.FullPathFromRelativePath(MUSIC_FILE)); CCSimpleAudioEngine.SharedEngine.PreloadEffect(CCFileUtils.FullPathFromRelativePath(EFFECT_FILE)); // set default volume CCSimpleAudioEngine.SharedEngine.EffectsVolume = 0.5f; CCSimpleAudioEngine.SharedEngine.BackgroundMusicVolume = 0.5f; }
public BMFontUnicode() { var data = CCFileUtils.GetFileData("fonts/strings.plist"); PlistDocument doc = new PlistDocument(data); var strings = doc.Root as PlistDictionary; string chinese = strings["chinese1"].AsString; string japanese = strings["japanese"].AsString; string spanish = strings["spanish"].AsString; label1 = new CCLabelBMFont(spanish, "fonts/arial-unicode-26.fnt", 200, CCTextAlignment.Left); AddChild(label1); label2 = new CCLabelBMFont(chinese, "fonts/arial-unicode-26.fnt"); AddChild(label2); label3 = new CCLabelBMFont(japanese, "fonts/arial-unicode-26.fnt"); AddChild(label3); }
public void Load(AtlasPage page, String path) { var ccTexture = CCApplication.SharedApplication.TextureCache.AddImage(path); if (texture == null) { using (Stream stream = CCFileUtils.GetFileStream(path)) { texture = Util.LoadTexture(CCDrawManager.GraphicsDevice, stream); } } else { texture = ccTexture.XNATexture; } page.rendererObject = texture; page.width = texture.Width; page.height = texture.Height; }
public CCSkeleton(string skeletonDataFile, string atlasFile, float scale = 0) { Initialize(); using (StreamReader atlasStream = new StreamReader(CCFileUtils.GetFileStream(atlasFile))) { atlas = new Atlas(atlasStream, "", new CocosSharpTextureLoader()); } SkeletonJson json = new SkeletonJson(atlas); json.Scale = scale == 0 ? 1 : scale; using (StreamReader skeletonDataStream = new StreamReader(CCFileUtils.GetFileStream(skeletonDataFile))) { SkeletonData skeletonData = json.ReadSkeletonData(skeletonDataStream); skeletonData.Name = skeletonDataFile; SetSkeletonData(skeletonData, true); } }
public LabelFNTUNICODELanguages() { var data = CCFileUtils.GetFileData("fonts/strings.plist"); PlistDocument doc = new PlistDocument(data); var strings = doc.Root as PlistDictionary; var chinese = strings["chinese1"].AsString; var japanese = strings["japanese"].AsString; var spanish = strings["spanish"].AsString; var russian = strings["russian"].AsString; label1 = new CCLabel(spanish, "fonts/arial-unicode-26.fnt", new CCSize(200, 0), CCLabelFormat.BitMapFont); label1.LabelFormat.Alignment = CCTextAlignment.Center; AddChild(label1); label2 = new CCLabel(chinese, "fonts/arial-unicode-26.fnt"); AddChild(label2); label3 = new CCLabel(russian, "fonts/arial-26-en-ru.fnt"); AddChild(label3); label4 = new CCLabel(japanese, "fonts/arial-unicode-26.fnt"); AddChild(label4); }
public void menuCallback(CCObject pSender) { // get the userdata, it's the index of the menu item clicked CCMenuItem pMenuItem = (CCMenuItem)(pSender); int nIdx = pMenuItem.zOrder - 10000; switch (nIdx) { // play background music case 0: SimpleAudioEngine.sharedEngine().playBackgroundMusic(CCFileUtils.fullPathFromRelativePath(MUSIC_FILE), true); break; // stop background music case 1: SimpleAudioEngine.sharedEngine().stopBackgroundMusic(); break; // pause background music case 2: SimpleAudioEngine.sharedEngine().pauseBackgroundMusic(); break; // resume background music case 3: SimpleAudioEngine.sharedEngine().resumeBackgroundMusic(); break; // rewind background music case 4: SimpleAudioEngine.sharedEngine().rewindBackgroundMusic(); break; // is background music playing case 5: if (SimpleAudioEngine.sharedEngine().isBackgroundMusicPlaying()) { Debug.WriteLine("background music is playing"); } else { Debug.WriteLine("background music is not playing"); } break; // play effect case 6: m_nSoundId = SimpleAudioEngine.sharedEngine().playEffect(CCFileUtils.fullPathFromRelativePath(EFFECT_FILE)); break; // play effect case 7: m_nSoundId = SimpleAudioEngine.sharedEngine().playEffect(CCFileUtils.fullPathFromRelativePath(EFFECT_FILE), true); break; // stop effect case 8: SimpleAudioEngine.sharedEngine().stopEffect(m_nSoundId); break; // unload effect case 9: SimpleAudioEngine.sharedEngine().unloadEffect(CCFileUtils.fullPathFromRelativePath(EFFECT_FILE)); break; // add bakcground music volume case 10: SimpleAudioEngine.sharedEngine().setBackgroundMusicVolume(SimpleAudioEngine.sharedEngine().getBackgroundMusicVolume() + 0.1f); break; // sub backgroud music volume case 11: SimpleAudioEngine.sharedEngine().setBackgroundMusicVolume(SimpleAudioEngine.sharedEngine().getBackgroundMusicVolume() - 0.1f); break; // add effects volume case 12: SimpleAudioEngine.sharedEngine().setEffectsVolume(SimpleAudioEngine.sharedEngine().getEffectsVolume() + 0.1f); break; // sub effects volume case 13: SimpleAudioEngine.sharedEngine().setEffectsVolume(SimpleAudioEngine.sharedEngine().getEffectsVolume() - 0.1f); break; } }
public void menuCallback(object pSender) { // get the userdata, it's the index of the menu item clicked CCMenuItem pMenuItem = (CCMenuItem)(pSender); int nIdx = pMenuItem.ZOrder - 10000; switch (nIdx) { // play background music case 0: SimpleAudioEngine.SharedEngine.PlayBackgroundMusic(CCFileUtils.FullPathFromRelativePath(MUSIC_FILE), true); break; // stop background music case 1: SimpleAudioEngine.SharedEngine.StopBackgroundMusic(); break; // pause background music case 2: SimpleAudioEngine.SharedEngine.PauseBackgroundMusic(); break; // resume background music case 3: SimpleAudioEngine.SharedEngine.ResumeBackgroundMusic(); break; // rewind background music case 4: SimpleAudioEngine.SharedEngine.RewindBackgroundMusic(); break; // is background music playing case 5: if (SimpleAudioEngine.SharedEngine.IsBackgroundMusicPlaying()) { CCLog.Log("background music is playing"); } else { CCLog.Log("background music is not playing"); } break; // play effect case 6: m_nSoundId = SimpleAudioEngine.SharedEngine.PlayEffect(CCFileUtils.FullPathFromRelativePath(EFFECT_FILE)); break; // play effect case 7: m_nSoundId = SimpleAudioEngine.SharedEngine.PlayEffect(CCFileUtils.FullPathFromRelativePath(EFFECT_FILE), true); break; // stop effect case 8: SimpleAudioEngine.SharedEngine.StopEffect(m_nSoundId); break; // unload effect case 9: SimpleAudioEngine.SharedEngine.UnloadEffect(CCFileUtils.FullPathFromRelativePath(EFFECT_FILE)); break; // add bakcground music volume case 10: SimpleAudioEngine.SharedEngine.BackgroundMusicVolume = SimpleAudioEngine.SharedEngine.BackgroundMusicVolume + 0.1f; break; // sub backgroud music volume case 11: SimpleAudioEngine.SharedEngine.BackgroundMusicVolume = SimpleAudioEngine.SharedEngine.BackgroundMusicVolume - 0.1f; break; // add effects volume case 12: SimpleAudioEngine.SharedEngine.EffectsVolume = SimpleAudioEngine.SharedEngine.EffectsVolume + 0.1f; break; // sub effects volume case 13: SimpleAudioEngine.SharedEngine.EffectsVolume = SimpleAudioEngine.SharedEngine.EffectsVolume - 0.1f; break; } }
static void cacheSpriteFramesInfo(string imageDevPath, LHScene scene) { string sceneRelative = scene.relativePath; string curDevSuffix = scene.currentDeviceSuffix(true); string atlasName = LHUtils.stripExtension(imageDevPath); // string atlasName = Path.GetFileNameWithoutExtension(imageDevPath); string atlasPlist = atlasName + ".plist"; // string atlasPlist = Path.ChangeExtension (atlasName, "plist"); string sceneSuf = sceneRelative + curDevSuffix; // atlasPlist = sceneSuf + atlasPlist; // Debug.WriteLine ("atlasPlist"); // Debug.WriteLine (atlasPlist); // string sceneSuf = Path.Combine (sceneRelative, curDevSuffix); // atlasPlist = Path.Combine (sceneSuf, atlasPlist); CCSpriteFrameCache cache = CCSpriteFrameCache.SharedSpriteFrameCache; cache.AddSpriteFrames(atlasPlist); atlasName = sceneRelative + atlasName; // atlasName = Path.Combine (sceneRelative, atlasName); if (false == scene.hasEditorBodyInfoForImageFilePath(atlasName)) { string path = CCFileUtils.FullPathFromRelativePath(atlasPlist); PlistDocument document = CCContentManager.SharedContentManager.Load <PlistDocument>(path); PlistDictionary dict = document.Root.AsDictionary; PlistDictionary framesDict = dict ["frames"].AsDictionary; foreach (var pair in framesDict) { string sprName = pair.Key; PlistDictionary frmInfo = pair.Value.AsDictionary; if (null != frmInfo) { PlistDictionary bodyInfo = frmInfo ["body"].AsDictionary; if (null != bodyInfo) { Debug.WriteLine("CACHING BODY " + sprName + " atlas " + atlasName + " body " + bodyInfo); scene.setEditorBodyInfoForSpriteName(sprName, atlasName, bodyInfo); } } } } }