Best Practice: Destroying / hiding a lot of actors at once...

blondonblondon Member Posts: 31
edited February 2012 in Working with GS (Mac)
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

Comments

  • MotherHooseMotherHoose Member Posts: 2,456
    rather than boolean for control of the state of a large number of actors …

    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
  • tatiangtatiang Member, Sous Chef, PRO, Senior Sous-Chef Posts: 11,949
    @MotherHoose I'm really curious about how you use game.flowIndex. What would be an example of something that would increase that value? Do you just have a ChangeAttribute game.flowIndex to game.flowIndex+1 on every interactive/moveable actor? Or is it more complex than that? And your example to destroy the actors when game.flowIndex=5... is the idea that when you reach a certain limit of behaviors to then affect the game in some way (in this case, destroying actors)?

    New to GameSalad? (FAQs)   |   Tutorials   |   Templates   |   Greenleaf Games   |   Educator & Certified GameSalad User

  • Braydon_SFXBraydon_SFX Member, Sous Chef, Bowlboy Sidekick Posts: 9,273
    Hi,

    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.
  • MotherHooseMotherHoose Member Posts: 2,456
    I usually have my background image in each scene control the flow … but sometimes use an off-screen controlActor … or an activeActor will change the flow

    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
  • tatiangtatiang Member, Sous Chef, PRO, Senior Sous-Chef Posts: 11,949
    I understand now. I really appreciate you taking the time to spell it out. I'm starting to think about good ways to reset a game I'm working on, so this is definitely food for thought. One question: why do you set image names at run time rather than when configuring the game in the editor? Is there a performance gain?

    New to GameSalad? (FAQs)   |   Tutorials   |   Templates   |   Greenleaf Games   |   Educator & Certified GameSalad User

  • MotherHooseMotherHoose Member Posts: 2,456
    I set images at runtime so that load times between scenes are shorter (uncheck Preload Art)
    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.
  • blondonblondon Member Posts: 31
    Thanks for the insight.. I am going to play around with this a bit.
    Brad
  • tatiangtatiang Member, Sous Chef, PRO, Senior Sous-Chef Posts: 11,949
    @MotherHoose I did check out the slides... very cool.

    New to GameSalad? (FAQs)   |   Tutorials   |   Templates   |   Greenleaf Games   |   Educator & Certified GameSalad User

Sign In or Register to comment.