rotation - Cocos2dx继承的CCNode类不围绕其中心旋转?

标签 rotation ccsprite cocos2d-x

我在这里有点不知所措,如果已经有人问过这个问题,请原谅我 - 我已经在谷歌上搜索了很多,但我找不到任何东西?

我正在尝试旋转在类中生成的一组 Sprite ,然后在单击菜单项时在主游戏场景中旋转该对象,但旋转不在 Sprite 的中心?它是一个更大的区域,可能是层大小?

我尝试过将 anchor 设置为每种可能的组合?

这是 iv 得到的

这是游戏角色.h

    #define COMPUTE_X(x) ((abs(x)) * 16) + (16*2) + (16/2)
    #define COMPUTE_Y(y) (386 - (abs(y) * 16)) + (16/2)
    #define COMPUTE_X_Y(x,y) ccp( COMPUTE_X(x), COMPUTE_Y(y))

    // Game character class
    #include "cocos2d.h"
    using namespace cocos2d;

    //a class to encapsulate playable game character by creating a group of sprites etc..

    #ifndef GAMECHARACTER_H
    #define GAMECHARACTER_H

    class GameCharacter : public CCNode {

    private:

    //some private methods etc....

    public:

    void addSprite(const char* filename);
    void setInitialPosition(CCPoint* position);

    //Various other methods.........

    };

    #endif

    void GameCharacter::addSprite(const char* filename)
    {
    //go get the sprite sheet
    CCTexture2D* gameArtTexture = CCTextureCache::sharedTextureCache()->addPVRImage("SpriteSheet.pvr.ccz");
    CCSpriteBatchNode::batchNodeWithTexture(gameArtTexture);
    CCSprite *tempBlock = CCSprite::spriteWithSpriteFrameName(filename);
    this->addChild((CCSprite*)tempBlock,0);
    }

    void GameCharacter::setInitialPosition(CCPoint* position)
    {
    //loop through the positions and set the character up
    CCArray *children = this->getChildren();
    CCSprite *currentBlock;
    for (int i=0;i<7;i++){
    currentBlock = (CCSprite*) children->objectAtIndex(i);
    //compute x y grid positions (1,1) ---> to real (72,394)
    currentBlock->setPosition(COMPUTE_X_Y(position[i].x,position[i].y));
    }
    }

    This is the gamecharacter.cpp

    void GameScene::AddCharacter(CCPoint* position)
    {
    const char* filename;

    GameCharacter* character = new GameCharacter();

    for (int i = 0; i < 7; i++) {
    filename = helperFunctions::Format("character%d.png",i+1); //character1.png -> character7.png
    character->addSprite(filename);
    }

    character->setInitialPosition(position);
    this->addChild((CCSprite*) character,-1,2);
    _sprite = character;
    }

    //here is the menuitem click handler
    void GameScene::menuRotateRightCallback(CCObject* pSender)
    {
    //rotate the character right
    //really slowly so we can see whats happening
    _sprite->runAction((CCRotateBy::actionWithDuration(2.50,90)));

    }

谢谢

最佳答案

使用起来容易得多

x = center.x + cos(angle) * radius;
y = center.y + sin(angle) * radius;

关于rotation - Cocos2dx继承的CCNode类不围绕其中心旋转?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9403517/

相关文章:

CSS 动画 : span rotating

Java:三角形旋转 - 不成功的概念

iphone - 我想在检测到触摸点时移动 Sprite 体

objective-c - 如何正确使用 CCSpriteFrameCache 和 CCSpriteBatchNode?

c++ - CCArray 与 std::vector

ios - EXC_BAD_ACCESS 与 GCM 3.0

android-logcat - 对于 Eclipse,CCLog 不起作用。 CCMessageBox 运行良好

ios - 如何在没有 IB 的情况下控制对象的自动调整大小?

cocos2d-iphone - Cocos2d - 视网膜图像不显示

ios - 一个轴上的 Unity (iOS) 设备角度