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


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

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


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

示例1: movement

void movement(sf::Sprite& character, sf::RenderWindow& window)
{
	float moveSpeed = 0.1, moveSpeedR = -0.1;

	if (sf::Keyboard::isKeyPressed(sf::Keyboard::LShift))
	{
		moveSpeed /= 2.2;
		moveSpeedR /= 2.2;
	}

	if (sf::Keyboard::isKeyPressed(sf::Keyboard::Z))
	{
		moveSpeed *= 2.2;
		moveSpeedR *= 2.2;
	}

	if (sf::Keyboard::isKeyPressed(sf::Keyboard::Up))
	{
		character.move(0, moveSpeedR);
	}
	if (sf::Keyboard::isKeyPressed(sf::Keyboard::Down))
	{
		character.move(0, moveSpeed);
	}
	if (sf::Keyboard::isKeyPressed(sf::Keyboard::Right))
	{
		character.move(moveSpeed, 0);
	}
	if (sf::Keyboard::isKeyPressed(sf::Keyboard::Left))
	{
		character.move(moveSpeedR, 0);
	}
}
开发者ID:erinbui,项目名称:pacfish,代码行数:33,代码来源:main.cpp

示例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);
	}
}
开发者ID:Epsilonn2,项目名称:modelisation,代码行数:33,代码来源:Menu.cpp

示例3: Inputer

// fucntion to handle player input during the game
void Inputer(sf::Sprite &playerSprite, float deltaTime) 
{
	// Check the boundry
	int boundry[4] = 
	{ 
		0,
		0,
		4000,
		4000 
	};
	
	// declare vector2f variable to store player position
	sf::Vector2f pos = playerSprite.getPosition();

	// move player at a velocity of 300 * variable deltaTime
	float velocity = 300.0f * deltaTime;

	// take key input from player, check boundary, and move accordingly at stored velocity
	if (sf::Keyboard::isKeyPressed(sf::Keyboard::Left)) 
	{
		if (pos.x > boundry[0]) playerSprite.move(-velocity, 0);
	}
	if (sf::Keyboard::isKeyPressed(sf::Keyboard::Right))
	{
		if (pos.x < boundry[2]) playerSprite.move(velocity, 0);
	}
	if (sf::Keyboard::isKeyPressed(sf::Keyboard::Up)) 
	{
		if (pos.y > boundry[1]) playerSprite.move(0, -velocity);
	}
	if (sf::Keyboard::isKeyPressed(sf::Keyboard::Down)) 
	{
		if (pos.y < boundry[3]) playerSprite.move(0, velocity);
	}
}
开发者ID:natblank,项目名称:MDU118_project_2,代码行数:36,代码来源:Main.cpp

示例4: move

void move(float x, float y, sf::Sprite& sprite, sf::Sprite obstacle)
{
    sprite.move(x, y);

    if(sprite.getGlobalBounds().intersects(obstacle.getGlobalBounds()))
    {
        sprite.move(-x, -y);
    }
}
开发者ID:esenti,项目名称:labshooter,代码行数:9,代码来源:main.cpp

示例5: movement

void movement(sf::Sprite& PacFish, sf::RenderWindow& window, sf::Sprite WallSprites[], int sizeOfArray, vector<sf::Sprite>& bullets)
{

	float moveSpeed = 4, moveSpeedR = -4;
	sf::Vector2f currentPos = PacFish.getPosition();
	if (sf::Keyboard::isKeyPressed(sf::Keyboard::LShift))
	{
		moveSpeed /= 2.2;
		moveSpeedR /= 2.2;
	}
	if (sf::Keyboard::isKeyPressed(sf::Keyboard::Z))
	{
		moveSpeed *= 2.2;
		moveSpeedR *= 2.2;
	}


	if (PacFish.getPosition().y >= 0 && PacFish.getPosition().y <= window.getSize().y)
	{
		if (sf::Keyboard::isKeyPressed(sf::Keyboard::Up))
		{
			PacFish.move(0, moveSpeedR);
		}
		if (sf::Keyboard::isKeyPressed(sf::Keyboard::Down))
		{
			PacFish.move(0, moveSpeed);
		}
		if (PacFish.getPosition().y <= 0)
			PacFish.setPosition(currentPos);
		if (PacFish.getPosition().y >= window.getSize().y - 56)
			PacFish.setPosition(currentPos);
	}

	if (PacFish.getPosition().x >= 0 && PacFish.getPosition().x <= window.getSize().x)
	{
		if (sf::Keyboard::isKeyPressed(sf::Keyboard::Right))
		{
			PacFish.move(moveSpeed, 0);
		}

		if (sf::Keyboard::isKeyPressed(sf::Keyboard::Left))
		{
			PacFish.move(moveSpeedR, 0);
		}
		if (PacFish.getPosition().x <= 0)
			PacFish.setPosition(currentPos);
		if (PacFish.getPosition().x >= window.getSize().x - 66)
			PacFish.setPosition(currentPos);
	}


	// collisions
	handleWalls(PacFish, currentPos, WallSprites, sizeOfArray);
	handleBullets(PacFish, currentPos, bullets);

}
开发者ID:DevelopersGuild,项目名称:pacfish,代码行数:56,代码来源:main.cpp

示例6: goDirection

	void goDirection(const int &dir, sf::Sprite &spritesheet)
	{
		switch (dir) {
		case 0:
			spritesheet.move(sf::Vector2f(0, -3));
			break;
		case 1:
			spritesheet.move(sf::Vector2f(0, 3));
			break;
		case 2:
			spritesheet.move(sf::Vector2f(3, 0));
			break;
		case 3:
			spritesheet.move(sf::Vector2f(-3, 0));
			break;
		}
	}
开发者ID:amanuel2,项目名称:C-Examples,代码行数:17,代码来源:AnimationWithMouvment.cpp

示例7: think

	void think(float dt)
	{
		static float inc = 0.0f;

		inc += 1*dt;

		if( inc >= 2*PI) inc = 0.0f;

		sprite.move( std::sin(inc*velX), 0);
	}
开发者ID:stephenap07,项目名称:furry-ninja,代码行数:10,代码来源:Enemy.hpp

示例8: update

	void update(sf::RenderWindow& _window) {
		_spriteG.move(_velocity.x, _velocity.y);//Personnage qui bouge


		sf::Vector2f _positionRect = sf::Vector2f(43, 50);
		_positionRect.x = _spriteG.getPosition().x;
		_positionRect.y = _spriteG.getPosition().y;

		_rect.setPosition(_positionRect.x, _positionRect.y);
	}
开发者ID:W0Z4,项目名称:ProjetMario,代码行数:10,代码来源:Goomba.hpp

示例9: Scenery

                                Scenery(LevelBlock* host
                                        , const sf::Texture& texture)
                                : mHostBlock(host)
                                , mSprite(texture)
                                {
                                    sf::FloatRect bounds = mSprite.getLocalBounds();
                                    mSprite.setOrigin(bounds.width / 2.f, bounds.height / 2.f);

                                    mSprite.move(20.f, 20.f);
                                };
开发者ID:RichardSlade,项目名称:Flocky-Sheep,代码行数:10,代码来源:Scenery.hpp

示例10: boundsCheck

Level::BoundType Level::boundsCheck(sf::Sprite& entity, const bool vert)
{
    BoundType intersects = NO_BOUND;
    int difference = 0;
    sf::Sprite tempSprite;
    sf::FloatRect firstBound, secondBound, tempBound;

    //Setup Entity Bounds
    //The constant multiples are to give the bounds some buffer from the edges of the bounds so that,
    //for example, a BoundType::BOTTOM_BOUND doesnt trigger when running into a wall on the right
    if (vert) {
        //Top Bound
        firstBound.left = entity.getGlobalBounds().left + (entity.getGlobalBounds().width * .10);
        firstBound.top = entity.getGlobalBounds().top;
        firstBound.width = entity.getGlobalBounds().width - (entity.getGlobalBounds().width * .20);
        firstBound.height = 1;
        //Bottom Bound
        secondBound.left = entity.getGlobalBounds().left + (entity.getGlobalBounds().width * .10);
        secondBound.top = entity.getGlobalBounds().top + entity.getGlobalBounds().height;
        secondBound.width = entity.getGlobalBounds().width - (entity.getGlobalBounds().width * .20);
        secondBound.height = 1;
    } else {
        //Left Bound
        firstBound.left = entity.getGlobalBounds().left;
        firstBound.top = entity.getGlobalBounds().top + (entity.getGlobalBounds().height * 0.15);
        firstBound.width = 1;
        firstBound.height = entity.getGlobalBounds().height - (entity.getGlobalBounds().height * 0.30);
        //Right Bound
        secondBound.left = entity.getGlobalBounds().left + entity.getGlobalBounds().width;
        secondBound.top = entity.getGlobalBounds().top + (entity.getGlobalBounds().height * 0.15);
        secondBound.width = 1;
        secondBound.height = entity.getGlobalBounds().height - (entity.getGlobalBounds().height * 0.30);
    }

    //Search activeTiles Until Intersection Is Found Or None
    for (int i = 0; i < activeTiles.size() && intersects == NO_BOUND; ++i) {
        tempSprite = activeTiles[i];
        tempBound = tempSprite.getGlobalBounds();

        if (firstBound.intersects(tempBound)) {
            if (vert) {
                difference = tempBound.top + tempBound.height;
                difference -= entity.getGlobalBounds().top;
                entity.move(0, difference);
                intersects = TOP_BOUND;
            } else {
                difference = tempBound.left + tempBound.width;
                difference -= entity.getGlobalBounds().left;
                entity.move(difference, 0);
                intersects = LEFT_BOUND;
            }
        } else if (secondBound.intersects(tempBound)) {
            if (vert) {
                difference = tempBound.top;
                difference -= entity.getGlobalBounds().top + entity.getGlobalBounds().height;
                entity.move(0, difference);
                intersects = BOTTOM_BOUND;
            } else {
                difference = tempBound.left;
                difference -= entity.getGlobalBounds().left + entity.getGlobalBounds().width;
                entity.move(difference, 0);
                intersects = RIGHT_BOUND;
            }
        }
    }

    return intersects;
}
开发者ID:GGist,项目名称:SpriteEngine,代码行数:68,代码来源:Level.cpp

示例11: 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

示例12: planeAutoMoveDown

void Object::planeAutoMoveDown(sf::Sprite &plane)
{
	plane.move(0, enemyMoveSpeed1);	// round 1

}
开发者ID:lc4t,项目名称:Fighters,代码行数:5,代码来源:Object.cpp

示例13:

int screen_1::Run(sf::RenderWindow &App)
{
	sf::Event Event;

	bool Running = true;

	while (Running)
	{
		//Verifying events
		while (App.pollEvent(Event))
		{
			// Window closed
			if (Event.type == sf::Event::Closed)
			{
				return (-1);
			}
			//Key pressed
			if (sf::Keyboard::isKeyPressed(sf::Keyboard::Left))
			{
				sf::Vector2f pos = frogger.getPosition();

				if (pos.x <= 15 || (pos.x <= 15 && pos.y <= 675))
				{
					frogger.move(0, 0);
				}// end if
				else
				{
					if (rectSourceSprite.left != 216)
					{
						rectSourceSprite.left = 216;
						rectSourceSprite.width = 55;
						frogger.setTextureRect(rectSourceSprite);
					}// end if

					frogger.move(-50, 0);

				}// end else
			}// end if
			if (sf::Keyboard::isKeyPressed(sf::Keyboard::Right))
			{
				sf::Vector2f pos = frogger.getPosition();

				if (pos.x >= 690)
				{
					frogger.move(0, 0);
				}// end if
				else
				{
					if (rectSourceSprite.left != 89)
					{
						rectSourceSprite.left = 89;
						rectSourceSprite.width = 60;
						frogger.setTextureRect(rectSourceSprite);
					}// end if

					frogger.move(50, 0);

				}// end else
			}// end if
			if (sf::Keyboard::isKeyPressed(sf::Keyboard::Up))
			{
				sf::Vector2f pos = frogger.getPosition();

				if (pos.y <= -35)
				{
					frogger.move(0, 0);
				}// end if
				else
				{
					if (rectSourceSprite.left != 0)
					{
						rectSourceSprite.left = 0;
						rectSourceSprite.width = 89;
						frogger.setTextureRect(rectSourceSprite);
					}// end if

					frogger.move(0, -50);
				}
			}// end if
			if (sf::Keyboard::isKeyPressed(sf::Keyboard::Down))
			{
				sf::Vector2f pos = frogger.getPosition();

				if (pos.y >= 540)
				{
					frogger.move(0, 0);
				}// end if
				else
				{
					if (rectSourceSprite.left != 149)
					{
						rectSourceSprite.left = 149;
						rectSourceSprite.width = 67;
						frogger.setTextureRect(rectSourceSprite);
					}// end if

					frogger.move(0, 50);

				}// end else
			}// end if
//.........这里部分代码省略.........
开发者ID:jesusmperez,项目名称:Frogger_Css2A_Project,代码行数:101,代码来源:screen_x.hpp

示例14: move_by

 void move_by(T p)
 {
     circ.move(p);
     sprite.move(p);
     vision_aura.move(p);
 }
开发者ID:dvbuntu,项目名称:ogre,代码行数:6,代码来源:ogre_obj.hpp

示例15: 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


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