![]() ![]() ![]() Then when you destroy the fixture, you can remove the associated instance of MyFixtureUserDataType. MFixtureUserData.emplace_back( std::move(myUserData) ) MyUserData->mOwningFixture = body->CreateFixture( fixtureDef ) MyUserData->mObjectType = 3 // whatever this fixture is aboutį = reinterpret_cast(myUserData.get()) Then when you create your fixtures, you also create the data: // Store this somewhere in your game managing classes So somewhere in your code you need to create your own class: struct MyFixtureUserDataType Since the userData deals with "opaque pointers" (Box2d does not know what those are nor what they're for, only you do), and the example uses raw pointers, Box2d will not clean the memory associated to those once the Box2d objects are destroyed, you need to take care of cleaning those.Ī way to do it is to wrap those into smart pointers. The user data is an object that you control and you need hold alive for the whole life of the box2d object. This part of the official documentation illustrates how this should be done now, however it lacks an important information, IMHO. ![]() So it may explain why you see tutorials around that "do no work" with a more recent version of Box2d. They went from storing void pointers to storing an actual object. It seems that box2d recently changed the way they manage userData. When I did something like this, the program is crashing: struct B2_API b2FixtureUserData Next to the structure definition, it is written "You can define this to inject whatever data you want in b2Fixture". Previously, it was possible, as I understood, to create a body and write: tUserData = smth īut this is not possible because the method returns a structure: b2BodyUserData& b2Body::GetUserData() Void* fixtureUserData = contact->GetFixtureA()->GetUserData() įixturesUnderfoot.erase(contact->GetFixtureB()) //A is foot so B is groundįixturesUnderfoot.erase(contact->GetFixtureA()) //B is foot so A is ground Std::string fixtureUserData = contact->GetFixtureA()->getmy() įixturesUnderfoot.insert(contact->GetFixtureB()) //A is foot so B is groundįixtureUserData = contact->GetFixtureB()->GetUserData() įixturesUnderfoot.insert(contact->GetFixtureA()) //B is foot so A is ground This is what I want to do: class M圜ontactListener : public b2ContactListener But I don't understand how to do this correctly, because just adding a line to the structure of the program crashes. I found out that it is possible to edit the b2FixtureDef structure to add my new data there. After digging through the Box2d files for three days, I realized that I could not cope alone. Now there is no such function and userData should be set in a different way. But with the source of Box2d I have, I don't see the SetUserData functions in the code as I see them in the guides.Īfter understanding it, I realized that these manuals were outdated, and So if you are developing only for one specific resolution, you can use Device dimensions, otherwise it is suggested to use Logical dimensions with the scale mode you find suitable.Many guides used userData. They basically will be scaled based on the scale mode you choose. No matter what resolution you have, the logical dimensions will always be the same. Meaning on an iPhone 3GS it will return width as 320īut logical dimensions are exactly what you set in your project properties. You should use W = application:getContentWidth(), H = application:getContentHeight() which would return logical dimensions that are used when in scaling mode.īasically it all brings down to these points:ġ) Choose the scaling mode that is proper for your game (Letterbox being most popular)Ģ) Choose logical dimensions for your game and create all the graphics for logical dimensions you set in the project properties (recommended 480x800 or 640x960)ģ) Create backgrounds a little more bigger than logical dimensions to cover whitespaces on devices with different ratiosĤ) Use absolute positioning ( ) for objects that need to stick to sides of the screen as on screen buttons for exampleĥ) (Optionally) prepare bigger graphics in in some fixed ratio coefficient and use Automatic Image Resoltuion feature to automatically load them for bigger devicesĪddition: (Difference between device and logical dimensions)ĭevice dimensions is exactly what device has.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |