A trap of adding resources into cocos2dx-wp8 project
By lihex Posted 2012-11-06 09:04 Comments 164
If you download the previous version of cocos2dx-0.13.0-wp8-0.8.zip, you will find some test cases that has marked as pass but can not run properly on wp8 devices.
We sincerely regret this error, as it was caused by our sloppiness
I’ll explain why it is not running correctly on devices in debug mode.
In the project of the cocos2dx-wp8, game resources are placed in the Assets directory, this directory is also the root directory of the game resources:
If you want to create a sprite from a picture:
CCSprite :: spriteWithFile ("Image / sprite.png");
It will read as:
"App / Install / PATH / Assets / Image / sprite.png "
Not only we need to copy the game resources to the Assets directory, but also add each resource file to the VS project.
So how do we do it specifically?
For example to add sprite.png:
- Select Assets filter
- Right click
> Add New Filter, named it Image # Select Image filter # Right click> Add Existing Item…
- Choose the \$YOUR_PROJECT/Assets/Image/sprite.png
This seems to work, but there are still problems:
The problem is, if we add a “sprite.plist” file, according to the above procedures, it is added to the project, but when you run the program, you will found that the program could not find “sprite.plist”!
Why is that? This problem has also plagued me for long time, fortunately, this has been resolved The reason is that only the file formats that Visual Studio can identify will be automatically packed into the app package, such as images: png, jpg. If you right-click to view the properties of these files, you will find the “Content field” is set as “Yes” and “Item Type” is set to properly type, such as “Image” in case of sprite.png
However VS does not recognize “plist”, so its Content is set to “No” and it’s “Item type” is set to “Does not participate in build”, which means plist files will not be packed into the application package.
The solution is very simple, that is to set the resource file Content field to “ Yes” , the Item type field to “Does not participate in build”.
The reason why it works in the Emulator but not on the physical devices is because Device Debugging configuration forgot to add those attributes to files.
The cocos2dx-0.13.0-wp8-0.8.zip was updated, Please download again with the same url.
Download Zipball: http://cocos2d-x.googlecode.com/files/cocos2dx-0.13.0-wp8-0.8.zip