Hi,
I am making 2d voxel game and i have the following problem.
Instead of view i just draw the voxels around camera.
But the problem is with the voxels which are not fully visible.
Since sfml cannot draw below 0 and its more effective to just draw the visible part i choosed to use setTextureRect function. So here is my code:
void Draw::drawEarth(sf::Vector2i pos,char id){
sf::Sprite s;
s.setTexture(*((*data).getTexEarth(id)),true);
if(pos.x<0){ //i have to cut voxel
//for example if pos.x=-8 then i have to draw 8 to 20 --> 12 pixels
//my voxels scale is 20*20 pixels
s.setTextureRect(sf::IntRect(-pos.x,0,20,20));
s.setPosition(0,pos.y);
(*window).draw(s);
}
else{ //the whole voxel will be visible
s.setTextureRect(sf::IntRect(0,0,20,20));
s.setPosition(pos.x,pos.y);
}
(*window).draw(s);
}
But the output is this:
http://postimg.org/image/k5fzdw8vh/(the right, bottom part of picture is my voxel texture)
So u can see there is full sized sprite with texture which is transformed, but not cutted as it have to be.
The yellow part of texture should not be printed.
So my question is what am i doing wrong.
I would appreciate any help