1
Graphics / Setting a view's position?
« on: January 17, 2012, 05:26:04 am »
Hey thanks, I'll try that!
EDIT: Tested, it works just as intended.
EDIT: Tested, it works just as intended.
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.
PS: i'm not using SFML, i will start use it tomorrow maybe.
Btw, can you use a global view? Or give a reference of that view to your function?
App.GetView().Move(3,4);
const sf::View& view = App.GetView();
view.Move(3,4);
if (!currentTexture.LoadFromFile("blah.jpg"))
if(*file==_T('\0'))
{
errno=EINVAL;
return NULL;
}
BOOST_ASSERT(size_type(idx - index_bases[0]) < extents[0]);
what is your problem?Code: [Select]
typedef sf::Vector2<double> Vector2d;
Vector2d vec(1, 5);
//and you are done.
//if you want to change the coords just do
vec.x = 42;
vec.y = 1337;
void drawTiles(sf::RenderWindow &app)
{
for(int x = 0; x < tileMapWidth-1; x++)
{
for (int y = 0; y < tileMapHeight-1; y++)
{
int textureIndex = tileMap[y][x];
sf::Texture texture = tileTextures[textureIndex];
sf::Sprite sprite;
sprite.Scale(.1875, .1875);
sprite.SetTexture(texture);
sprite.SetPosition(x*tileWidth,y*tileHeight);
app.Draw(sprite);
}
}
app.Display();
}
I guess you're you using separate images for each tile... Am I right?
You can use one big image with all tiles on it, but if you are following a tutorial that will give you some trouble.
Why are you scaling the sprites before drawing?
sf::texture Texture = tileTextures[0];
void drawTiles(sf::RenderWindow &app)
{
for(int x = 0; x < tileMapWidth; x++)
{
for (int y = 0; y < tileMapHeight; y++)
{
int* textureIndex = tileMap[y, x];
sf::Texture texture = tileTextures[0]; //[*textureIndex+1];
sf::Sprite sprite;
sprite.Scale(.1875, .1875); // 48/256 (tileWidth/size of original image)
sprite.SetTexture(texture);
sprite.SetPosition(x*tileWidth,y*tileHeight);
app.Draw(sprite);
app.Display();
}
}
}
Wait, I guess that means I should create everything with their origin at 0,0 then set their position to something else. Does it have to be done like this?
For me the shape appears at (300, 300), which i do believe is correct because the shape itself starts at (200, 200) and is moved by (100, 100) afterwards.
A minimal code would be better.Code: [Select]#include <SFML/Graphics.hpp>
#include <iostream>
int main()
{
sf::Shape shape;
shape.AddPoint(200, 200, sf::Color::White, sf::Color::White);
shape.AddPoint(200, 300, sf::Color::White, sf::Color::White);
shape.AddPoint(300, 300, sf::Color::White, sf::Color::White);
shape.AddPoint(300, 200, sf::Color::White, sf::Color::White);
shape.SetPosition(100, 100);
sf::Vector2f position = shape.GetPosition();
std::cout << position.x << " " << position.y << std::endl;
return 0;
}
This code should display "100 100". And I'm sure it does
#include <SFML/Graphics.hpp>
#include <iostream>
int main()
{
sf::RenderWindow App(sf::VideoMode(800, 600, 32), "Position Test");
sf::Shape shape;
shape.AddPoint(200, 200, sf::Color::White, sf::Color::White);
shape.AddPoint(200, 300, sf::Color::White, sf::Color::White);
shape.AddPoint(300, 300, sf::Color::White, sf::Color::White);
shape.AddPoint(300, 200, sf::Color::White, sf::Color::White);
shape.SetPosition(100, 100);
sf::Vector2f position = shape.GetPosition();
std::cout << position.x << " " << position.y << std::endl;
while (App.IsOpened())
{
sf::Event Event;
while(App.PollEvent(Event))
{
if (Event.Type == sf::Event::Closed)
App.Close();
}
App.Clear();
App.Draw(shape);
App.Display();
}
return 0;
}