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

Author Topic: Concatenate tiles to an image  (Read 1591 times)

0 Members and 1 Guest are viewing this topic.

Cloppy

  • Newbie
  • *
  • Posts: 5
    • View Profile
Concatenate tiles to an image
« on: December 06, 2010, 05:24:53 pm »
Hey Guys,
I programmed a little IsoMap for learning reasons.
However, I used one tile (64*32px), calculated the position and called App.Draw() every time, so something about 470 times per frame, which is pretty unperformant. So i wanted to add all the tiles to a sf::Image and draw it once per frame.

But I could not find a function to add a sf::Image to another.
Can anyone help me or has anyone an idea how to do that?

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32498
    • View Profile
    • SFML's website
    • Email
Concatenate tiles to an image
« Reply #1 on: December 06, 2010, 05:41:41 pm »
sf::Image::Copy.
Laurent Gomila - SFML developer

Cloppy

  • Newbie
  • *
  • Posts: 5
    • View Profile
Concatenate tiles to an image
« Reply #2 on: December 16, 2010, 04:42:43 pm »
I tried that in all ways, but doesn't work.

Code: [Select]
i_map.Copy(vTiles[0], draw_x, draw_y, sf::IntRect(0, 0, 64, 32), true);

I want to copy the vTiles[0] image to i_map multiple times, so draw_x and draw_y are the current position, where the tile belongs to the map.

But i_map doesn't change.

By the way, it would be cool, if someone could have a look at my algorithm to create the map and tell if it's okay or total bullcrap.

Code: [Select]
void CMapManager::LoadMap(sf::View* pView, float time)
{
int add_x, draw_x, draw_y;

sf::FloatRect offset = pView->GetRect();

int start_x = offset.Left / TILE_W + 1;
int start_y = offset.Top / TILE_H + 1;

int end_x = (WINDOW_W / TILE_W) + start_x + 2;
int end_y = (WINDOW_H / (TILE_H / 2)) + start_y + 4;

if(start_x < 1) {
start_x = 1;
pView->Move(SCROLLSPEED * time, 0);
}
if(start_y < 1) {
start_y = 1;
pView->Move(0, SCROLLSPEED * time);
}
if(end_x > MAP_W - 1) {
end_x = MAP_W - 1;
pView->Move(-SCROLLSPEED * time, 0);
}
if(end_y > MAP_H - 1) {
end_y = MAP_H - 1;
pView->Move(0, -SCROLLSPEED * time);
}

int posY = -(static_cast<int>(offset.Top) % 16) - 16;
for(int y = start_y; y < end_y; y++) {

int posX = -(static_cast<int>(offset.Left) % 64) - 64;

for(int x = start_x; x < end_x; x++) {
if(y % 2 == 0)
add_x = TILE_W / 2;
else
add_x = 0;

draw_x = posX + add_x + offset.Left;
draw_y = posY + offset.Top;

posX += 64;

i_map.Copy(vTiles[0], draw_x, draw_y, sf::IntRect(0, 0, 64, 32), true);
}

posY += 16;
}

s_Tile.SetImage(i_map);
}


But main problem is the Copy function. It just does not want to work. I'm doing something wrong, but have no idea where the issue hides.

 

anything