Scaling images / sprites to the body scale

General discussion about the R.U.B.E editor
Post Reply
Eddy8555
Posts: 42
Joined: Sat Apr 27, 2013 3:01 pm

Scaling images / sprites to the body scale

Post by Eddy8555 »

I'm using RUBE to draw a polygon around an image, and exporting it to my program. There I create a CCSprite and work with it in Android. So far so good.

Now, I need to have a larger car in my program. So I go to RUBE, drop the car image onto the scene, draw the body polygon, and then scale it to my desired size. But in my program, the image is still the same size, so I get a "ghost" care around my car image.

So the question is, how do I sale the image? Or in cocos2d terms, how do I scale the sprite?

For quick reference, this is how I create the sprite:

CCSprite sprite = CCSprite.sprite(imageName);
layer.addChild(sprite, 0);
body.setUserData(sprite);

So I'm looking for something like:

sprite.scaleTo(body.getScale());
iforce2d
Site Admin
Posts: 861
Joined: Sat Dec 22, 2012 7:20 pm

Re: Scaling images / sprites to the body scale

Post by iforce2d »

Take a look at the cocos2d sample project which does this. 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. You might also be interested in the screenToWorld and worldToScreen functions in the BasicRUBELayer, as an example of how coordinates can be converted. This project is intended for iOS, but afaik all the concepts used in cocos2d (sprites etc) should be common to the Android version.
Post Reply