本文整理汇总了C++中sf::Sprite::setTextureRect方法的典型用法代码示例。如果您正苦于以下问题:C++ Sprite::setTextureRect方法的具体用法?C++ Sprite::setTextureRect怎么用?C++ Sprite::setTextureRect使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类sf::Sprite
的用法示例。
在下文中一共展示了Sprite::setTextureRect方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: Update
void Update(float fTime)
{
FRect.left += dx * fTime;
// x
Collision(0);
if (!bOnGround)
dy = dy + 0.0005f * fTime;
FRect.top += dy * fTime;
bOnGround = false;
// y
Collision(1);
fCurrentFrame += 0.005f * fTime;
if (fCurrentFrame > 3)
fCurrentFrame -= 3;
if(dx > 0)
SSprite.setTextureRect(sf::IntRect(112 + 30 * int(fCurrentFrame), 144, 16, 16));
if(dx < 0)
SSprite.setTextureRect(sf::IntRect(112 + 30 * int(fCurrentFrame) + 16, 144, -16, 16));
SSprite.setPosition(FRect.left - g_fOffsetX, FRect.top - g_fOffsetY);
dx = 0;
}
示例2: update
//Enemy sprite render.
void update(float deltaTime, char** levelMap, struct config* config) {
if(mDirection == 0) {mMovement.x = 0; mMovement.y = -mSpeed;}
if(mDirection == 1) {mMovement.x = mSpeed; mMovement.y = 0;}
if(mDirection == 2) {mMovement.x = 0; mMovement.y = mSpeed;}
if(mDirection == 3) {mMovement.x = mSpeed; mMovement.y = 0;}
mRect.left += mMovement.x * deltaTime;
collision(levelMap, config);
mRect.top += mMovement.y * deltaTime;
collision(levelMap, config);
//Enemy animation.
mCurrentFrame += mAnimationSpeed * deltaTime;
if(mCurrentFrame > mFrameCount) mCurrentFrame -= mFrameCount;
if(mMovement.x > 0) mSprite.setTextureRect(sf::IntRect(mRect.width * int(mCurrentFrame), 925, mRect.width, mRect.height));
if(mMovement.x < 0) mSprite.setTextureRect(sf::IntRect(mRect.width * int(mCurrentFrame), 667, mRect.width, mRect.height));
if(mMovement.y > 0) mSprite.setTextureRect(sf::IntRect(mRect.width * int(mCurrentFrame), 535, mRect.width, mRect.height));
if(mMovement.y < 0) mSprite.setTextureRect(sf::IntRect(mRect.width * int(mCurrentFrame), 787, mRect.width, mRect.height));
mSprite.setPosition(mRect.left - offsetX, mRect.top - offsetY);
mTextName.setPosition(mRect.left - offsetX, mRect.top - mTextName.getCharacterSize() - offsetY);
}
示例3:
//Player constructor.
Player(sf::Texture& texture, sf::Texture& hpImage, int x, int y, sf::Font& font) {
mSprite.setTexture(texture);
mRect = sf::FloatRect(x, y, 120, 110); //Character x, y, width, height.
mName = "Player 1";
mTextName.setString(mName);
mTextName.setFont(font);
mTextName.setCharacterSize(30);
mTextName.setStyle(sf::Text::Bold);
mTextName.setColor(sf::Color::Red);
mHpSprite.setTexture(hpImage);
mHpSprite.setTextureRect(sf::IntRect(0, 0, 100, 10));
mSprite.setTextureRect(sf::IntRect(0, 15, 120, 110));
mSpeed = 0.1;
mMovement.x = 0;
mMovement.y = 0;
mCurrentFrame = 0;
mAnimationSpeed = 0.005;
mIsAlive = true;
mHP = 100;
mMaxHp = 100;
mMP = 100;
}
示例4: moveLeft
void Player::moveLeft(int moveSpeed){
facing = left;
xPos -= moveSpeed;
if((xPos/10)%2 == 0)
playerSprite.setTextureRect(sf::IntRect(99, 0, 27, 40));
else
playerSprite.setTextureRect(sf::IntRect(339, 0, 27, 40));
playerSprite.setPosition(xPos, yPos);
}
示例5: moveRight
void Player::moveRight(int moveSpeed){
facing = right;
xPos += moveSpeed;
if((xPos/10)%2 == 0)
playerSprite.setTextureRect(sf::IntRect(659, 0, 27, 40));
else
playerSprite.setTextureRect(sf::IntRect(421, 0, 27, 40));
playerSprite.setPosition(xPos, yPos);
}
示例6: Flip
// The flip function works well TODO MOVE THIS SHIT
void Player::Flip(sf::Sprite& sprite)
{
if (Player::Direction==-1)
{
sprite.setTextureRect(
sf::IntRect(
sprite.getTextureRect().width, //TODO left+width?
0,
-sprite.getTextureRect().width,
sprite.getTextureRect().height
)
);
}
else
{
sprite.setTextureRect(Player::TextureRect);
}
}
示例7: get_sprite
void Animation::get_sprite(int frame, sf::Sprite& sprite) const
{
if ( d->tileset )
{
d->tileset->get_tile(d->start_tile+frame,sprite);
sf::IntRect ir = sprite.getTextureRect();
ir.left += d->offset.x;
ir.top += d->offset.y;
sprite.setTextureRect(ir);
}
}
示例8: setTexture
void TextureManager::setTexture(sf::Sprite& sprite, string name, unsigned int spriteIndex)
{
TextureData& data = textureMap[name];
if (data.texture.getSize().x < 1)
loadTexture(name, sf::Vector2i(0, 0));
if (spriteIndex < data.sprites.size())
{
sprite.setTexture(data.texture);
sprite.setTextureRect(data.sprites[spriteIndex]);
sprite.setOrigin(float(data.sprites[spriteIndex].width) / 2, float(data.sprites[spriteIndex].height) / 2);
}else{
sprite.setTexture(data.texture, true);
sprite.setOrigin(data.texture.getSize().x / 2, data.texture.getSize().y / 2);
}
}
示例9: Update
// update fucntion for animated sprite class
// pass in float that stores the time since last frame
void GHAnimatedSprite::Update(float timeSinceLastFrame)
{
// count the time change
timeSinceLastChange += timeSinceLastFrame;
if (timeSinceLastChange >= 0.25f)
{
// reset the timer
timeSinceLastChange = 0.0f;
//increment the frame counter
if (currentFrame >= 3)
{
currentFrame = 0;
}
else
{
currentFrame++;
}
//change the section of the texture
sprite.setTextureRect(sf::IntRect(64 * currentFrame, 0, 64, 64));
}
}
示例10: rand
//Enemy constructor.
Enemy(sf::Texture& texture, int x, int y, sf::Font& font) {
mSprite.setTexture(texture);
mRect = sf::FloatRect(x, y, 120, 110); //Character x, y, width, height.
mName = "Enemy";
mTextName.setString(mName);
mTextName.setFont(font);
mTextName.setCharacterSize(30);
mTextName.setStyle(sf::Text::Bold);
mTextName.setColor(sf::Color::Magenta);
mSprite.setTextureRect(sf::IntRect(0, 15, 120, 110));
mDirection = rand() % 4;
mSpeed = 0.05;
mCurrentFrame = 0;
mAnimationSpeed = mSpeed * 0.05;
mIsAlive = true;
mHP = 100;
mDamage = 30;
}
示例11: velY
Enemy (sf::Texture & tileset) :velX(2), velY(0)
{
sprite.setTexture(tileset);
sprite.setTextureRect(sf::IntRect(153,58,11,10));
}
示例12: rysuj_hud
void rysuj_hud( sf::RenderWindow & okno )
{
if( bonusik->zwroc_timer() > 0 )
alphaPaskaBonusu = 1;
// else
// if( bonusik->zwroc_timer() == 0 )
// alphaPaskaBonusu = 0;
if( bonusik->zwroc_timer() == 0 ){
if( alphaPaskaBonusu > 0 )
alphaPaskaBonusu -= 0.01;
}
spr_paskaBonusu.setColor( sf::Color( 255, 255, 255, 255*alphaPaskaBonusu));
/// GDY HP DOJDZIE DO STANU KRYTYCZNEGO, ZAMIEN NA CZERWONY KOLOR
// if( gracz->zwroc_hp() < 20 )
// spr_paskaHp.setColor( sf::Color( 255, 255, 255, 255 ) );
// else
// spr_paskaHp.setColor( sf::Color( 255, 255, 255, 255 ) );
// gracz->ustaw_hp( 10 );
for( int i = 0 ; i < 2 ; i++ )
{
spr_paskaHp.setTexture( tex_paskaHp[ i ] );
spr_paskaBonusu.setTexture( tex_paskaBonusu[ i ] );
// spr_paskaBonusu.setScale( 1.5, 1 );
if( i == 0 )
{
spr_paskaHp.setTextureRect( sf::IntRect( 0, 0, 153, 18 ) );
spr_paskaBonusu.setTextureRect( sf::IntRect( 0, 0, 578, 31 ) );
}
else
{
spr_paskaHp.setTextureRect( sf::IntRect( 0, 0,
(gracz->zwroc_hp()/gracz->zwroc_maxHP())*153, 18 ) );
spr_paskaBonusu.setTextureRect( sf::IntRect( 0, 0,
(bonusik->zwroc_timer() / bonusik->zwroc_maxTimer() )*578, 31 ) );
}
okno.draw( spr_paskaHp );
if( alphaPaskaBonusu > 0 )
{
okno.draw( spr_paskaBonusu );
}
}
rysuj_tekst( okno, "Poziom: ", ::lvl, 170, 5 );
// rysuj_tekst( okno, "Score: ", ::score );
rysuj_tekst( okno, L"Pozostało: ", ::potrzeba_zabitych - ::ilosc_zabitych, 520, 110 );
/// rysuj jaki lvl
/// rysuj ile punktow
/// rysuj jaki bonus
if( bonusik->x != -500 && bonusik->typ == -1 )
rysuj_tekst( okno,
L"Szybko, bonus jest na mapie\n\tmusisz go znaleźć!", 200, 100 );
if( bonusik->zwroc_timer() > 0 )
rysuj_tekst( okno, "Czas bonusu: ", bonusik->zwroc_timer() + 1, 285, 410 );
if( bonusik->typ != -1 )
{
ustaw_timer( 1, 2 );
typ_bonusu = bonusik->typ;
}
if( zwroc_timer( 1 ) != 0 )
{
switch( typ_bonusu )
{
case bonus_dmgUp:
rysuj_tekst( okno, L"Wylosowałes bonus: Zwiększenie ataku!", 200, 100 );
break;
case bonus_hpUp:
rysuj_tekst( okno, L"Wylosowałes bonus: Całkowite wyleczenie!", 200, 100 );
break;
case bonus_spdUp:
rysuj_tekst( okno, L"Wylosowałes bonus: Przyśpieszenie!", 200, 100 );
break;
case bonus_hpDown:
rysuj_tekst( okno, L"Co, ale że co?! HP ci spadło !", 200, 100 );
break;
case bonus_spdDown:
rysuj_tekst( okno, L"Chodzisz powooooli jak zółw...", 200, 100 );
break;
case bonus_immune:
rysuj_tekst( okno, L"Muahahaha! Nieśmiertelny! (czasowo ^^)", 200, 100 );
break;
case 6:
rysuj_tekst( okno, L"Nięęęęęę", 300, 10 );
break;
case -1: break;
default:
rysuj_tekst( okno, L"Nięę", 300, 10 );
break;
}
}
}
示例13: applyTo
void Animation::applyTo(sf::Sprite& sprite, const int index) {
if (index != -1)
frameAt = index;
sprite.setTextureRect(frames[frameAt]);
}
示例14: lunchAnimation
void Animation::lunchAnimation(sf::Sprite &sprite,int x,int y, int tailleX,int tailleY)
{
sprite.setTextureRect(sf::IntRect(x,y,tailleX,tailleY));
}
示例15: setTexture
void setTexture(sf::Texture & texture) { sprite.setTexture(texture); sprite.setTextureRect(sf::IntRect((type/2)*80,(type%2)*40,80,40)); }