在我的游戏中,我有一个块精灵。有了这个精灵,我已经制作了一个块体,这样我的角色就无法穿过它了。
cocos2d::CCSprite* block = cocos2d::CCSprite::create("Block.png");
block->setPosition(ccp(5,20));
this->addChild(block);
b2BodyDef blockbodydef;
blockbodydef.type = b2_kinematicBody;
blockbodydef.position.Set(5/PTM_RATIO,20/PTM_RATIO);
blockbodydef.userData = block;
b2Body *blockbody = world->CreateBody(&blockbodydef);
b2PolygonShape blockPoly;
blockPoly.SetAsBox(37.5/PTM_RATIO , 37.5 / PTM_RATIO);
b2FixtureDef blockshapedef;
blockshapedef.shape = &blockPoly;
blockshapedef.density = 2.0f;
blockshapedef.friction = 0.2f;
blockshapedef.restitution = 0.8f;
blockbody->CreateFixture(&blockshapedef);
但是,我希望拥有多个这些块。有没有办法在没有原始精灵消失的情况下改变bodydef和sprite的位置,或者我是否必须为每个块创建不同的精灵?
答案 0 :(得分:0)
你必须为另一个块创建另一个精灵。纹理缓存在cocos2dx中,因此它只能从文件加载一次。