我已经完成了以下功能,它包含 26 if else block in update。所以它反映了 FPS 的小幅下降。
我已经使用动态转换检查了 26 个对象。取决于形状,我检查了逻辑。
这是编码。
void WagonNode::update(float dt)
{
int found = 0;
for (int32 i = 0; i < kMaxContactPoints100 && found < contactPointCount100_; i++)
{
ContactPoint100* point = contactPoints100_ + i;
b2Fixture *otherFix = point->otherFixture;
if( otherFix )
{
found++;
b2Body *otherBody = otherFix->GetBody();
BodyNode *otherNode = (BodyNode*) otherBody->GetUserData();
if (dynamic_cast<ShapeA*>(otherNode) != NULL)
{
tagWord(CCString::create("A"));
}
else if (dynamic_cast<ShapeB*>(otherNode) != NULL)
{
tagWord(CCString::create("B"));
}
else if (dynamic_cast<ShapeC*>(otherNode) != NULL)
{
tagWord(CCString::create("C"));
}
else if (dynamic_cast<ShapeD*>(otherNode) != NULL)
{
tagWord(CCString::create("D"));
}
else if (dynamic_cast<ShapeE*>(otherNode) != NULL)
{
tagWord(CCString::create("E"));
}
else if (dynamic_cast<ShapeF*>(otherNode) != NULL)
{
tagWord(CCString::create("F"));
}
else if (dynamic_cast<ShapeG*>(otherNode) != NULL)
{
tagWord(CCString::create("G"));
}
else if (dynamic_cast<ShapeH*>(otherNode) != NULL)
{
tagWord(CCString::create("H"));
}
else if (dynamic_cast<ShapeI*>(otherNode) != NULL)
{
tagWord(CCString::create("I"));
}
else if (dynamic_cast<ShapeJ*>(otherNode) != NULL)
{
tagWord(CCString::create("J"));
}
else if (dynamic_cast<ShapeK*>(otherNode) != NULL)
{
tagWord(CCString::create("K"));
}
else if (dynamic_cast<ShapeL*>(otherNode) != NULL)
{
tagWord(CCString::create("L"));
}
else if (dynamic_cast<ShapeM*>(otherNode) != NULL)
{
tagWord(CCString::create("M"));
}
etc...
}
}
}
如果上述编码有任何变化,那将对我有很大帮助。
任何人都可以帮助我处理或稳定 FPS 吗?