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


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

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


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

示例1: rotate

        void rotate () {
            if (ControlScheme == Joystick) {
                float X, Y, X2, Y2, xDif, yDif;
                X = Sprite.getPosition().x;
                Y = Sprite.getPosition().y;
                X2 = X + sf::Joystick::getAxisPosition(PlayerNumber, sf::Joystick::X);
                Y2 = Y + sf::Joystick::getAxisPosition(PlayerNumber, sf::Joystick::Y);

                xDif = X - X2;
                yDif = Y - Y2;

                float R, U, RA, UA, R2, U2, rDif, uDif;
                R = Sprite.getPosition().x;
                U = Sprite.getPosition().y;
                RA = sf::Joystick::getAxisPosition(PlayerNumber, sf::Joystick::R);
                UA = sf::Joystick::getAxisPosition(PlayerNumber, sf::Joystick::U);

                R2 = R + RA;
                U2 = U + UA;

                rDif = R - R2;
                uDif = U - U2;

                double RUAngle = atan2(rDif, uDif);
                RUAngle *= (180/3.1415);
                RUAngle -= 90;

                double angle = atan2(yDif, xDif);
                angle *= (180/3.1415);
                angle -= 90;
                if (RA > 20 || RA < -20 || UA > 20 || UA < -20) Sprite.setRotation(RUAngle);
                else Sprite.setRotation(angle);
                angle -= 90;
                angle *= (3.1415/180);
                } else {
                    float X, Y, X2, Y2, xDif, yDif;
                    X = Sprite.getPosition().x;
                    Y = Sprite.getPosition().y;
                    X2 = sf::Mouse::getPosition(App).x;
                    Y2 = sf::Mouse::getPosition(App).y;

                    xDif = X - X2;
                    yDif = Y - Y2;

                    double angle = atan2(yDif, xDif);
                    angle *= (180/3.1415);
                    angle -= 90;
                    Sprite.setRotation(angle);
                    angle -= 90;
                    angle *= (3.1415/180);
                    }
            }
开发者ID:IncredibleSulk,项目名称:Neverdoom,代码行数:52,代码来源:players.hpp

示例2: manageHit

void cursor::manageHit()
{
    if(hit)
    {
        hitSprite.setColor(sf::Color(255, 255, 255, 255));
        hit = false;
    }
    else if(hitSprite.getColor().a > 0)
    {
        int currentAlpha = hitSprite.getColor().a;
        a += timeModifier;
        while(a > 1)
        {
            currentAlpha -= 15;
            a -= 15;
        }
        if(a < 0)
            a = 0;

        if(currentAlpha < 0)
            currentAlpha = 0;

        hitSprite.setColor(sf::Color(255, 255, 255, currentAlpha));
    }
    hitSprite.setPosition(sprite.getPosition());
    hitSprite.setRotation(sprite.getRotation());
}
开发者ID:KoczurekK,项目名称:Battle-of-Hrubieszow-old,代码行数:27,代码来源:cursor.hpp

示例3: LowAmmo

void cursor::LowAmmo(int current, int maximum)
{
    lowAmmoSprite.setPosition(sprite.getPosition());
    lowAmmoSprite.setRotation(sprite.getRotation());

    double ammoLimit = 0.3 * maximum;
    double ammoPseudoPercentage = static_cast <float> (current) / ammoLimit;
    ammoPseudoPercentage *= 255;

    lowAmmoSprite.setColor(sf::Color(255, 255, 255, 255 - ammoPseudoPercentage));
}
开发者ID:KoczurekK,项目名称:Battle-of-Hrubieszow-old,代码行数:11,代码来源:cursor.hpp

示例4: HighAmmo

void cursor::HighAmmo(int current, int maximum)
{
    highAmmoSprite.setPosition(sprite.getPosition());
    highAmmoSprite.setRotation(sprite.getRotation());

    double pseudoAmmo = current - (0.7 * maximum);
    double pseudoAmmoMax = maximum - (0.7 * maximum);

    double ammoPseudoPercentage = static_cast <float> (pseudoAmmo) / pseudoAmmoMax;
    ammoPseudoPercentage *= 255;

    highAmmoSprite.setColor(sf::Color(255, 255, 255, ammoPseudoPercentage));
}
开发者ID:KoczurekK,项目名称:Battle-of-Hrubieszow-old,代码行数:13,代码来源:cursor.hpp

示例5: main


//.........这里部分代码省略.........
    size_t size = 0;
    sf::ConvexShape cShape;
    cShape.setFillColor(sf::Color::Red);
    //This loops through every single body in the game world
    for(b2Body* b = world->GetBodyList(); b; b = b->GetNext()) {
      //This loops through every fixture in the current body
      for(b2Fixture* f = b->GetFixtureList(); f; f = f->GetNext()) {
        //This checks to see if the type of the fixture is a polygon, if it is then draw the polygon
        if(f->GetType() == b2Shape::e_polygon && currentLevel != 2) {
          // Create the convex shape
          static sf::ConvexShape cShape;
          cShape.setFillColor(sf::Color::Red);
          //Stores a pointer to the shape stored in the fixture
          b2PolygonShape* s = (b2PolygonShape*)f->GetShape();
          //Get the amount of vertices stored in the shape
          size = s->GetVertexCount();
          //Set the size of the object in SFML so it knows how many vertices the shape should have
          cShape.setPointCount(size);
          //Loop through the vertices and send them from Box2D to the SFML shape
          for(int i = 0; i < size; i++) {
            //Stores the current vertex in v
            b2Vec2 v = s->GetVertex(i);
            //Converts the vertex from its local space to where it is in the world
            cShape.setPoint(i, sf::Vector2f((b->GetWorldVector(v).x + b->GetPosition().x), (b->GetWorldVector(v).y + b->GetPosition().y)));
          }
          //Draws the shape onto the window
          window.draw(cShape);
        }
        else if ((f->GetType() == b2Shape::e_polygon && b->GetType() == b2_dynamicBody)) {
          static sf::Sprite bikeFrame;
          bikeFrame.setTexture(bikeFrame_t);
          bikeFrame.setPosition(f->GetBody()->GetPosition().x, f->GetBody()->GetPosition().y);
          bikeFrame.setScale(0.5f,0.5f);
          bikeFrame.setRotation(b->GetAngle() * 57.2957795f);
          bikeFrame.setOrigin(0,0);
          window.draw(bikeFrame);
        }
        else if (f->GetType() == b2CircleShape::e_circle) {
          //  // Create A cricle to be drawn
          //  static sf::CircleShape circle;
          //  circle.setFillColor(sf::Color::Green);
          //  //Stores a pointer to the shape stored in the fixture
          //  b2PolygonShape* s = (b2PolygonShape*)f->GetShape();
          //  // Calculate the radius for the SFML circle
          //  circle.setRadius(s->m_radius);
          //  circle.setPosition(f->GetBody()->GetPosition().x - circle.getRadius(), f->GetBody()->GetPosition().y - circle.getRadius());
          //  window.draw(circle);

          b2PolygonShape* s = (b2PolygonShape*)f->GetShape();
          static sf::Sprite sWheel;
          sWheel.setScale((s->m_radius*0.01)*2,(s->m_radius*0.01)*2);
          sWheel.setPosition (f->GetBody()->GetPosition().x, f->GetBody()->GetPosition().y);
          
          if(currentLevel == 1) sWheel.setTexture(wheel);
          if(currentLevel == 2) sWheel.setTexture(bikeWheel);
          sWheel.setOrigin(50,50);
          sWheel.setRotation(b->GetAngle() * 57.2957795f);
          window.draw(sWheel);

        }
      }
    }
    #pragma endregion

    #pragma region DrawClickedLines
    // draw all elements in line vector
开发者ID:DaveRune,项目名称:SFML-Box2D,代码行数:67,代码来源:main.cpp

示例6: setRotation

 void                            setRotation(float rotation){ mSprite.setRotation(rotation); }
开发者ID:RichardSlade,项目名称:MscFinalProject,代码行数:1,代码来源:Entity.hpp


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