A lot of moving 1 pixel sized objects (bullets). Best way to do it?

Started by TMuh, Sun 20/10/2013 15:17:38

Previous topic - Next topic

TMuh

Hey,

im doing game with a lot of 1 pixel sized bullets moving around screen at the same time (from 100 to 1000, depends what is possible). So is there ways to do it? I was thinking of drawingsurface but would it be too slow?

Crimson Wizard

I think drawing surface would be fastest of what AGS script allows, because using objects, characters or gui controls for such purpose will add a lot of unnecessary calculations (and using lots of memory).

On other hand, dealing with that amount of things from script can be slow anyway. You may, perhaps, consider using/making a particles plugin.

TMuh

DrawingSurface seems to run surprisingly smoothly even with 1000 moving pixels.

I dont know if using screen-sized dynamicsprite for drawingsurface would make it even faster. Now it draws every pixel straight to background seperately. I tried to test it but for some reason when I drew all bullets to dynamicsprite first and then drew the sprite to background, it didnt update screen properly. Screen updated only after I moved character or mouse so the trails of mouse and character were updated.

Anyways, this worked fine:
Code: AGS
function room_RepExec()
{
Count++;
if (Count > 3) {
DrawingSurface *back = Room.GetDrawingSurfaceForBackground(1);  //Background(1) is where the original background is saved.
DrawingSurface *bullet = Room.GetDrawingSurfaceForBackground(0); //Background(0) is where bullets and other stuff is drawn.

int cnt = 0;
while (cnt < MAXBULLET) {
bullet.DrawingColor = back.GetPixel(FloatToInt(blt.x[cnt]), FloatToInt(blt.y[cnt]));
bullet.DrawPixel(FloatToInt(blt.x[cnt]), FloatToInt(blt.y[cnt]));
MoveBlt(cnt); //Moves bullet to its direction.
bullet.DrawingColor = 16;
bullet.DrawPixel(FloatToInt(blt.x[cnt]), FloatToInt(blt.y[cnt]));


cnt++;
}
back.Release();
bullet.Release();
Count = 0;
}

}



And this didnt work:
Code: AGS
DynamicSprite* Background = DynamicSprite.CreateFromBackground(1); //Gets original clean background.
DrawingSurface *Backsurf = Background.GetDrawingSurface();
int cnt = 0;
while (cnt < MAXBULLET) {
MoveBlt(cnt);
Backsurf.DrawingColor = 16;
Backsurf.DrawPixel(FloatToInt(blt.x[cnt]), FloatToInt(blt.y[cnt])); //Draws bullets to dynamicsprite.
cnt++;
}
DrawingSurface *RealBack = Room.GetDrawingSurfaceForBackground();
RealBack.DrawImage(0, 0, Background.Graphic); //Draws dynamicsprite to background.
RealBack.Release(); Backsurf.Release(); Background.Delete();

TMuh

Quote from: Crimson Wizard on Sun 20/10/2013 15:32:08
You may, perhaps, consider using/making a particles plugin.

Would the plugin make it faster somehow or is it just for saving coding time?

Crimson Wizard

Quote from: TMuh on Sun 20/10/2013 22:13:20
Would the plugin make it faster somehow or is it just for saving coding time?
No, that definitely won't save code time (on other hand that may not be too long to create one, if you can program C++).
Regarding speed: since plugins will execute a real machine code, not script, it will be generally faster in all cases, but the question usually is: does it worth it?
If you are satisifed with the results you've got in script, you may as well stick to that.

TMuh

Ok, thank you. I havent studied plugins and my c++ skills are "some basics only", so i think this is good enought for me now.

SMF spam blocked by CleanTalk