Page 2 of 3

Re: All images dragged into scene come at same size

Posted: Sat Jun 01, 2013 7:08 am
by toojee
ok thanks, I already see this, but its pretty incomplete, my actual version is already more complete than that ^^
I have work to do :D

Re: All images dragged into scene come at same size

Posted: Fri Jun 07, 2013 1:14 pm
by Eddy8555
Thank you, iforce. I looked at the sample project -- great stuff! -- and it helped me figure out how to get the scrolling of a background image to work. But it didn't help with my original question about the body / sprite connection.

I am using the generated C++ code in RUBE, and not the JSON, and I'd prefer not to work with the loader right now. Is that possible?

Re: All images dragged into scene come at same size

Posted: Fri Jun 07, 2013 3:30 pm
by iforce2d
As we discussed before the generated C++ is only good for knocking up a quick prototype, and is a dead-end for any purposes beyond that. Plus, it doesn't know anything about images... loading the exported .json is the only way you can get image positions into your program. How did you load the positions for images in the screenshot above with the red background? If you were already using the loader there, best to just keep using it instead of reverting back to the generated C++.

Re: All images dragged into scene come at same size

Posted: Fri Jun 07, 2013 5:31 pm
by Eddy8555
Well, I didn't use the loader yet, just got the C++ code, copied it into my project, and then attached a sprite to it, using this method:

+ (CCSprite*) createSprite:(CCLayer*) layer withBody: (b2Body*) body andImageName:(NSString*)imageName andOpacity:(int) opacity andPosition: (CGPoint) pos andTag:(int) tag{

CCSprite *sprite = [CCSprite spriteWithFile:(imageName)];
sprite.opacity = opacity;
sprite.tag = tag;

[layer addChild:sprite];
body->SetUserData(sprite);

return sprite;
}

The "pos" in the method above is the same position for which I'm setting the bodyDef.

Thanks again for your help.

Re: All images dragged into scene come at same size

Posted: Fri Jun 07, 2013 11:43 pm
by iforce2d
I see. But that does not take into account the scale, rotation or offset of the image relative to the body it is attached to. I'm afraid I'm gonna have to refer you again to the post I linked to above. The important part is:

"In the RUBELayer class, the functions loadImages and setImagePositionsFromPhysicsBodies perform the getting of the necessary info from the JSON file, and then the positioning of the sprite to the current location, rotation, and scale of the body."

I really think you need to drop the idea of using the generated C++ code, because it will get you nowhere fast. Did you try building and running the cocos2d sample project?

You might also like to watch this video, which shows all the steps for setting up the loader with cocos2d, it takes about 30 minutes: Using RUBE with Cocos2d (2/2)

Re: All images dragged into scene come at same size

Posted: Sat Jun 08, 2013 5:16 pm
by Eddy8555
Thanks, I watched the video and I'll try to setup the loader this week. (and yes, I did compile and run the cocos2d sample project, it's great.)

A quick question: I got a build of RUBE for mac, installed it, went to the preferences menu and checked the "Right click opens action menu in editor views." But when I right click I get a grayed out message saying "No actions registered."

When I do the same on my Windows machine the action options open (add body, etc.) So how do I get this to work on my mac? OS version 10.8.

(I hope it's OK to ask this different question on the same thread. If not I'll gladly move it to a new one.)

Re: All images dragged into scene come at same size

Posted: Sat Jun 08, 2013 5:18 pm
by Eddy8555
Actually another question: how do I get the "cocos2d project" option in xCode's "New Project?" I'm using 4.5.

I'm asking because I noticed you have that option in your environment on the tutorial video you linked to.

Re: All images dragged into scene come at same size

Posted: Sat Jun 08, 2013 5:44 pm
by iforce2d
The contents of the action menu are loaded from files in the 'config' folder, which should be in the same folder as the R.U.B.E.app itself. If you have moved files around you might not get the menu contents showing. However, this is not the first time I have had a report that the menu was empty, so perhaps there is a bug there somewhere. But the other person said it only happens sometimes... does it happen sometimes for you, or all the time? If it happens all the time, I will look into it.

To get the cocos2d templates, you will need to download the cocos2d stuff from their website, and there is a script to run which will set up those for you. The RUBE examples are all using cocos2d 1.0.1 so you might want to get that one, to help things go smoothly rather than 2.0

Re: All images dragged into scene come at same size

Posted: Sat Jun 08, 2013 7:34 pm
by Eddy8555
OK, it was probably because I moved the Rube application file to the mac's Applications folder, instead of an alias. I reinstalled and now the action menu is working fine. Thank you, once again :)

Re: All images dragged into scene come at same size

Posted: Sun Jun 09, 2013 2:38 pm
by Eddy8555
So I set up the loader, created a scene with a couple of bodies and images, and loaded it. My plant image -- I uploaded a screenshot earlier in this thread -- loaded nicely, with the body wrapping the image the way it should. Very cool.

Now, in the flow of my application, the screen starts blank (at least for the purpose of this question.) So I do not want anything loaded right away. But I do want to add my sprites / bodies when the player is pressing a button, at various stages of the game. So I'm looking for some API call like this:

[self addMonsterToGame:json monsterName: name];

I'm sure I can do this by tinkering with RubeLayer and BasicRubeLayer and the b2dJson files. But maybe there's an easier way?