1 registered members (AndrewAMD),
1,089
guests, and 2
spiders. |
Key:
Admin,
Global Mod,
Mod
|
|
|
Re: removing large sprite entities all at once
[Re: ncc1701d]
#309941
02/12/10 06:41
02/12/10 06:41
|
Joined: Mar 2009
Posts: 112 Germany
KDuke
Member
|
Member
Joined: Mar 2009
Posts: 112
Germany
|
Well random and ent_create is the way to go. You simply use a loop with which you create the sprites. If you use an array to store these created entities you can easily remove them with a loop of the same kind, using the array which stores the pointers to the sprite entities and removing them with ent_remove. If you would like a dynamic number of these sprites you can use sys_malloc for dynamically creating an array with a given number of space to handle the sprites.
Using A7 Free Click and join the 3dgs irc community! Room: #3dgs
|
|
|
Re: removing large sprite entities all at once
[Re: KDuke]
#309950
02/12/10 09:07
02/12/10 09:07
|
Joined: Feb 2008
Posts: 3,232 Australia
EvilSOB
Expert
|
Expert
Joined: Feb 2008
Posts: 3,232
Australia
|
Another way would be to loop generating all the sprites. This loop also gives each entity a simple action that watches one particular global variable. If this global variable equals a set number, the entities then self-destruct. EG
var trees_on = 1;
action tree_alive()
{ while(trees_on==1)
{ wait(1); }
ent_remove(me);
}
function create_trees()
{ ...
for(i=0; i<150; i++)
{
ent_create("tree.tga", vector(random(2000)-1000,random(2000)-1000,0), tree_alive);
}
...
}
// then just set "trees_on == 0" for one frame and all the trees will remove themselves.
"There is no fate but what WE make." - CEO Cyberdyne Systems Corp. A8.30.5 Commercial
|
|
|
Re: removing large sprite entities all at once
[Re: Widi]
#309985
02/12/10 13:59
02/12/10 13:59
|
Joined: Feb 2008
Posts: 3,232 Australia
EvilSOB
Expert
|
Expert
Joined: Feb 2008
Posts: 3,232
Australia
|
Widi does have a point. Mine will be a little bit fps-hungry if youve got a hell of a lot of trees. But seeing as the tree-action is so small theres not going to be that fps-intensive.
BUT, if you are just using this process for a "remove trees at end of level" type system, then mine is seriously in-efficient and KDukes is far more appropriate.
"There is no fate but what WE make." - CEO Cyberdyne Systems Corp. A8.30.5 Commercial
|
|
|
Re: removing large sprite entities all at once
[Re: Joey]
#310012
02/12/10 17:08
02/12/10 17:08
|
Joined: Jul 2008
Posts: 1,178 England
MrGuest
Serious User
|
Serious User
Joined: Jul 2008
Posts: 1,178
England
|
I'd just store all the trees handles in an array,
#include <acknex.h>
#include <default.c>
#define trees_max 50
var hnd_trees[3][trees_max];
void trees_remove(int group){
ENTITY* ent;
int i;
for(i = 0; i < trees_max; i++){
you = ptr_for_handle(hnd_trees[group][i]);
if(you){
ent_remove(you);
}else{
break;
}
}
}
void trees_create(VECTOR* offset, int group, int count){
if(count > trees_max){
printf("TOO MANY TREES, Increase #define on line 6");
return;
}
int i;
VECTOR pos;
pos.z = 0;
int i;
for(i = 0; i <= count; i++){
pos.x = offset.x + (random(500)-250); //-250 to 249.99
pos.y = offset.y + (random(500)-250);
hnd_trees[group][i] = handle(ent_create("tree.mdl", pos, NULL));
}
}
void main(){
wait(1);
level_load(NULL);
vec_set(camera.x, vector(0, 0, 5000));
camera.tilt = -90;
trees_create(vector(0, 0, 0), 0, 10);
trees_create(vector(-1000, 1000, 0), 1, 10);
trees_create(vector(1000, 1000, 0), 2, 10);
random_seed(0);
int i;
while(1){
i = random(3);
trees_remove(i);
trees_create(vector(random(2000)-1000, random(2000)-1000, 0), i, integer(random(25)));
wait(-2);
}
}
make sure your tree model exists doesn't stop trees spawning in each other doesn't choose more than 1 model hope this helps
|
|
|
|