okay .. iknow that this question has been asked many times and i have even checked out the topics but i just cant seem to get my head around this problem #include <SFML\graphics.hpp>
#include "stdafx.h"
int main()
{
sf::Texture img;
if(!img.loadFromFile("bg.png"))
{std::cout<<"load error";}
sf::Sprite bg(img,sf::Rect<int>(10,12,30,23));
sf::RenderWindow app(sf::VideoMode(640,480),"test");
while(app.isOpen())
{ sf::Event x;
while(app.pollEvent(x))
{if(x.type==sf::Event::Closed){app.close();}}
app.clear(sf::Color(0,0,0,0));
app.draw(bg);
app.display();
}
return 0;
}
my texture could not have gone out of scope as there is only a main function and even the image is getting loaded as it does not show any error
plzz help
Allocate textures after the window is open :)
Yeah there can be some issues with allocating the texture before the window creation, but I don't think I've ever had the problem with VS...
Anyways, you should really use more whitespaces. Your code is nearly unreadable to a normal programmer, e.g. something like this:
#include <SFML/graphics.hpp>
int main()
{
sf::RenderWindow app(sf::VideoMode(640,480), "test");
sf::Texture img;
if(!img.loadFromFile("bg.png"))
{
std::cout << "load error";
}
sf::Sprite bg(img, true);
while(app.isOpen())
{
sf::Event x;
while(app.pollEvent(x))
{
if(x.type==sf::Event::Closed)
{
app.close();
}
}
app.clear(sf::Color(0, 0, 0, 0));
app.draw(bg);
app.display();
}
}
Note: I removed the sf::Rect<int> to make sure you're not specifying a wrong position there.
Also you should always start with an empty project, thus you wouldn't need stdafx. ;)
controlled by the mouse somewhat like this
if(event.type==sf::event::mousemoved)
{puck.setpositon(mousex,mousey})
You also might want to look into sf::Mouse::getPosition(window);
is there some way to get the velocity of the puck ??
Yes with knowledge in physics and math. ;)
(average) velocity = passed distance/passed time