How to load Plist file in Cocos2dx v3.9 - cocos2d-x-3.x

I am developing one game using Cocos2d-x 3.9. I tried to load the plist file in my game with following code.
But the size of data is 0. It returns no data.
How can I load plist? CCDictionary was deprecated in Cocos2d-x v3.9
ValueMap data;
std::string path = FileUtils::getInstance()->fullPathForFilename("my.plist");
data = FileUtils::getInstance()->getValueMapFromFile(path);

Related

Saving data with Unity and Tango

I have been trying to save game data using a binary formatter and Application.persistentDataPath on my Tango device. After saving however, the file is nowhere to be found.
Right now the path is reading out as "Storage/emulated/0/Android/data/com.mine.project/files/filename.bin", but as stated above, the path doesn't actually exist anywhere.
Is there another way to save all of this data on the Tango that I have yet to find? If not, is there a way to get these files to show up?
This is the code that I am currently using, minus some debugging functions I use.
string path = Application.persistentDataPath + Path.DirectorySeparatorChar + "file.bin";
BinaryFormatter bf = new BinaryFormatter ();
FileStream file = File.Open (path, FileMode.OpenOrCreate);
bf.Serialize(file, data);
file.Close ();
From what I can tell this isn't throwing any errors, I can even find the file again via the File.Exists() function, but I need to find the file again for access through other programs, and so far it has proven impossible.

Storing images in windows phone 8

I have been really cracking my head trying to write and read png files into a folder in Windows Phone 8. From few blogs sites and codeplex i found that the there is an extension to the WritableBitmap Class which provides few extra functionalities. ImageTools has PNG encoder and decoder. But I really cant find examples to use them.
What Im trying to achieve here is to create a folder called page and then in it a file called Ink File. I want to convert the bitmap to a PNG and store it there. The bitmap is created from the strokes drawn on a canvas. The class ImageTools provides a function called ToImage to convert the strokes from the canvas to image.
For storing
ExtendedImage myImage = InkCanvas.ToImage();
var encoder = new PngEncoder();
var dataFolder = await local.CreateFolderAsync("Page", CreationCollisionOption.OpenIfExists);
StorageFile Ink_File = await dataFolder.CreateFileAsync("InkFile", CreationCollisionOption.ReplaceExisting);
using (var stream = await Ink_File.OpenAsync(Windows.Storage.FileAccessMode.ReadWrite))
{
using (var s = await Ink_File.OpenStreamForWriteAsync())
{
encoder.Encode(myImage, s);
await s.FlushAsync();
s.Close();
}
}
Is this a correct method? I receive some null exceptions for this. How do i find if the image is saved as png. How is this image saved? Is it encoded and saved in a file or is it saved as a png itsef. And how do we read this back?
I have checked out this, this , this and lot more like this.
I'm developing app for WP8
I have used the PNG Writer Library found in ToolStack and it works :)

How to load Vuforia QCAR tracking file data during runtime in iOS

I am working on Augmented reality using Vuforia sdk, and i want to load 3d object on runtime, i want to fetch it from web-service and load it when i need that, So basically my question only is this how can we load any .h file on run time. First is this possible that we can load it on runtime and if possible then how can we do that.
If you have dynamic data, putting it into a .h file doesn't make sense. Headers are only useful while the program is being compiled, not at run time.
AFAIK vuforia just puts arrays of vertical, triangles, etc. into h file. So you don't need to load h file in runtime (and this is impossible, there is no h files when programm is running). Instead you need to get those arrays and give them to vuforia
just download that file from network, store it within application directories and load it like the sample data bundled with the app
NSString * pathToDownloadedFile; //should have path to your file
QCAR::DataSet *dataSet = nil;
QCAR::TrackerManager& trackerManager = QCAR::TrackerManager::getInstance();
QCAR::ImageTracker* imageTracker = static_cast<QCAR::ImageTracker*> (trackerManager.getTracker(QCAR::Tracker::IMAGE_TRACKER));
dataSet = imageTracker->createDataSet();
dataSet->load([pathToDownloadedFile cStringUsingEncoding:NSASCIIStringEncoding], QCAR::DataSet::STORAGE_ABSOLUTE);
imageTracker->activateDataSet(dataSet);

iPhone/iPad Base64->NSData->PDF how to?

Obj-C or Monotouch.Net C# answers are fine.
I have a Base64 string that is a PDF document received over a web service. I can get the NSData.
How do I take the NSData and save it as a PDF?
-- I get the NSData this way --
byte[] encodedDataAsBytes = System.Convert.FromBase64String (myBase64String);
string decoded = System.Text.Encoding.Unicode.GetString (encodedDataAsBytes);
NSData data = NSData.FromString (decoded, NSStringEncoding.ASCIIStringEncoding);
The simplest way to save it is probably to use NSData's writeToFile:options:error: method.
I found that using the .NET framework works better than trying to use the iOS framework for this problem. This will take any file and convert it to it's original then save it to the iPhone/iPad device. "path" is just a folder on the dev ice.
using (var f = System.IO.File.Create (path))
{
byte[] encodedDataAsBytes = System.Convert.FromBase64String (Base64PDFString);
f.Write (encodedDataAsBytes, 0, encodedDataAsBytes.Length);
}
I'm working on a project where I recently had to accomplish the same thing you are describing. I get base64 encoded PDF files as strings from a .NET web service which need to be decoded to their original and saved as PDF files in the applications documents directory.
My solution was:
Use ASIHTTPRequest to communicate with the web service.
I then use TBXML to parse incoming xml and get the base64 as an NSString.
To decode the string I use a method from QSUtilities library called decodeBase64WithString.
Finally I save the result with NSData's writeToFile.
I have tested and successfully used this method with PDF files that are up to 25mb. I also had a couple of test runs with a 48mb file but that file made the decodeBase64WithString method take up too much memory and my app crashed. Haven't found a solution to this yet..
If you are working with multiple large files be sure to free up your memory once in a while. I got all my files in one loop in which I had to use my own nsautorelease pool and drain it at the end of the loop to free up any autoreleased objects.

Create XML file dynamically in Iphone

I want to create a xml file dynamically for my Iphone application. I tried it by using NSXMLDocument but NSXMLDocument is not declared in iphone application.
Please help me in doing so.
Thanks
Gaurav
Try the open source XML stream writer for iOS:
Written in Objective-C, a single .h. and .m file
One #protocol for namespaces support and one for without
Example:
// allocate serializer
XMLWriter* xmlWriter = [[XMLWriter alloc]init];
// start writing XML elements
[xmlWriter writeStartElement:#"Root"];
[xmlWriter writeCharacters:#"Text content for root element"];
[xmlWriter writeEndElement];
// get the resulting XML string
NSString* xml = [xmlWriter toString];
This produces the following XML string:
<Root>Text content for root element</Root>
You can use KissXML to generate XML files on the iPhone.
You can also use libxml2 to generate XML data on the iPhone.