Cocos2d v2 Sample Project

General discussion about the R.U.B.E editor
Post Reply
therealcos
Posts: 16
Joined: Tue Aug 20, 2013 7:30 am

Cocos2d v2 Sample Project

Post by therealcos »

I'm having a bit of trouble replicating several things shown in the tutorials on this site when I start an XCode project using a template for v2 of Cocos2d. Is there any chance you could upload a Cocos2d sample project just like the one that's already up there (that uses BasicRUBELayer, RUBELayer, etc.) except with v2 of Cocos2d instead of v1?

On a related note, do you have any personal opinions on using v2 of Cocos2d as opposed to v1? I'd like to start building a game with v2 just because I assume it's better to use the most up-to-date version whenever possible.
iforce2d
Site Admin
Posts: 861
Joined: Sat Dec 22, 2012 7:20 pm

Re: Cocos2d v2 Sample Project

Post by iforce2d »

There is only one line that needs changing (two if you want to use debug draw). You might like to take a look at this thread: viewtopic.php?f=6&t=204

By the way, I noticed that Cocos2d defines the version number like this:

Code: Select all

// 0x00 HI ME LO

#define COCOS2D_VERSION 0x00010001

#define COCOS2D_VERSION 0x00020100
... so it should be fairly simple to check which version is in use so that this issue will not come up in future. Of course, it can be done at run-time like:

Code: Select all

if ( COCOS2D_VERSION >> 16 == 2 )
... but I am wondering if there is some nice trick that can do this in the preprocessor?

EDIT: Turns out the pre-processor does this just fine, like:
#if (COCOS2D_VERSION >> 16) == 2
So I'll update the sample code downloads like this.
therealcos
Posts: 16
Joined: Tue Aug 20, 2013 7:30 am

Re: Cocos2d v2 Sample Project

Post by therealcos »

Hmm, I just tried replacing these two lines (after dropping the new cocos2d folder in there) and it seems there are a few references in your code to some things that may have been deprecated between v1 and v2. I worked through a number of these, but I'm currently hunting for v2's new implementation of functions like setDirectorType and setDeviceOrientation (referenced in your AppDelegate). Looking forward to seeing the updated version of the sample project you upload... ;)
iforce2d
Site Admin
Posts: 861
Joined: Sat Dec 22, 2012 7:20 pm

Re: Cocos2d v2 Sample Project

Post by iforce2d »

I mean that there are only those lines in the RUBE files that will need changing. Naturally, there will be other fundamental differences in the Cocos2d related files themselves (AppDelegate etc), which are usually taken care of by way of starting with a project template for v2. It would be better to start with a standard Cocos2d v2 template and add the RUBE files to it, rather than the other way around. From the point you at now though, maybe you could make another project using the v2 template, and just copy the AppDelegate (and whichever other standard files have problems) in from that.

Perhaps what I should have done is exclude the Cocos2d files from that sample loader altogether, so that it only has the RUBE files. Then, tell people to add those files to a freshly created template project, which will be v1 or v2 as per their preference. Come to think of it that would be a better plan, because then people can use the most recent version of Cocos2d instead of whatever version was around when I made the demo project. Unfortunately the result will be a set of files that cannot be just downloaded and built with one click, but I think it makes more sense than having two separate sample projects, each containing the entire source for Cocos2d that will likely need to have files fiddled around with like you're doing now. I will look into changing the download file sometime to do that.
therealcos
Posts: 16
Joined: Tue Aug 20, 2013 7:30 am

Re: Cocos2d v2 Sample Project

Post by therealcos »

Just reading this now, and that's exactly what I started doing last night - working from the ground up. ;)

Turns out it's not too hard this way - only a few minor details that need to be changed in BasicRUBELayer, RUBELayer, etc. (e.g. rather than scheduling the tick function with a selector, there's a "scheduleUpdate" function now) but maybe I can send over my updated versions of these files that work within a Cocos2d v2 template for you to browse over once they're polished.

Thanks for all the help!
iforce2d
Site Admin
Posts: 861
Joined: Sat Dec 22, 2012 7:20 pm

Re: Cocos2d v2 Sample Project

Post by iforce2d »

I updated the Cocos2d sample loader to build for both v1 and v2. This meant that the Cocos2d source code itself is now removed from the download, which was probably a better idea anyway.

RUBE with Cocos2d setup
http://www.youtube.com/watch?v=UT-uGUcnMW0
banarne
Posts: 19
Joined: Fri Aug 23, 2013 1:30 pm

Re: Cocos2d v2 Sample Project

Post by banarne »

just a tip if your bodies/sprites are offset from eachother (retina).

change:

Code: Select all

m_debugDraw = new GLESDebugDraw( [[CCDirector sharedDirector] contentScaleFactor] );
to

Code: Select all

m_debugDraw = new GLESDebugDraw();
in BasicRUBELayer.mm
iforce2d
Site Admin
Posts: 861
Joined: Sat Dec 22, 2012 7:20 pm

Re: Cocos2d v2 Sample Project

Post by iforce2d »

arrrgghhh... you are quite correct. That was even discussed in a thread here already, and was one of the main reasons for making this update in the first place... how the hell did I forget about it?? :(
oh well, fixed now. Thanks!
Post Reply