Creating a New Cocos2d-x Project for Windows Phone 8
This article explains how to create a new Cocos2d-x project for Windows Phone 8.
Contents |
Introduction
Cocos2d-x is a very popular 2D game framework. It's based on C++ and it has been ported before to iOS, Android, Windows, Marmalade, Linux, Bada, Blackberry-QNX, and now it's available also for Windows Phone 8 (c++ is supported). Creating games with Cocos2d-x makes sense, since you can easily port the games from one platform to another. This tutorial guides you on how to create a new project for the Windows Phone 8 platform, and after that you can continue by starting to build your own application, or porting an existing one.
You can download the Cocos2d-x Windows Phone 8 variant from their website.
You can import the Cocos2d-x project to Visual Studio, but soon you'll notice that the whole framework is actually built inside a HelloWorld application. The next steps describe how to remove the helloworld-stuff, and start building you own application.
Setting up the project
- Download the Cocos2d-x Windows Phone 8 version.
- Rename the cocos2dx-0.13.0-wp8-0.8 folder properly for your application.
- Go inside that new folder. You can delete the cocos2dx-wp8.sdf file. You should also see a folder named HelloWorld, you should also rename this folder properly for your own projects.
- Edit the cocos2dx-wp8.sln file. The original file should look like this:
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "cocos2d", "HelloWorld\cocos2d.vcxproj", "{1A0D24B4-1DE0-400B-BC35-92A51351477F}"
EndProject
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "test", "tests\tests.vcxproj", "{A9E507CA-55C4-45D9-A0E4-6450A43176A6}"
EndProjectYou can remove the tests project, and you should change the name of the cocos2d app, and it should point into your own app. It should look like this:
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "myapp", "myapp\cocos2d.vcxproj", "{1A0D24B4-1DE0-400B-BC35-92A51351477F}"
EndProjectNow load up the project with Visual Studio. Open up WMAppManifest.xml, and change the application settings: name, icon, tile images, etc. In the packaging tab you should also change Author & Publisher name, Product Id and Publisher Id. You can easily create new GUIDs with the Visual Studio GUIDGen tool or using this online generator. Right click the HelloWorld project name in you project explorer, and choose to rename it. The image below shows example of the HelloWorld project WMAppManifest.xml file, which you should edit for your own application.
Now you should try to build and run the new project. You should see the Angry Squirrels game.
If the game worked on the emulator, then it's time to move forward. Now you can delete the Angry Squirrels stuff and start building your own game. You can safely remove all assets related to the Angry Squirrels game (all the images of Squirrels and blocks etc.). However if you didn't change the app-icon or application tiles from WMAppManifest.xml you should keep the Assets/Tiles folder and ApplicationIcon.png file.
Cocos2d-x Application Structure
The HelloWorld project is basically building the cocos2d-x framework and dependencies within your own application. Here's quick overview of the Project structure:
- Assets: This folder has all of your project's asses such as images etc.
- Box2d: Box2d physics library. Box2d is part of the cocos2d-x framework and it's build with your project too
- Classes: Your own classes related to your own application
- cocos2dx: Cocos2d-x itself, contains sprite blitting with DirectX etc.
- CocosDenshion: Simple audioengine, part of the Cocos2d-X framework
- tinyxml: Lightweight xml-parser, also part of the cocos2d-x
Using Cocos2d-x
You should see three classes under the Classes selection in Visual studio: Appdelegate, HelloWorldScene, and MyContactListener.
The Appdelegate.cpp is responsible for binding the Cocos2d classes into the WP8 platform, and you should keep it in your own project as well. The AppDelete handles all the "magic" between windows phone platform and cocos2-d application. The wp8 port is using DirectX instead of OpenGL, but the wp8 port, and the AppDelegate hides it all form the developer, so unless you're planning to use shaders in your game, you should newer see a difference between wp8 and iOS/Android ports.
The HelloWorldScene creates the cocos2d sprites & box2d objects for the game, and the MyContactListener is just a helper class, so you can delete both of them, and create your own scene instead. However I recommend keeping the old HelloworldScene file as a reference for the future.
That's it. If you're new to the cocos2d-x, and you're building a new game, you should start with cocos2d-x tutorials at cocos2d-x tutorials
Porting Existing Cocos2-x Applications to Windows Phone 8
For porting existing cocos2d-x applications you should see Porting Cocos2d-x Games for Windows Phone 8



Contents
Hamishwillee - Review/subedit
Hi
Just gave this a minor subedit for wiki style. I think its a really useful topic - particularly as Cocos is so widely used.
In terms of "room for improvement".
Hope the comments makes sense/are helpful.
Regards
Hamsihhamishwillee 06:30, 7 December 2012 (EET)
Hamishwillee - OK, just read "Porting Cocos2d-x Games for Windows Phone 8"
Hi Summeli
OK, so just read your companion article Porting Cocos2d-x Games for Windows Phone 8. It answers a lot of the questions I had here. I would be tempted to push all the porting stuff (ie the "Differences between Windows Phone 8 and iOS applications") into the other article. )
I am not quite sure where to "draw the line" between the two, but I think perhaps have architectural stuff in this one (like "Introduction for integrating WinRT components into your native c++ app") and at the end of this article you understand what makes a Cocos2d app on Windows Phone 8 and you have a "framework"/project which you can copy in your stuff for porting or write new code. The other article then talks about what assets get copied where.
Just a thought anyway.
regards
Hamishhamishwillee 06:53, 7 December 2012 (EET)
CodeHelix - Won't deploy on Windows Phone 8 Device
I have tried to follow along but am only able to deploy to the emulator as it will not work when I try to deploy on my WP8 as I find the emulator not suitable for game development especially since I want to make a twin stick shooter. Is there another step that needs to be made to be able to deploy to a WP8 device?CodeHelix 05:45, 11 December 2012 (EET)
Summeli - I don't have wp8 device
So I don't know what's the problem with the deployment. It seems to be working on the simulator itself, so it should be possible to deploy it also to the phone. Can you even debug i, and see if you're missing some assets or something?summeli 08:29, 11 December 2012 (EET)
Summeli - Thanks for the feedback
Yes, my original idea was to keep this article as "minimalistic steps" for creating a cocos2d-x project for new game projects, and then have the other article focused on porting the existing applications. I guess that link to some cocos2d-x tutorial & to the proting article would work better.summeli 08:33, 11 December 2012 (EET)
SandCu - Problems on wp8 Device
Hi I've tested cocos2D-X on my lumia 920 but it only draws at the left bottom side of the screen,I've already raise this problem as an issue on github but no one answered till now,so I wonder whether u've got any clues about this. thanks. here's the link to my issue on github,I've uploaded some screen snapshot,hopes help.
https://github.com/cocos2d-x/cocos2dx-win8/issues/20SandCu 12:20, 24 January 2013 (EET)
Summeli - about the resolutions
Microsoft only added support for 800x480 resolution. It works really well with Nokia 820, but you have to do some extra work for other resolutions.
See the AppDelegate.cpp, and try changing the resolutions etc. Modifying this should help you a bit:
mainView->setDesignResolution(320, 533);summeli 12:44, 24 January 2013 (EET)
SandCu - thanks for your reply
yeah,that does a resolution problem. lumia 820 use the WVGA resolution and the method CCEGLView->Create() use the default resolution so it works well on it,but the lumia 920 use the WXGA resolution and that's the problem,the problem could be found on the WXGA Emulator too.
thanks for your divice but the method 'setDesignResolution' seems not worked as expected.SandCu 13:26, 24 January 2013 (EET)
Summeli - Try this hack
This one should work: http://www.cocos2d-x.org/boards/6/topics/18789?r=18987#message-18987summeli 14:34, 24 January 2013 (EET)
SandCu -
That does help! thanks a lot,I'm gonna share this with other guys,thank again!SandCu 09:44, 25 January 2013 (EET)
Eric2013 -
HI all, I have tried the above workaround, it works for 480x800 and 768x1280 devices, but still not working for 720x1280 device. Please advice.
Summeli -
Do you mean those small black borders in 768x1280 resolution? It's not so bad. Microsoft even approves your app to the marketplace with those. I would expect this issue to be fixed when microsoft gets the cocos2d-x port finalized.summeli 08:43, 4 February 2013 (EET)