1
我是新上cocos2dx
,并且这可能是一个愚蠢的错误,cocos2dx当我设置setPhysicsBody雪碧,雪碧了
我做了动画,我的精灵和它的工作。然后我添加PhysicsBody
到我的精灵碰撞。之后,当我开始游戏时,Sprite不在屏幕上,我没有得到任何错误。我检查了两次重力。我的代码是在这里
CCSpriteFrameCache* frameCache = CCSpriteFrameCache::sharedSpriteFrameCache();
frameCache->addSpriteFramesWithFile("RedFurryFall.plist");
CCSpriteBatchNode* spriteSheet = CCSpriteBatchNode::create("RedFurryFall.png");
this->addChild(spriteSheet);
Vector<SpriteFrame*> RedFurryFallFrames(4);
for (int i = 1; i < 5; i++) {
CCString * fileName = CCString::createWithFormat("RedFurryFall%d.png", i);
CCSpriteFrame* frame = CCSpriteFrameCache::sharedSpriteFrameCache()->spriteFrameByName(fileName->getCString());
RedFurryFallFrames.pushBack(frame);
}
CCAnimation* runAnim = CCAnimation::createWithSpriteFrames(RedFurryFallFrames, 0.15);
CCSprite* redFurry = CCSprite::createWithSpriteFrameName("RedFurryFall1.png");
CCSize winSize = CCDirector::sharedDirector()->getWinSize();
redFurry->setPosition(ccp(winSize.width*0.5, winSize.height*0.85));
redFurry->setScale(0.50);
auto physicsBody = PhysicsBody::createCircle(redFurry->getContentSize().width/2, PhysicsMaterial(0.1, 1, 0));
physicsBody->setDynamic(false);
physicsBody->setGravityEnable(false);
redFurry->setPhysicsBody(physicsBody);
CCAction*action = CCRepeatForever::create(CCAnimate::create(runAnim));
redFurry->runAction(action);
spriteSheet->addChild(redFurry);
当我删除此redFurry->setPhysicsBody(physicsBody);
我可以看到我的屏幕上的精灵。我无法弄清楚那有什么问题。感谢您的关注。
您可以为物理实体和精灵启用调试帧。但是大多数情况下,精灵的物理和位置出了问题。所以我建议设置一个断点,并看看你需要的精灵的位置。 – teivaz
下面的答案是否适合您? –