SFML lies?!?!

I'm trying to move my sf::Sprite from the center, and not the top left corner, so I use the SetCenter() function to, well... Set the center. However, it does not seem to be working. Could it possibly be the move function that I'm using? Also, when I use GetCenter() it tells me that I AM at 0.0, 0.0... It makes no sense!

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
#include <stdlib.h>
#include <iostream>
#include <SFML/System.hpp>
#include <SFML/Window.hpp>
#include <SFML/Graphics.hpp>

sf::RenderWindow Window(sf::VideoMode(800, 600, 32), "MySFML");
sf::Image Image;
sf::Sprite Wawa;

void Load();
void Update();
void Display();
int SQCollide(sf::Sprite A, sf::Sprite B);

int main()
{
	Load();
	while (Window.IsOpened())
	{
		Update();
		Window.Clear();
		Display();
		Window.Display();
	}
	return 0;
}

void Load()
{
	if (!Image.LoadFromFile("bird.png"))
	{
		std::cout<<"NOOOOOOOOOOOOOOOOOOOO!!!\n";
	}
	Wawa.SetImage(Image);
}

void Update()
{
	//Extra Keys
	sf::Event Event;
	while (Window.GetEvent(Event))
	{
		if (Event.Type == sf::Event::Closed)
		{
			Window.Close();
		}
		
		if (Event.Key.Code == sf::Key::F2)
		{
			sf::Image Screen = Window.Capture();
			Screen.SaveToFile("Screenshot.bmp");
		}
		
		if (Event.Key.Code == sf::Key::Escape)
		{
			Window.Close();
		}
	}
	
	//The Important Keys - Real Time Stuffs
	const sf::Input& Input = Window.GetInput();
	float Meow = Window.GetFrameTime();
		
	if (Input.IsKeyDown(sf::Key::W))
	{
		Wawa.Move(0, -400 * Meow);
	}
	if (Input.IsKeyDown(sf::Key::S))
	{
		Wawa.Move(0, 400 * Meow);
	}
	if (Input.IsKeyDown(sf::Key::A))
	{
		Wawa.Move(-400 * Meow, 0);
	}
	if (Input.IsKeyDown(sf::Key::D))
	{
		Wawa.Move(400 * Meow, 0);
	}
	Wawa.SetCenter(0.0, 0.0);
	std::cout<<Wawa.GetCenter().x<<std::endl<<Wawa.GetCenter().y<<std::endl<<std::endl;
	return;
}

void Display()
{
	Window.Draw(Wawa);
	return;
}

int SQCollide(sf::Sprite A, sf::Sprite B)
{
	double AX;
	double AY;
	double A1;
	double A2;
	
	
	
	double BX;
	double BY;
	double B1;
	double B2;
}


Thank you for any help you can give!

- Kyle

EDIT: Please ignore the unfinished collision function; this problem is more predominate than that right now.
Last edited on
You are setting the center of the sprite to 0 0 with SetCenter so of course GetCenter returns 0 0. What did you expect?
Oh, ya... The Sprite its self does not stay at 0.0, 0.0... It moves around (when I use WSAD), but always says that it's at 0.0.

- Kyle
Last edited on
SetCenter sets the origin of the sprite. So if you have a sprite of size 10x10 and you call SetCenter(5, 5), and then you move the sprite to position 100 200 that would make the middle of the sprite be located at 100 200 (The top left corner would be located at 95 195). To get the position of the sprite use GetPosition().
Okay, but it moves independently every frame. So if I don't press anything should it not be at 0.0, 0.0?

- Kyle
What should be at 0 0? The sprite position? I think the sprite should be located at 0 0 before you have pressed any buttons, assuming the default Sprite constructor sets the position to 0 0.
Yes, the sprite should be at 0, 0, AND it should not be able to be affected when I use WSAD because I reset the position to 0, 0 every time.

- Kyle
SetCenter does not affect the position of the sprite. Use SetPosition to do that.
Maybe this will explain SetCenter http://en.sfml-dev.org/forums/index.php?topic=4840.0
Ah yes. Thank you! Now it all works.

- Kyle
Topic archived. No new replies allowed.