本文整理汇总了C++中sf::Sprite::setTexture方法的典型用法代码示例。如果您正苦于以下问题:C++ Sprite::setTexture方法的具体用法?C++ Sprite::setTexture怎么用?C++ Sprite::setTexture使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类sf::Sprite
的用法示例。
在下文中一共展示了Sprite::setTexture方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1:
//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;
}
示例2: moveLeft
/**
*\fn void moveLeft(void)
*\brief allows the Tamagotchi to move
*\param None
*\return Null
*/
void moveLeft(sf::Sprite &t, sf::Texture &t1, sf::Texture &t2)
{
sf::Vector2f pos = t.getPosition();
if(pos.x < 2)
{
D = 0;
}
if(pos.x > 600)
{
D = 1;
}
if(D == 0)
{
t.move(+1, 0);
t.setTexture(t2, 1);
}
if(D == 1)
{
t.move(-1, 0);
t.setTexture(t1, 1);
}
}
示例3: Initialize
void StateGameMenu::Initialize()
{
menu_pointer_tex.loadFromFile("./Resources/Images/gamemenu_pointer.png");
menu_pointer_sprt.setTexture(menu_pointer_tex);
menu_tex.loadFromFile("./Resources/Images/gamemenu.png");
menu_sprt.setTexture(menu_tex);
menu_sprt.setPosition(180, 142);
}
示例4: actualizarImagenExplocionPequenia
bool actualizarImagenExplocionPequenia(float currentTime){
float temporal= currentTime - tiempoInicio;
if(temporal <100){
imagen.loadFromFile("graphics/SmallExp00.png");
sprite.setTexture(imagen, true);
return true;
}
if(temporal >100 && temporal < 200){
imagen.loadFromFile("graphics/SmallExp00.png");
sprite.setTexture(imagen, true);
return true;
}
if(temporal >200 && temporal < 300){
imagen.loadFromFile("graphics/SmallExp01.png");
sprite.setTexture(imagen, true);
return true;
}
if(temporal >300 && temporal < 400){
imagen.loadFromFile("graphics/SmallExp01.png");
sprite.setTexture(imagen, true);
}
if(temporal >400 && temporal < 500){
imagen.loadFromFile("graphics/SmallExp02.png");
sprite.setTexture(imagen, true);
}
if(temporal >500 && temporal < 600){
imagen.loadFromFile("graphics/SmallExp02.png");
sprite.setTexture(imagen, true);
return true;
}
if(temporal >600 && temporal < 700){
imagen.loadFromFile("graphics/SmallExp03.png");
sprite.setTexture(imagen, true);
return true;
}
if(temporal >700 && temporal < 800){
imagen.loadFromFile("graphics/SmallExp03.png");
sprite.setTexture(imagen, true);
return true;
}
if(temporal >800 && temporal < 1200){
imagen.loadFromFile("graphics/SmallExp04.png");
sprite.setTexture(imagen, true);
return true;
}
if(temporal >1200 && temporal < 1700){
imagen.loadFromFile("graphics/SmallExp04.png");
sprite.setTexture(imagen, true);
return true;
}
else
{
return false;
}
};
示例5: 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);
}
}
示例6: setTexture
void cursor::setTexture(string cursorPass)
{
sprite.setTexture(textureManager.get(cursorPass));
sprite.setOrigin((Collision::GetSpriteSize(sprite).x / sprite.getScale().x / 2), (Collision::GetSpriteSize(sprite).y / sprite.getScale().y / 2));
sprite.rotate(-90);
sprite.setColor(sf::Color(255, 255, 255, settings.getCursorAplha()));
}
示例7: drawSprite
void drawSprite(int x, int y, double w, double h, TextureIndex textureIndex)
{
freeSprite.setPosition(x, y);
freeSprite.setTexture(getTexture(textureIndex));
freeSprite.setScale(w / getTexture(textureIndex).getSize().x, h / getTexture(textureIndex).getSize().y);
window->draw(freeSprite);
}
示例8: click
void click(sf::RectangleShape rectangle,sf::Sprite &sprite, bool &clicked, bool &player, sf::Texture &crossTexture, sf::Texture &circleTexture, sf::Event &event) {
if (((rectangle.getPosition().x <= event.mouseButton.x && event.mouseButton.x <= rectangle.getLocalBounds().width + rectangle.getPosition().x) &&
(rectangle.getPosition().y <= event.mouseButton.y && event.mouseButton.y <= rectangle.getLocalBounds().height + rectangle.getPosition().y)) &&
!(clicked)) {
std::cout << "You clicked on a rectangle" << std::endl;
clicked = true;
if (player) {
std::cout << "cross" << std::endl;
sprite.setTexture(crossTexture);
} else {
std::cout << "circle" << std::endl;
sprite.setTexture(circleTexture);
}
player = !player;
}
}
示例9: resolve
void resolve() {
shifter(cx);
// Shift the palette for this iteration.
for(int y = 0; y < imageHeight; ++y) {
// In the imaginary axis...
double c_im = MaxIm - (y * Im_factor);
// The current imaginary is the max value minus the scaled vertical iterator.
for(int x=0; x<imageWidth; ++x) {
// In the real axis...
double c_re = MinRe + (x * Re_factor);
// The current real is the min value plus the scaled horizontal iterator.
c.real = c_re;
c.imag = c_im;
// Change the real and imaginary components of the global complex variable c.
int iters = fractal();
// The returned value is the escape iterations for the current coordinate
col = sf::Color(iters * 4, iters * 4, iters * 4, 255);
// Create a color based on the current scape iterations.
imagen.setPixel(x, y, col);
// Set the image pixel at this current location to that color.
}
}
mandtex.update(imagen);
// Update the texture.
mandelb.setTexture(mandtex);
// Set the texture to the window.
}
示例10: load_image
void _Log::load_image(){
if( image_loaded == false && image_path.length() != 0 ) {
texture_1.loadFromFile( image_path );
Sprite.setTexture( texture_1, false );
sf::IntRect spr_data = Sprite.getTextureRect();
float x,y = WINDOW_HEIGHT - spr_data.height;
switch( align ){
case 1: x = 0.f; break;
case 2: x = WINDOW_WIDTH * 0.25 - spr_data.width /2; break;
case 3: x = WINDOW_WIDTH * 0.5 - spr_data.width /2; break;
case 4: x = WINDOW_WIDTH * 0.75 - spr_data.width /2; break;
case 5: x = WINDOW_WIDTH - spr_data.width; break;
}
Sprite.setPosition( x, y );
cout << x << " " << y << endl;
image_loaded = true;
}
}
示例11: init
void init() {
m_first_trip = false;
m_current_state = IDLE;
getBody()->GetFixtureList()->SetUserData("Checkpoint");
getBody()->SetUserData(this);
//Load Texture
s_texture = "Assets/Game/cp_ps.png";
m_text_size = sf::Vector2u(42, 94);
m_sprite.setTexture(ResourceManager<sf::Texture>::instance()->get(s_texture));
m_sprite.setOrigin(m_text_size.x / 2, m_text_size.y / 2);
m_sprite.setPosition(vHelper::toSF(getBody()->GetPosition()));
addFrames(frame_idle, 0, 0, 1, 42, 94, 1.0f);
addFrames(frame_trip, 1, 0, 5, 42, 94, 1.0f);
addFrames(frame_active, 2, 0, 3, 42, 94, 1.0f);
m_animator.addAnimation(IDLE, frame_idle, sf::seconds(1.0f));
m_animator.addAnimation(TRIP, frame_trip, sf::seconds(0.4f));
m_animator.addAnimation(ACTIVE, frame_active, sf::seconds(0.3f));
//Load Audio
s_noise = "Assets/Audio/Game/cp.wav";
m_noise.setBuffer(ResourceManager<sf::SoundBuffer>::instance()->get(s_noise));
}
示例12: init
void WindowCreateThing::init(sf::RenderWindow &window) {
rectTitle.setSize(sf::Vector2f(window.getSize().x*0.45, window.getSize().y*0.07));
rectTitle.setPosition(sf::Vector2f(window.getSize().x/2-(rectTitle.getSize().x/2), window.getSize().x/4-(rectTitle.getSize().y/2)));
rectTitle.setFillColor(sf::Color(158, 158, 158));
rectTitle.setOutlineColor(sf::Color::Black);
rectTitle.setOutlineThickness(1.f);
rectMain.setSize(sf::Vector2f(window.getSize().x*0.45,window.getSize().y*0.45));
rectMain.setPosition(sf::Vector2f(rectTitle.getPosition().x, rectTitle.getPosition().y+rectTitle.getSize().y));
rectMain.setFillColor(sf::Color::White);
rectMain.setOutlineColor(sf::Color::Black);
rectMain.setOutlineThickness(1.f);
load();
starting_position = sf::Mouse::getPosition(window);
textTitle.setFont(font);
textTitle.setString("CreateThings.txt");
textTitle.setCharacterSize(24);
textTitle.setColor(sf::Color::White);
textTitle.setPosition(sf::Vector2f(rectTitle.getPosition().x+rectTitle.getSize().x*0.3, rectTitle.getPosition().y+rectTitle.getSize().y*0.1));
//textTitle.setPosition(sf::Vector2f(400,10));
textClose.setFont(font);
textClose.setString("X");
textClose.setStyle(sf::Text::Bold);
textClose.setCharacterSize(35);
textClose.setColor(sf::Color::White);
textClose.setPosition(sf::Vector2f(rectTitle.getPosition().x+rectTitle.getSize().x-30, rectTitle.getPosition().y+rectTitle.getSize().y*0.05));
///// FOLDER ICONE
textureFolder.setSmooth(true);
spriteFodler.setTexture(textureFolder);
sf::Vector2f targetSize(25.0f, 25.0f);
spriteFodler.setScale(
targetSize.x / spriteFodler.getLocalBounds().width,
targetSize.y / spriteFodler.getLocalBounds().height);
spriteFodler.setPosition(sf::Vector2f(textTitle.getPosition().x-targetSize.x, textTitle.getPosition().y));
///// CLOSE ICONE
/*textureClose.setSmooth(true);
spriteClose.setTexture(textureClose);
sf::Vector2f targetSize2(window.getSize().y*0.07, window.getSize().y*0.07);
spriteClose.setScale(
targetSize2.x / spriteClose.getLocalBounds().width,
targetSize2.y / spriteClose.getLocalBounds().height);
spriteClose.setPosition(rectTitle.getPosition().x+rectTitle.getSize().x-targetSize2.x, rectTitle.getPosition().y);*/
}
示例13: hud
hud()
{
tex_paskaHp[ 0 ].loadFromFile( "gfx/pasek_hpTlo.png" );
tex_paskaHp[ 1 ].loadFromFile( "gfx/pasek_hp.png" );
tex_paskaBonusu[ 0 ].loadFromFile( "gfx/pasek_bonusTlo.png" );
tex_paskaBonusu[ 1 ].loadFromFile( "gfx/pasek_bonus.png" );
spr_paskaHp.setTexture( tex_paskaHp[ 0 ] );
spr_paskaBonusu.setTexture( tex_paskaBonusu[ 0 ] );
tex_tla.loadFromFile( "gfx/tlo0.png" );
czcionka.loadFromFile( "font/Barme Reczny.ttf" );
tekst.setFont( czcionka );
tekst.setCharacterSize( 18 );
timer[ 0 ] = 0;
timer[ 1 ] = 0;
typ_bonusu = 0;
alphaPaskaBonusu = 0.0001;
// spr_paskaBonusu.setColor( sf::Color( 255, 255, 255, alphaPaskaBonusu ) );
}
示例14: init
virtual void init()
{
dt=0;
select_switch = 0.2;
if (!standard_font.loadFromFile("fonts/Unique.ttf"))
{
// error...
}
// darken = sf::RectangleShape(sf::Vector2f(800,400));
//sfx
if (!buffer.loadFromFile("sfx/Blip 007.wav"))
{
//error
}
blip.setBuffer(buffer);
if(!title.loadFromFile("gfx/title.png"))std::cout<<"Error"<<std::endl;
tits.setTexture(title);
tits.setOrigin(50,8);
tits.setScale(sf::Vector2f(3,3));
tits.setPosition(400,100);
sf::FloatRect tempt ;
for(int i =0 ; i<4;i++)
{
selector[i].setFont(standard_font);
selector[i].setCharacterSize(28);
// dla centrowania obiektow
tempt = selector[i].getGlobalBounds();
selector[i].setOrigin(sf::Vector2f(tempt.width/2,tempt.height/2));
selector[i].setPosition(350,150+30*i);
}
selector[0].setString("Start game");
selector[1].setString("Info");
selector[2].setString("Highscores");
selector[3].setString("Exit");
selector[0].setColor(sf::Color(0,127,127));
timer.restart();
};
示例15: Set
void Set(sf::Texture &Img, int x, int y)
{
SSprite.setTexture(Img);
FRect = sf::FloatRect(float(x), float(y), 16, 16);
fCurrentFrame = 0.0f;
bLife = true;
dx = 0.05f;
//dy = 0.0f;
}