Welcome, Guest. Please login or register. Did you miss your activation email?

Author Topic: Rotate a Sprite centered  (Read 2964 times)

0 Members and 1 Guest are viewing this topic.

ShadoWhy

  • Newbie
  • *
  • Posts: 2
    • View Profile
    • Email
Rotate a Sprite centered
« on: May 25, 2017, 01:35:34 pm »
I using SFML 2.4.2
My english is not the best sorry for mistakes.
I try to make a Pseudo3D Object(an Emerald or something like this) and have tried to Rotate the Picture.

The Variables of the Code are:
Defines:
#define DEFAULT_BIT_SCALE 4
#define DEFAULT_BIT_SIZE    8
 
Objects:
sf::Texture texture;
sf::Sprite sprite[DEFAULT_BIT_SIZE];
 

The Code in the Init look like this:
void bit8::Cube::init()
{      
        //Its an test Texture
        this->texture.loadFromFile("gfx/8x8x8.png");
        this->texture.setRepeated(false);
        this->texture.setSmooth(false);
       
        //This is the code for creation for test a cube
        for (int i = 0; i < DEFAULT_BIT_SIZE; i++) {
                this->sprite[i].setTexture(texture);
                this->sprite[i].setTextureRect(sf::IntRect(i * DEFAULT_BIT_SIZE, 0, DEFAULT_BIT_SIZE, DEFAULT_BIT_SIZE));
                this->sprite[i].setScale(DEFAULT_BIT_SCALE, DEFAULT_BIT_SCALE);
                this->sprite[i].setPosition(200, 300 + i*DEFAULT_BIT_SCALE);
               
        }
}
 

The Code for the Rotate look like this:
float degrees = 0
for (int i = 0; i < DEFAULT_BIT_SIZE; i++) {
                if (degrees > 359.90) {
                        degrees = 0;
                }
                degrees += 0.1f;
                this->sprite[i].setRotation(degrees);
        }
 
I don't know if the Question is in the right place.
And I have the problem that I have to change the Rotation axis to the Center and dont know a way to do that.
So is the question how to do the axis in the center.
Thanks for any answers.
« Last Edit: May 25, 2017, 01:40:18 pm by ShadoWhy »

GameBear

  • Jr. Member
  • **
  • Posts: 73
    • View Profile
    • Email
Re: Rotate a Sprite centered
« Reply #1 on: May 25, 2017, 03:30:47 pm »
string message = "some random dude";
cout << "I'm just " << message;

Hapax

  • Hero Member
  • *****
  • Posts: 3379
  • My number of posts is shown in hexadecimal.
    • View Profile
    • Links
Re: Rotate a Sprite centered
« Reply #2 on: May 25, 2017, 05:04:38 pm »
Note that the position is also based around the origin so you may need to adjust your positions after changing the origin.
Selba Ward -SFML drawables
Cheese Map -Drawable Layered Tile Map
Kairos -Timing Library
Grambol
 *Hapaxia Links*

ShadoWhy

  • Newbie
  • *
  • Posts: 2
    • View Profile
    • Email
Re: Rotate a Sprite centered
« Reply #3 on: May 30, 2017, 05:53:36 pm »
Thanks.
It works.

Carlos Augusto Br Cpp

  • Newbie
  • *
  • Posts: 40
  • Programming is life
    • View Profile
    • Email
Re: Rotate a Sprite centered
« Reply #4 on: June 01, 2017, 05:30:54 pm »
good... please put [SOLVED] on the name of this post, to help people know that you have get it... I was writing an answer when I see that you got it to works...  ;D

 

anything