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

Show Posts

This section allows you to view all posts made by this member. Note that you can only see posts made in areas you currently have access to.


Messages - amator

Pages: [1]
1
Graphics / Incorrect coordinates after SetCenter on Sprite (1.6)
« on: April 26, 2012, 06:16:01 pm »
Hi!

I have a problem with setting coordinates after SetCenter call in sf::Sprite.
The problem is that I can't see sprite although coordinates are corrected.
Before the SetCenter call is OK on the same code  :(

Code: [Select]
tempBox.mSprite.SetImage(mPlatformImage);
tempBox.mSprite.Resize(tempHeight.mEndPoint - tempHeight.mStartPoint, 32);
tempBox.mSprite.SetCenter(tempBox.mSprite.GetSize().x / 2, tempBox.mSprite.GetSize().y / 2);
tempBox.mSprite.SetPosition(tempHeight.mStartPoint - tempBox.mSprite.GetCenter().x, tempHeight.mHeight - tempBox.mSprite.GetCenter().y);

Size of mSprite after Resize():
- width: 1536
- height: 32

- mEndPoint: 1520
- mStartPoint: -16
- mHeight: 402

Window resolution: 640x480

Let me add that I have a sf::View, centered on the center of the window and all the time I do a 2px offset in X axis.

Where is the problem?
Please, help me.


EDIT:
I recreated the problem with simple code. You can compile it and check (uncomment this line and comment out again).
Code: [Select]
#include <SFML/Graphics.hpp>
 
 int main()
 {
     sf::RenderWindow *window = new sf::RenderWindow(sf::VideoMode(640, 480), "Problemik");
 
     sf::Image image;
sf::Sprite sprite;
     
if (!image.LoadFromFile("problem.png"))
         return 1;
     
sprite.SetImage(image);
sprite.Resize(1536, 32);
//sprite.SetCenter(sprite.GetSize().x / 2, sprite.GetSize().y / 2); // Here is the problem
sprite.SetPosition(450 - sprite.GetCenter().x, 300 - sprite.GetCenter().y);
 
     while (window->IsOpened())
     {
         sf::Event Event;
         
while (window->GetEvent(Event))
         {
             if (Event.Type == sf::Event::Closed)
                 window->Close();
         }
 
         window->Clear();
         window->Draw(sprite);
         window->Display();
     }
 
     return 0;
 }

I attached whatever as problem.png


[attachment deleted by admin]

Pages: [1]