Frage

I'm at a bit of a loss here, forgive me if this has already been asked - i've have searched google high and low but i cant find anything?

i'm trying to rotate a group of sprites that are generated in a class, then rotating this object in the main gamescene on a menuitem click but the rotation is not at the center of the sprite? it a some larger area probably the layer size?

I've tried setting the anchorpoint to every possible combination?

Here is what iv got

This is the gamecharacter.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)));

    }

Thanks

Keine korrekte Lösung

Lizenziert unter: CC-BY-SA mit Zuschreibung
Nicht verbunden mit StackOverflow
scroll top