Best Practice: Destroying / hiding a lot of actors at once...
Hey there guys...
I am working on simple game right now and I have run into an issue that I am trying to sort out. The game basically has a lot of random actors being spawned and filling up a screen (think something like tetris) when a variable gets set (explode = 1) the actors will be removed from the screen or destroyed. It works great until I have 20+ actors on the screen. Then I get a big lag spike.
I know that having a lot of actors on the screen is not ideal for performance sake. I wasn't sure how to achieve what I'm trying to do the most efficient way. I've tried several things like just destroying when the variable is flipped to moving them off the screen. Moving them off the screen increases the performance but still is not ideal..
Just wanted to throw it out there in case someone else has a better idea...
Thanks in advance!
Brad
I am working on simple game right now and I have run into an issue that I am trying to sort out. The game basically has a lot of random actors being spawned and filling up a screen (think something like tetris) when a variable gets set (explode = 1) the actors will be removed from the screen or destroyed. It works great until I have 20+ actors on the screen. Then I get a big lag spike.
I know that having a lot of actors on the screen is not ideal for performance sake. I wasn't sure how to achieve what I'm trying to do the most efficient way. I've tried several things like just destroying when the variable is flipped to moving them off the screen. Moving them off the screen increases the performance but still is not ideal..
Just wanted to throw it out there in case someone else has a better idea...
Thanks in advance!
Brad
Comments
I use a gameAttribute index type to track the flow of game (user's actions/actor events/other attributes … change this)… flowIndex
especially good when trying to control the state/behaviors of a large number of actorInstances
EX: on the actors you want to destroy at the same time
Rule: when
Attribute: game.flowIndex = 5
--Destroy
though the boolean works well … it only allows the 2 states/conditions …
I like to use a flow attribute so all the elements in the game know what they should be doing and when!
see how important GS thinks flow is in game development: GameSalad Weekend Intensive
I no longer bother with flowCharts as charts/diagrams … but, do make lists for gameFlow sceneFlow and IndexAttributes to track
@};- MH
New to GameSalad? (FAQs) | Tutorials | Templates | Greenleaf Games | Educator & Certified GameSalad User
Yes, just use a change attribute like you stated, @tatiang.
If I understand the question correctly, you would put a change attribute at the beginning of the actor (at the top) so when it spawns, it increases the number by one.
Then, like @MotherHoose said, create a rule that when the number equals 5, for example, it would destroy then.
That is, if I understand the question.
My GameSalad Academy Courses! ◦ Check out my quality templates! ◦ Add me on Skype: braydon_sfx
EX: game.flowIndex
flowIndex = O
on all actors:
Rule: when
Attribute: game.flowIndex = 0
-changeAttributes to the original X,Y
(this is good for reset button … when touch is pressed changeAttribute: game.flowIndex To: 0 … and all the actors go at once to the start
Rule: when
Attribute: self.Time ≥ 0.001
--changeAttribute: flowIndex To: 1
all actors including background:
Rule: when
Attribute: game.flowIndex = 1
-changeAttribute: self.Image To: correctImageName
background image:
Rule: when
Attribute: self.Time ≥ 0.1
-changeAttribute: flowIndex To: 2
all activeActors:
Rule: when
Attribute: game.flowIndex = 2
-do the things you're supposed to do
===
of course most of my Prototypes are generic … and used for many different elements
and most all the prototypes have added attributes: origX, origY, myImage; my# … etc.
since none of the rules involve separate timers and since they only fire once when the condition is first valid … seems to make things smooth and fast
(well some are "≥" rather than just "=" conditions)
===
I know I am big on control … but do believe everything in the game should know where it is at and when to do something as a group
@};- MH
New to GameSalad? (FAQs) | Tutorials | Templates | Greenleaf Games | Educator & Certified GameSalad User
scene loading does not have to load the images … along with the actors and behaviors and rules etc … before its starts running
actual load for game should be shorter … but haven't verified it
(before we had Preload Art … I used to use an off-screen actor to load the images for the next scene … actually named preLoader! … I figured I'd keep the computer busy setting up the next scene while the player was wasting time in the current scene!)
also note: my scenes often have a flow attribute and some of my actors do (for image changes at … ex: bigger ship; better weapon; more health)
@};- MH
PS did you catch the slides?: http://www.slideshare.net/1ninjakitty/gamesalad-weekend-intensive
hopefully we get the video of the weekend, soon.
Brad
New to GameSalad? (FAQs) | Tutorials | Templates | Greenleaf Games | Educator & Certified GameSalad User