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

Author Topic: Large double array of sprite  (Read 1370 times)

0 Members and 1 Guest are viewing this topic.

TehKyle

  • Newbie
  • *
  • Posts: 8
    • View Profile
Large double array of sprite
« on: May 22, 2011, 12:09:13 pm »
I get segment fault with this code
 sf::Sprite TileMapSprite[600][400];
and then load the image and display only the appropriate sprite based on camera location.

Is there better way to store multiple tile with position stored?

Nexus

  • SFML Team
  • Hero Member
  • *****
  • Posts: 6287
  • Thor Developer
    • View Profile
    • Bromeon
Large double array of sprite
« Reply #1 on: May 22, 2011, 12:31:13 pm »
Separate between logical tiles (that store properties like the tile type) and graphical sprites (which are only used to render the tiles). Then, you don't need a sprite for each tile, and you can also create sprites on the fly instead of storing them all the time.

By the way, 400 * 600 * sizeof(sf::Sprite) is about 45MB. I don't think you need that much memory only for the sprites.
Zloxx II: action platformer
Thor Library: particle systems, animations, dot products, ...
SFML Game Development:

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32498
    • View Profile
    • SFML's website
    • Email
Large double array of sprite
« Reply #2 on: May 22, 2011, 08:15:56 pm »
45 MB is too much for the stack, which has a very limited size. So if your array is declared on the stack, declare it on the heap (using the new keyword -- or better, an array class like std::vector) and it should work.
Laurent Gomila - SFML developer