当前位置: 首页>>代码示例>>C++>>正文


C++ Sprite::setPosition方法代码示例

本文整理汇总了C++中sf::Sprite::setPosition方法的典型用法代码示例。如果您正苦于以下问题:C++ Sprite::setPosition方法的具体用法?C++ Sprite::setPosition怎么用?C++ Sprite::setPosition使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在sf::Sprite的用法示例。


在下文中一共展示了Sprite::setPosition方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1: openChest

    void openChest(Chestwo, sf::Vector2f Pos, sf::Sprite s)
    {
        s.setPosition(Pos);
        window->draw(s);

    }
开发者ID:StylishTriangles,项目名称:TadzikEngine,代码行数:6,代码来源:rpg.hpp

示例2: supprimerMissile

sf::Sprite Missile::supprimerMissile(sf::Sprite sp)
{
    sp.setScale(0.0f, 0.0f);
    sp.setPosition(0.0f, 0.0f);
    return sp;
}
开发者ID:l3info-MBT,项目名称:Space_Wars,代码行数:6,代码来源:Missile.cpp

示例3: drawSpriteAtCell

 void GraphicsHandler::drawSpriteAtCell(sf::Sprite &s, std::size_t x, std::size_t y)
 {
     s.setPosition(x*board_config.cellWidth(), y*board_config.cellHeight());
     display.draw(s);
 }
开发者ID:AdnanHafeez,项目名称:ChessPlusPlus,代码行数:5,代码来源:Graphics.cpp

示例4: step_back

void character::step_back(){
    xpos -= xvel;
    ypos -= yvel;
    sprite.setPosition(sf::Vector2f(xpos, ypos));
    collision_box = sprite.getGlobalBounds();
}
开发者ID:deipfei,项目名称:MacPan,代码行数:6,代码来源:character.cpp

示例5: main

///
/// main function
//
int main()
{

	// Initialize the screen
	sf::RenderWindow rw(sf::VideoMode(640,496),"Caverns");
	global::rwpWindow = &rw;

	// Seed the random number generator
	ut::seed();
	std::cout << "seed: " << ut::current_seed << std::endl;

	// Set up fpscalc
	FpsCalc::GetInstance()->Init(60);

	// Load all the fonts
	global::fntMain.loadFromFile("resources/font/pixelette.ttf");
	global::fntDeath.loadFromFile("resources/font/trebucbd.ttf");

	// Load all the sounds
	global::SNDBUF_mine.loadFromFile("resources/sound/mine.wav");
	global::SNDBUF_zombie.loadFromFile("resources/sound/zombie.wav");
	global::SNDBUF_zombie_omg.loadFromFile("resources/sound/zombie_omg.wav");
	global::SNDBUF_player_hit.loadFromFile("resources/sound/player_hit.wav");
	global::SNDBUF_player_miss.loadFromFile("resources/sound/player_miss.wav");
	global::SNDBUF_player_hurt.loadFromFile("resources/sound/player_hurt.wav");
	global::SNDBUF_get_sword.loadFromFile("resources/sound/get_sword.wav");

	// Load all the textures
	global::TXT_player_down.loadFromFile("resources/texture/player_down.png");
	global::TXT_player_up.loadFromFile("resources/texture/player_up.png");
	global::TXT_player_left.loadFromFile("resources/texture/player_left.png");
	global::TXT_player_right.loadFromFile("resources/texture/player_right.png");
	global::TXT_player_down_sword.loadFromFile("resources/texture/player_down_sword.png");
	global::TXT_player_right_sword.loadFromFile("resources/texture/player_right_sword.png");

	global::TXT_wall.loadFromFile("resources/texture/wall.png");
	global::TXT_u_wall.loadFromFile("resources/texture/unbreakable_wall.png");
	global::TXT_exit.loadFromFile("resources/texture/exit.png");
	global::TXT_lantern.loadFromFile("resources/texture/lantern.png");
	global::TXT_chest_closed.loadFromFile("resources/texture/chest_closed.png");
	global::TXT_chest_open.loadFromFile("resources/texture/chest_open.png");

	global::TXT_menu.loadFromFile("resources/texture/menu.png");
	global::TXT_dead.loadFromFile("resources/texture/dead.png");
	global::TXT_pause.loadFromFile("resources/texture/paused.png");

	global::TXT_zombie_left.loadFromFile("resources/texture/zombie_left.png");
	global::TXT_zombie_right.loadFromFile("resources/texture/zombie_right.png");
	global::TXT_zombie_left_omg.loadFromFile("resources/texture/zombie_left_omg.png");
	global::TXT_zombie_right_omg.loadFromFile("resources/texture/zombie_right_omg.png");




	// Set sprites
	SPR_menu.setTexture(global::TXT_menu); SPR_menu.setPosition(0,0);
	SPR_dead.setTexture(global::TXT_dead); SPR_dead.setPosition(0,0);
	SPR_pause.setTexture(global::TXT_pause); SPR_pause.setPosition(0,0);




	///////           ///////
	// Enter the main loop //
	///////           ///////
	int loop_return = main_loop();




	// Close the screen
	global::rwpWindow->close();

	// Free all memmory used
	FpsCalc::GetInstance()->FreeMemory();

	return 0;
}
开发者ID:Lithumist,项目名称:Comp08,代码行数:81,代码来源:main.cpp

示例6: update

	//Drop item sprite render.
	void update(float time) {
		
		//if(~isMarkedForRemoval())
			mSprite.setPosition(mRect.left - offsetX, mRect.top - offsetY);

	}
开发者ID:dvotf,项目名称:Badass_Tales_Of_Badassland,代码行数:7,代码来源:main.cpp

示例7: while

int screen_1::Run(sf::RenderWindow &App)
{
    hop.setBuffer(hopFile);
    trucked.setBuffer(truckedFile);
    dunked.setBuffer(dunkedFile);
    
    // Clock
    sf:: Clock clock;
    sf::Time time;
    sf::Time delay;
    
    // Plays Intro
    intro.play();
    delay = intro.getDuration();
    
    time = clock.getElapsedTime();
    // Music
    while ( clock.getElapsedTime() <= delay )
    {
        //cout << "NO";
    }
    froggerTheme.setVolume(50);
    froggerTheme.play();
    clock.restart();
    
    sf::Event Event;
    
    bool Running = true;
    int sum = 0;// for log testing purposes
    int sum2 = 0;
    int sum3 = 0;
    int sum4 = 0;
    int sum5 = 0;
    int sum6 = 0;
    int sum7 = 0;
    int sum8 = 0;
    int sum9 = 0;
    int sum10 = 0;
    
    while (Running)
    {
        // Timer Rect and Clock
        double time = clock.getElapsedTime().asSeconds();
        
        if(time >= 1.5)
        {
            timeRect.width = timeRect.width - 2.383;
            timer.setTextureRect(timeRect);
            clock.restart();
        }
        
        if(timeRect.width <= 0)
        {
            frogOnLily1 = false;
            frogOnLily2 = false;
            frogOnLily3 = false;
            frogOnLily4 = false;
            frogOnLily5 = false;
            mainPlayer.setNumLives(3);
            rectSource.width = 115;
            life.setTextureRect(rectSource);
            occupied1.setPosition(-100, -100);
            occupied2.setPosition(-100, -100);
            occupied3.setPosition(-100, -100);
            occupied4.setPosition(-100, -100);
            occupied5.setPosition(-100, -100);
            froggerTheme.pause();
            clock.restart();
            timeRect.width = 143;
            timer.setTextureRect(timeRect);
            frogger.setPosition(320, 605);
            
            return 2;
        }
        // *********************************************************************
        // Creating the objects of Object class for continuous movement
        //
        // Object(double posX, double posY, double speed)
        // *********************************************************************
        // Trucks
        Object t1(130, 420,0.2 );
        Object t2(550, 290, 0.2);
        // Cars
        Object c1(-50, 420, 0.3);
        Object c2(280, 289, 0.2);
        Object c3(0, 289, 0.2);
        // Short Logs
        Object sl1(0, 125, 0.2);
        Object sl2(200, 61, 0.3);
        Object sl3(300, 8, 0.4);
        // Long Logs
        Object l1(799, 8.3, 0.4);
        Object l2(500, 125, 0.2);
        
        // Sets object's direction
        t1.moveRight(truck);
        t2.moveLeft(truck2);
        c1.moveRight(car);
        c2.moveLeft(car2);
        c3.moveLeft(car3);
//.........这里部分代码省略.........
开发者ID:EmilyGarcia,项目名称:Frogger,代码行数:101,代码来源:screen_1.hpp

示例8: CenterSprite

 void CenterSprite(sf::Sprite& sprite, const sf::RenderTarget& target)
 {
     sf::FloatRect sprite_bounds = sprite.getLocalBounds();
     sprite.setOrigin(sprite_bounds.left + (sprite_bounds.width/2.0f), sprite_bounds.top + (sprite_bounds.height/2.0f));
     sprite.setPosition(sf::Vector2f(target.getSize() / (unsigned)2));
 }
开发者ID:Dante12129,项目名称:DteEngine,代码行数:6,代码来源:Align.cpp

示例9: draw

void SpriteManager::draw(sf::Sprite sprite, float x, float y, sf::RenderWindow &window) {
    sprite.setPosition(x, y);
    window.draw(sprite);
}
开发者ID:TheOneThatIsChosen720,项目名称:Virtual-Pet,代码行数:4,代码来源:SpriteManager.cpp

示例10: CenterSpriteHor

 void CenterSpriteHor(sf::Sprite& sprite, const sf::RenderTarget& target)
 {
     sf::FloatRect sprite_bounds = sprite.getLocalBounds();
     sprite.setOrigin(sprite_bounds.left + (sprite_bounds.width/2.f), 0);
     sprite.setPosition(target.getSize().x/2.f, sprite.getPosition().y);
 }
开发者ID:Dante12129,项目名称:DteEngine,代码行数:6,代码来源:Align.cpp

示例11: CenterSpriteVert

 void CenterSpriteVert(sf::Sprite& sprite, const sf::RenderTarget& target)
 {
     sf::FloatRect sprite_bounds = sprite.getLocalBounds();
     sprite.setOrigin(0, sprite_bounds.top + (sprite_bounds.height/2.f));
     sprite.setPosition(sprite.getPosition().x, target.getSize().y/2.f);
 }
开发者ID:Dante12129,项目名称:DteEngine,代码行数:6,代码来源:Align.cpp

示例12: id

StateGameMenu::StateGameMenu(State* state, unsigned int id) :
background_state(state), id(id), toggle(true)
{ menu_pointer_sprt.setPosition(208, 178); }
开发者ID:vsrz,项目名称:VHH,代码行数:3,代码来源:stategamemenu.cpp

示例13: set_position

	void set_position(const sf::Vector2f& position)
	{
		
		m_sprite.setPosition(position);
		
	}
开发者ID:janderkkotlarski,项目名称:Gravtacles,代码行数:6,代码来源:Gravtacles_V0-7.cpp

示例14: colorizer

	MainMenu() : system(TextureManager::instance().getTexture("assets/rticle.png"))
	{
		pointer.setTexture(TextureManager::instance().getTexture("assets/two_pointer.png"));
		//pointer.setPosition(1183, 427);

		//system = new thor::ParticleSystem();

		emitter.setEmissionRate(0.5f);
		emitter.setParticleLifetime( sf::seconds(40) );

		emitter.setParticleRotation( thor::Distributions::uniform(0.f, 360.f) );
		emitter.setParticlePosition( sf::Vector2f(1260,740) );
		emitter.setParticleScale(sf::Vector2f(0.1,0.1));

		system.addEmitter(thor::refEmitter(emitter));

		thor::ColorGradient gradient;
		gradient[0.0f] = sf::Color::Magenta;
		gradient[0.1f] = sf::Color::Red;
		gradient[0.2f] = sf::Color::Blue;
		gradient[0.3f] = sf::Color::Cyan;
		gradient[0.4f] = sf::Color::Green;
		gradient[0.5f] = sf::Color::Red;
		gradient[0.6f] = sf::Color::Magenta;
		gradient[0.7f] = sf::Color::Cyan;
		gradient[0.8f] = sf::Color::Red;
		gradient[0.9f] = sf::Color::Blue;
		gradient[1.0f] = sf::Color::Red;

		thor::ColorAnimation colorizer(gradient);
		thor::FadeAnimation fader(0.1f, 0.1f);

		system.addAffector( thor::ScaleAffector(sf::Vector2f(0.1f,0.1)));	
		system.addAffector( thor::AnimationAffector(fader) );
		system.addAffector( thor::AnimationAffector(colorizer) );

		sprite = AnimatedSprite(sf::seconds(0.3));

		v.setTexture(TextureManager::instance().getTexture("assets/one_upper.png"));
		back2.setTexture(TextureManager::instance().getTexture("assets/two_menu.png"));
		logo.setTexture(TextureManager::instance().getTexture("assets/one_logo.png"));
		press.setTexture(TextureManager::instance().getTexture("assets/one_anybutton.png"));
		anim.setSpriteSheet(TextureManager::instance().getTexture("assets/one_animooted.jpg"));

		for (int i = 0; i < 5; i++)
		{
			anim.addFrame(sf::IntRect(0, 800 * i, WIDTH, HEIGHT));
		}

		sprite.setAnimation(anim);
		sprite.setLooped(true);
		sprite.play();

		logo.setColor(sf::Color(255,255,255,0));
		press.setColor(sf::Color(255,255,255,0));
		pointer.setColor(sf::Color(255,255,255,0));
		press.setPosition(WIDTH/2 - press.getTextureRect().width/2, HEIGHT/2 - press.getTextureRect().height/2 + 100);
		pressFading = true;

		newLogoY = 800;
		oTweener.addTween(&CDBTweener::TWEQ_BACK, CDBTweener::TWEA_INOUT, 2.f, &newLogoY, 0.0f);

		first = true;

		pressFactor = 0.2;
		transition = false;
		check = false;
		
		sm.init(sf::Vector2f(WIDTH, HEIGHT));
		rt.create(WIDTH, HEIGHT);

		MusicManager::instance().playMusicFast("low");

		selection = 1;
	};
开发者ID:TideSofDarK,项目名称:grief-trigger,代码行数:75,代码来源:c_main.cpp

示例15: update

void update(sf::RectangleShape floor[], sf::RectangleShape road[], int floorWidth, int floorHeightPosition, sf::Sprite& rrSprite, double &pos, bool &jumpStatus,
     bool& isoverlap, std::stringstream &ss, sf::Clock &clock, sf::Text &textTime, sf::Music& roadrunnerMusic, sf::Music& sanicMusic, sf::Sound& squawkSound, 
     bool& deathStatus, sf::Sprite& sanicSprite, sf::Sprite& sanicPowerupSprite, bool& sanicPowerupStatus, int& globalSpeed, sf::Time& sanicTime, bool& powerupSpawnStatus, 
     sf::Time& powerupSpawnTimer, sf::Sprite arrayOfObjectSprite[], bool& boulderSpawnStatus, int numObject, int objStop, sf::Sound& jumpSound, sf::RectangleShape backgroundbox[])
{
	//game timer
     if (!isoverlap)
	{
		sf::Time time1 = clock.getElapsedTime();
		ss.str(std::string());
		ss << setprecision(2) << fixed << static_cast<double>(time1.asSeconds());
		textTime.setString(ss.str().c_str());
	}

     // Return to roadrunner character
     if (clock.getElapsedTime() >= sanicTime && sanicPowerupStatus)
     {
          sanicMusic.pause();
          roadrunnerMusic.play();
          sanicPowerupStatus = false;
     }

     // How fast everything moves
     if (sanicPowerupStatus && (clock.getElapsedTime() <= sanicTime - sf::seconds(1)))         //sanic run speed
          globalSpeed = 100;
     else
          globalSpeed = 15;                                                                    //roadrunner run speed

     // Powerup spawner, checks every 10 seconds
     if (clock.getElapsedTime() >= powerupSpawnTimer)
     {
          powerupSpawnTimer += sf::seconds(10);                       //time to spawn for every consecutive powerup after the first
          powerupSpawnStatus = true;
     }

     // Powerup spawn chance
     if (powerupSpawnStatus)
     {
          if (rand() % 100 <= 33)                                 // 33% chance to spawn
          {
               sanicPowerupSprite.setScale(0.05, 0.05);
               sanicPowerupSprite.setPosition(floorWidth, 250);
          }
          powerupSpawnStatus = false;
     }

     // Sanicpowerup movement, how fast the icon moves
     if (sanicPowerupSprite.getPosition().x >= objStop)
          sanicPowerupSprite.move(-globalSpeed, 0);

     // Roadrunner and sanicpowerup collision
     if (overlap(rrSprite, sanicPowerupSprite) && !sanicPowerupStatus)
     {
          roadrunnerMusic.pause();
          sanicMusic.play();
          sanicPowerupStatus = true;
          sanicTime = clock.getElapsedTime() + sf::seconds(10);
          sanicPowerupSprite.setScale(0, 0);
     }

     //Infinite floor/road
     floor[0].move(-globalSpeed, 0);
     floor[1].move(-globalSpeed, 0);

     road[0].move(-globalSpeed, 0);
     road[1].move(-globalSpeed, 0);
     
     if (floor[0].getPosition().x <= -floorWidth)
	{
		floor[0].setPosition(0, floorHeightPosition);
		floor[1].setPosition(floorWidth, floorHeightPosition);

          road[0].setPosition(0, floorHeightPosition);
          road[1].setPosition(floorWidth, floorHeightPosition);
	}

     //backgroundbox, movement, infinite background
     if (sanicPowerupStatus && (clock.getElapsedTime() <= sanicTime - sf::seconds(1)))
     {
          backgroundbox[0].move(-globalSpeed / 2 + 10, 0);
          backgroundbox[1].move(-globalSpeed / 2 + 10, 0);
     }
     else
     {
          backgroundbox[0].move(-globalSpeed + 10, 0);
          backgroundbox[1].move(-globalSpeed + 10, 0);
     }

     if (backgroundbox[0].getPosition().x <= -floorWidth)
     {
          backgroundbox[0].setPosition(0, -100);
          backgroundbox[1].setPosition(floorWidth, -100);
     }
     
    
	// Roadrunner jump
     if (sf::Keyboard::isKeyPressed(sf::Keyboard::Up) && rrSprite.getPosition().y >= 505)
	{
		jumpStatus = true;
          jumpSound.play();
//.........这里部分代码省略.........
开发者ID:DevelopersGuild,项目名称:bird-squad,代码行数:101,代码来源:main.cpp


注:本文中的sf::Sprite::setPosition方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。