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


C++ RectangleShape::getPosition方法代码示例

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


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

示例1: isInRect

bool CreditsMenu::isInRect(sf::Vector2i position, sf::RectangleShape menuItemRect)
{
	return(menuItemRect.getPosition().y < position.y && 
			menuItemRect.getPosition().y + menuItemRect.getSize().y > position.y &&
			menuItemRect.getPosition().x < position.x &&
			menuItemRect.getPosition().x + menuItemRect.getSize().x > position.x);
}
开发者ID:PhilipUL,项目名称:bacterium,代码行数:7,代码来源:CreditsMenu.cpp

示例2: checkColl

//Ugly collision detection!
bool Game::checkColl(sf::RectangleShape first, sf::RectangleShape second) const
{
    double firstMaxX = first.getPosition().x + first.getSize().x/2.0;
    double firstMinX = first.getPosition().x - first.getSize().x/2.0;
    double firstMaxY = first.getPosition().y + first.getSize().y/2.0;
    double firstMinY = first.getPosition().y - first.getSize().y/2.0;

    double secondMaxX = second.getPosition().x + second.getSize().x/2.0;
    double secondMinX = second.getPosition().x - second.getSize().x/2.0;
    double secondMaxY = second.getPosition().y + second.getSize().y/2.0;
    double secondMinY = second.getPosition().y - second.getSize().y/2.0;

    if (firstMaxX < secondMinX ||
        firstMaxY < secondMinY ||
        firstMinX > secondMaxX ||
        firstMinY > secondMaxY)
    {
        return false;
    }
    else
    {
        return true;
    }

}
开发者ID:samanthadoran,项目名称:PrototypeVaders,代码行数:26,代码来源:game.cpp

示例3: IsPossibleCollisionWithTopOrBottomSide

bool CollisionChecker::IsPossibleCollisionWithTopOrBottomSide(sf::RectangleShape &r1, sf::RectangleShape &r2)
{
    if(r1.getPosition().x+r1.getGlobalBounds().width > r2.getPosition().x
    && r1.getPosition().x < r2.getPosition().x+r2.getGlobalBounds().width){
        return true;
    }

    return false;
}
开发者ID:emSon150,项目名称:WhereAreMyEggs,代码行数:9,代码来源:CollisionChecker.cpp

示例4: IsPossibleCollisionWithLeftOrRightSide

bool CollisionChecker::IsPossibleCollisionWithLeftOrRightSide(sf::RectangleShape &r1, sf::RectangleShape &r2)
{
    if(r1.getPosition().y+r1.getGlobalBounds().height > r2.getPosition().y
    && r1.getPosition().y < r2.getPosition().y+r2.getGlobalBounds().height){
        return true;
    }

    return false;
}
开发者ID:emSon150,项目名称:WhereAreMyEggs,代码行数:9,代码来源:CollisionChecker.cpp

示例5: Physic

    void Physic(float time)
    {
        Control(time);

        if (recShape->getPosition().x <= 50)
            recShape->setPosition(sf::Vector2f(50, recShape->getPosition().y));
        else if (recShape->getPosition().x >= 974)
            recShape->setPosition(sf::Vector2f(974, recShape->getPosition().y));
    }
开发者ID:valerion1,项目名称:Games,代码行数:9,代码来源:Player.hpp

示例6: 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);*/
}
开发者ID:3991,项目名称:Game-25486,代码行数:57,代码来源:WindowCreateThing.hpp

示例7:

//Creates a sf::rectangleshape representing a button with given color
Button::Button(sf::RectangleShape &rect, sf::Color col) :
mRect(rect),
mMoveToPosition(rect.getPosition().x, rect.getPosition().y),
mDirection(0, 0),
mIsOnPosition(true),
mSpeed(100),
mMode(RectangleShape)
{
	mRect.setPosition(rect.getPosition().x, rect.getPosition().y);
	mRect.setFillColor(col);
}
开发者ID:Arqu3,项目名称:Spelprojekt-1,代码行数:12,代码来源:Button.cpp

示例8: IsCollidingWithRightSide

bool CollisionChecker::IsCollidingWithRightSide(sf::RectangleShape &r1, sf::RectangleShape &r2)
{
    if(r1.getPosition().x <= r2.getPosition().x+r2.getGlobalBounds().width
    && r1.getPosition().x >= r2.getPosition().x
    && r1.getPosition().y+r1.getGlobalBounds().height > r2.getPosition().y
    && r1.getPosition().y < r2.getPosition().y+r2.getGlobalBounds().height){
        return true;
    }

    return false;
}
开发者ID:emSon150,项目名称:WhereAreMyEggs,代码行数:11,代码来源:CollisionChecker.cpp

示例9: ifCollide

bool ifCollide(const sf::RectangleShape& A, const sf::RectangleShape& B)
{
	float aRad = A.getGlobalBounds().height;
	float bRad = B.getGlobalBounds().height;
	float length = (aRad + bRad)/2.f;

	sf::Vector2f aPos = A.getPosition();
	sf::Vector2f bPos = B.getPosition();
	sf::Vector2f diff = aPos - bPos;

	float magn = sqrt(diff.x*diff.x + diff.y*diff.y);

	return magn <= length;
}
开发者ID:DrJonki,项目名称:Ludum-Dare-30,代码行数:14,代码来源:PlayState.cpp

示例10: Control

    void Control(float time)
    {
        /*if (event.type == sf::Event::KeyPressed)
        {
        	if (event.key.code == sf::Keyboard::A || event.key.code == sf::Keyboard::Left)
        		recShape->setPosition(sf::Vector2f(recShape->getPosition().x - 10. * time, recShape->getPosition().y));
        	else if (event.key.code == sf::Keyboard::D || event.key.code == sf::Keyboard::Right)
        		recShape->setPosition(sf::Vector2f(recShape->getPosition().x + 10. * time, recShape->getPosition().y));
        	std::cout << "press";
        }*/

        if (sf::Keyboard::isKeyPressed(sf::Keyboard::A) || sf::Keyboard::isKeyPressed(sf::Keyboard::Left))
            recShape->setPosition(sf::Vector2f(recShape->getPosition().x - 0.5 * time, recShape->getPosition().y));
        else if (sf::Keyboard::isKeyPressed(sf::Keyboard::D) || sf::Keyboard::isKeyPressed(sf::Keyboard::Right))
            recShape->setPosition(sf::Vector2f(recShape->getPosition().x + 0.5 * time, recShape->getPosition().y));
    }
开发者ID:valerion1,项目名称:Games,代码行数:16,代码来源:Player.hpp

示例11: 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;
	}
}
开发者ID:MartenMoti,项目名称:yummy-octo-kidney,代码行数:16,代码来源:tic-tac-toe.cpp

示例12: game_update

void game_update(float elapsedTime)
{
    static float moveSpeed = 100.0f;

    color.a += 1;
    r.setFillColor(color);

    if(r.getPosition().x + r.getSize().x > g_pEngine->getScreenWidth() ||
        r.getPosition().x < 0)
    {
        moveDir *= -1;
        moveSpeed += 1;
    }

    r.move(moveSpeed * elapsedTime * moveDir, 0);
}
开发者ID:SwarmofPeanuts,项目名称:dice-roller-test-program,代码行数:16,代码来源:main.cpp

示例13: ClipVector

bool Ray::ClipVector(int axis, sf::RectangleShape& boxIn)
{
	float tempClipFractionLow = 0;
	float tempClipFractionHigh = 1;//temp Fractions
	

	//gets fraction of vector that fits inside of bounding box
	if(axis == 0)//x axis
	{
		tempClipFractionLow = (((boxIn.getPosition().x - boxIn.getGlobalBounds().width/2) - startPos.x)/(endPos.x - startPos.x));
		tempClipFractionHigh = (((boxIn.getPosition().x + boxIn.getGlobalBounds().width/2) - startPos.x)/(endPos.x - startPos.x));
	}
	else if(axis == 1)//y axis
	{
		tempClipFractionLow = (((boxIn.getPosition().y + boxIn.getGlobalBounds().height/2) - startPos.y)/(endPos.y - startPos.y));
		tempClipFractionHigh = (((boxIn.getPosition().y - boxIn.getGlobalBounds().height/2) - startPos.y)/(endPos.y - startPos.y));
	}
	else
	{
		return false;
	}

	if(tempClipFractionHigh < tempClipFractionLow)
	{
		swap(tempClipFractionHigh,tempClipFractionLow);
	}

	if(tempClipFractionHigh < clipFractionLow)
	{
		return false;
	}
	else
	if(tempClipFractionLow > clipFractionHigh)
	{
		return false;
	}

	clipFractionLow = max(tempClipFractionLow,clipFractionLow);
	clipFractionHigh = min(tempClipFractionHigh,clipFractionHigh);

	if(clipFractionLow > clipFractionHigh)
	{
		return false;
	}

	return true;
}
开发者ID:BenDy557,项目名称:Football,代码行数:47,代码来源:Ray.cpp

示例14: getMassCenter

    massCenter getMassCenter(){
        massCenter mc;

        mc.x = playerSprite.getPosition().x + (playerSprite.getSize().x/2);
        mc.y = playerSprite.getPosition().y + (playerSprite.getSize().y/2);

        return mc;

    }
开发者ID:2Def,项目名称:JumpSimulation,代码行数:9,代码来源:jump.cpp

示例15: set_square_position

//set square (user) position
void set_square_position(){
    sf::Vector2f v = square.getPosition();

    if(v.x < 0){
        square.setPosition(0, window_y - shape_size);}

    else if(v.x > window_x){
        square.setPosition(window_x - shape_size, window_y - shape_size);}
}
开发者ID:janicelihuang,项目名称:final_land,代码行数:10,代码来源:test_night_sky.cpp


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