All images dragged into scene come at same size

General discussion about the R.U.B.E editor
toojee
Posts: 9
Joined: Fri May 31, 2013 7:56 am

Re: All images dragged into scene come at same size

Post 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
Eddy8555
Posts: 42
Joined: Sat Apr 27, 2013 3:01 pm

Re: All images dragged into scene come at same size

Post 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?
iforce2d
Site Admin
Posts: 861
Joined: Sat Dec 22, 2012 7:20 pm

Re: All images dragged into scene come at same size

Post 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++.
Eddy8555
Posts: 42
Joined: Sat Apr 27, 2013 3:01 pm

Re: All images dragged into scene come at same size

Post 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.
iforce2d
Site Admin
Posts: 861
Joined: Sat Dec 22, 2012 7:20 pm

Re: All images dragged into scene come at same size

Post 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)
Eddy8555
Posts: 42
Joined: Sat Apr 27, 2013 3:01 pm

Re: All images dragged into scene come at same size

Post 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.)
Eddy8555
Posts: 42
Joined: Sat Apr 27, 2013 3:01 pm

Re: All images dragged into scene come at same size

Post 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.
iforce2d
Site Admin
Posts: 861
Joined: Sat Dec 22, 2012 7:20 pm

Re: All images dragged into scene come at same size

Post 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
Eddy8555
Posts: 42
Joined: Sat Apr 27, 2013 3:01 pm

Re: All images dragged into scene come at same size

Post 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 :)
Eddy8555
Posts: 42
Joined: Sat Apr 27, 2013 3:01 pm

Re: All images dragged into scene come at same size

Post 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?
Post Reply