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

Author Topic: Dealing with a large number of sprites?  (Read 2846 times)

0 Members and 1 Guest are viewing this topic.

zeromeus

  • Newbie
  • *
  • Posts: 3
    • View Profile
Dealing with a large number of sprites?
« on: July 05, 2011, 07:14:31 pm »
Hey all,

I'm trying to create a simple program that creates a 'fairy trail' of green pixels on a black background generated by the mouse. From another topic I learnt that I can't turn individual pixels on or off and so I'd instead need to use sprites for each pixel. However, when drawing so many sprites every time I call Display() the screen (understandably) flashes because it's drawing so many sprites at one go.

My current approach is creating a 2D vector the same size as the window with each cell storing the sprite to be drawn. I know this is a far from an efficient way of going about it, but it would be convenient for future purposes. So my question is, is there any cleaner way to do this while keeping some kind of map with all pixels?

If I'm guessing a good way to do it is to just have some kind of hashed container with all the cells the mouse has visited within some time frame and draw those on and kill cells that haven't been visited in a while.

Thanks so much!

Haikarainen

  • Guest
Re: Dealing with a large number of sprites?
« Reply #1 on: July 05, 2011, 07:21:38 pm »
Quote from: "zeromeus"
Hey all,

I'm trying to create a simple program that creates a 'fairy trail' of green pixels on a black background generated by the mouse. From another topic I learnt that I can't turn individual pixels on or off and so I'd instead need to use sprites for each pixel. However, when drawing so many sprites every time I call Display() the screen (understandably) flashes because it's drawing so many sprites at one go.

My current approach is creating a 2D vector the same size as the window with each cell storing the sprite to be drawn. I know this is a far from an efficient way of going about it, but it would be convenient for future purposes. So my question is, is there any cleaner way to do this while keeping some kind of map with all pixels?

If I'm guessing a good way to do it is to just have some kind of hashed container with all the cells the mouse has visited within some time frame and draw those on and kill cells that haven't been visited in a while.

Thanks so much!


Are you after some sort of particle effect? or is the fairy trail to trace mousemovement?

If particle: The Thor library has a nice particle system you could use, or you could just do class cGreenFairyThingies{int/float posx, int/float posy} and push those(only active pixels) into a vector. Why do you need a map over the whole window? If you really wanna map the whole screen in a vector, make it have a bool isActive; instead of a sprite, and on the drawing sequence create a new temporary sf::Sprite to set your parameters. That saves memory but wastes a little cpu/gpupower.

If you wanna trace mousemovement, use an intersected vector of positions !

zeromeus

  • Newbie
  • *
  • Posts: 3
    • View Profile
Dealing with a large number of sprites?
« Reply #2 on: July 05, 2011, 11:35:20 pm »
The trail is to trace mouse movement. I'm sorry but I'm kind of a noob. What exactly does it mean to use an intersected vector of positions?

Thanks!

Haikarainen

  • Guest
Dealing with a large number of sprites?
« Reply #3 on: July 06, 2011, 03:37:23 pm »
Quote from: "zeromeus"
The trail is to trace mouse movement. I'm sorry but I'm kind of a noob. What exactly does it mean to use an intersected vector of positions?

Thanks!


What are you going to use it for?

One way to use it(wich is not that precise but it works)

Do this; Each frame, check if mouse has moved more than ~8-16 pixels compared to the last recorded mouse, if it's true, then push the current mouseposition into a vector like std::vector<sf::Vector2f>.

On drawing; Iterate thru the std::vector, and draw lines between the points (from 0 to 1, from 1 to 2, from 2 to 3 etc).

 

anything