У меня есть объект b2body, например прямоугольник, как его уменьшить или увеличить? Как сам объект, так и его спрайт-курс. создать объект так:cocos2d-x: Box2d Scaling
bool Horizontal_balka::initWithWorld(b2World *world)
{
NotCut=false;
star=false;
deleteStar=false;
int32 count = 4;
string file = "Horizontal_balka.png";
b2Vec2 vertices[] = {
b2Vec2(0.0/PTM_RATIO,26.0/PTM_RATIO),
b2Vec2(0.0/PTM_RATIO,0.0/PTM_RATIO),
b2Vec2(412.0/PTM_RATIO,0.0/PTM_RATIO),
b2Vec2(412.0/PTM_RATIO,26.0/PTM_RATIO)
/*b2Vec2(60.0/PTM_RATIO,14.0/PTM_RATIO),
b2Vec2(34.0/PTM_RATIO,59.0/PTM_RATIO),
b2Vec2(28.0/PTM_RATIO,59.0/PTM_RATIO)*/
};
CCSize screen = CCDirector::sharedDirector()->getWinSize();
b2Body *body = createBodyForWorld(world, b2Vec2(screen.width/2/PTM_RATIO, screen.height/2/PTM_RATIO), 0, vertices, count, 5.0, .2, .2);
PolygonSprite::initWithFile(file, body, true);
return true;
}
PolygonSprite.cpp:
bool PolygonSprite::initWithFile(string filename, b2Body *body, bool original)
{
CCTexture2D *texture = CCTextureCache::sharedTextureCache()->addImage(filename.c_str());
return initWithTexture(texture, body, original);
}
bool PolygonSprite::initWithTexture(cocos2d::CCTexture2D *texture, b2Body *body, bool original)
{
b2Fixture *originalFixture = body->GetFixtureList();
b2PolygonShape *shape = (b2PolygonShape*)originalFixture->GetShape();
int vertextCount = shape->GetVertexCount();
vector<Vector2d> points;
for (int i = 0; i < vertextCount; i++)
{
Vector2d p = Vector2d(shape->GetVertex(i).x * PTM_RATIO, shape->GetVertex(i).y * PTM_RATIO);
points.push_back(p);
}
PRFilledPolygon::initWithPointsAndTexture(points, texture);
_body = body;
_body->SetUserData(this);
_original = original;
_centriod = _body->GetLocalCenter();
this->setAnchorPoint(ccp(_centriod.x * PTM_RATIO/texture->getContentSize().width,
_centriod.y * PTM_RATIO/texture->getContentSize().height));
return true;
}
Как я могу уменьшить размер объекта в 2 раза? И, конечно, сам спрайт уменьшается
Вы пытаетесь уменьшить конкретный объект относительно других объектов или пытаетесь одновременно уменьшить размер всех объектов в своей сцене? – FuzzyBunnySlippers