示例#1
0
文件: tileset.cpp 项目: slumki/Gameka
void TileSet::reloadTilesetImage() {
    GameData *gameData = GameData::getInstance();

    printf("ProjectDirectory: %s\n", gameData->getProjectDirectory().c_str());

    printf("t:: %s\n", gameData->getProjectDirectory().append("/").append(file).c_str());

    tilesetImage = getTilesetAlphaImage(true);


}
示例#2
0
文件: tileset.cpp 项目: slumki/Gameka
QImage* TileSet::getTilesetAlphaImage(bool reset) {
    GameData *gameData = GameData::getInstance();

    if(tilesetImage == NULL || reset) {
        tilesetImage = new QImage(gameData->getProjectDirectory().append("/").append(file).c_str());


        if(hasColorKey) {
            QImage mask = tilesetImage->createMaskFromColor(QColor(colorkey_r, colorkey_g, colorkey_b).rgb());
            mask.invertPixels();
            tilesetImage->setAlphaChannel(mask);

        }

    }



    return tilesetImage;
}
void BackgroundsGraphicsScene::setBackground(Background *background) {
    GameData *gameData = GameData::getInstance();
    this->background = background;


    if(background != NULL) {
        for(std::vector<QGraphicsPixmapItem*>::iterator it = pixmapItems.begin(); it != pixmapItems.end(); ++it) {
            QGraphicsPixmapItem *graphisPixmapItem = *it;
            delete graphisPixmapItem;
        }

        pixmapItems.clear();

        for(std::vector<BgLayer*>::iterator it = background->layerList->begin(); it != background->layerList->end(); ++it) {
           BgLayer *bgLayer = *it;

           QGraphicsPixmapItem *graphicsPixmapItem = new QGraphicsPixmapItem(QPixmap(QString(gameData->getProjectDirectory().append("/").append(bgLayer->fileName).c_str())));
           pixmapItems.push_back(graphicsPixmapItem);

           graphicsPixmapItem->setPos(bgLayer->displacementX, bgLayer->displacementY);

           addItem(graphicsPixmapItem);
       }

        this->update();
    }



}