void Card::setSelected(bool selected) { this->selected = selected; if(selected) { SetImage(*selectedFrame->image); SetSubRect(selectedFrame->rectangle); } else { SetImage(*unselectedFrame->image); SetSubRect(unselectedFrame->rectangle); } }
bool Animation::AddFrame(sf::Image* NewFrame, unsigned int Length) { Images.push_back(NewFrame); ImageLengths.push_back(Length); if (Images.size() == 1) { SetSubRect(sf::Rect<int>(0,0,NewFrame->GetWidth(), NewFrame->GetHeight())); SetImage(*Images.at(CurrentImage)); } return true; }
void Animation::RecomputeSubRect() { assert(GetImage()); float width = GetImage()->GetWidth() / column_; float height = GetImage()->GetHeight() / row_; float x = width * (curFrame_ % column_); float y = height * (curFrame_ % row_); IntRect subRect(x, y, x + width, y + height); SetSubRect(subRect); }
bool Animation::addFrame(sf::Image* newFrame) { images.push_back(newFrame); if (images.size() == 1) { SetSubRect(sf::Rect<int>(0, 0, newFrame->GetWidth(), newFrame->GetHeight())); SetImage(*images.at(0)); } numImgs++; return true; }
//////////////////////////////////////////////////////////// /// Set the image of the sprite //////////////////////////////////////////////////////////// void Sprite::SetImage(const Image& Img) { // If there was no source image before and the new image is valid, adjust the source rectangle if (!myImage && (Img.GetWidth() > 0) && (Img.GetHeight() > 0)) { SetSubRect(IntRect(0, 0, Img.GetWidth(), Img.GetHeight())); } // Assign the new image myImage = &Img; }
void Sprite::SetTexture(const Texture& texture, bool adjustToNewSize) { // If there was no valid texture before, force adjusting to the new texture size if (!myTexture) adjustToNewSize = true; // If we want to adjust the size and the new texture is valid, we adjust the source rectangle if (adjustToNewSize && (texture.GetWidth() > 0) && (texture.GetHeight() > 0)) { SetSubRect(IntRect(0, 0, texture.GetWidth(), texture.GetHeight())); } // Assign the new texture myTexture = &texture; }
void Player::apply_image(int id_image, int tile_at_x, int tile_at_y) { if (id_image != -1) { m_data.image.id = id_image; m_data.image.at_x = tile_at_x; m_data.image.at_y = tile_at_y; SetImage(ImageManager::singleton().fetch(id_image)); SetSubRect(sf::IntRect( tile_at_x , tile_at_y, tile_at_x + ProjectManagerBase::tile_width , tile_at_y + ProjectManagerBase::tile_height )); } }
void TiledSprite::SetTileIndex(unsigned i){ // solo modifica si el nuevo número o índice de tile es != del actual if(i!=mCurrentTileIndex){ mCurrentTileIndex=i; // calcula las coordenadas del subrectangulo donde se encuentra el tile deseado int left, top, bottom, right; left=((mCurrentTileIndex%nCols)*tileW); top=((mCurrentTileIndex/nCols)*tileH); right=left+tileW; bottom=top+tileH; // indica que no debe utilizarse la textura entera para el dibujado, sino la region con el tile seleccionado SetSubRect(sf::IntRect(left, top, right, bottom)); } }
// Passer à l'image numéro X void Animated::SetFrame(int Frame) { if ( myAnim != NULL) { if (myAnim->Size() > 0) { if ((*myAnim)[Frame].Image != NULL) SetImage(*((*myAnim)[Frame].Image)); SetSubRect((*myAnim)[Frame].Rect); SetColor((*myAnim)[Frame].Color); myCurrentFrame = Frame; } } }
GameMob::GameMob(int type,sf::Vector2f position): GameEntity(GameConfig::g_imgManag["mobs"].img,1,1,true) ,m_type(type){ m_colWidth=GameConfig::g_mob[type].width; m_colHeight=GameConfig::g_mob[type].height; SetPosition(position); if(GameConfig::g_mob[type].path==0){ m_velx=50; m_vely=0; } else{ m_velx=0; m_vely=50; } stop(); SetSubRect(sf::IntRect(GameConfig::g_mob[type].x,GameConfig::g_mob[type].y,m_colWidth,m_colHeight)); }