When moving over area, change color & calculating percentage of area

MarcoColMarcoCol Member, PRO Posts: 279
edited March 2013 in Working with GS (Mac)
Hi,

In my game I want that the player moves over the field, and where he just move,the color of the gound should be change some brighter. Also the area should be calculated in percentage, how muchmhemstillmhas done.
How can I do that?

It is a bit like a game where you must mow the gras and win only if you pass over xx percent.

Comments

  • MarcoColMarcoCol Member, PRO Posts: 279
    Doesn't have anyone an idea? Is that not possible with GS?
  • tatiangtatiang Member, Sous Chef, PRO, Senior Sous-Chef Posts: 11,949
    You can check for when the mowing actor collides with grass and change the color or image to something else. As for calculating the area, you would need each grass actor to have a self.mowed attribute (boolean) and when it gets "mowed" you change it to true and add one to game.mowedCount (integer). Calculate your percentage from game.mowedCount/game.numberOfGrassActors*100.

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

  • MarcoColMarcoCol Member, PRO Posts: 279
    Hi
    Ok. So i must have thousands of different gras actors?
  • MarcoColMarcoCol Member, PRO Posts: 279
    I try and it didn't work to make one actor and put it a few times on the scene. So if I am right, I must all different actors, which means I must use a few hundret different?!
  • SocksSocks London, UK.Member Posts: 12,822
    I try and it didn't work to make one actor and put it a few times on the scene. So if I am right, I must all different actors, which means I must use a few hundret different?!
    No, just use lots of instances of the same single actor.
  • MarcoColMarcoCol Member, PRO Posts: 279
    But when I there use for example,that if it colide with actor, the color should change, then the color of all (the same) actors change at the same time, just when the actor colide with the first actor...
  • SocksSocks London, UK.Member Posts: 12,822
    But when I there use for example,that if it colide with actor, the color should change, then the color of all (the same) actors change at the same time, just when the actor colide with the first actor...
    I guess you have your rules set up incorrectly.

  • MarcoColMarcoCol Member, PRO Posts: 279
    Yes. it was my mistake. I now finish it with destroying the actors and set another "image" under all the actors. That works pretty fine.
  • SocksSocks London, UK.Member Posts: 12,822
    edited March 2013
    Yes. it was my mistake. I now finish it with destroying the actors and set another "image" under all the actors. That works pretty fine.
    Rather than having two actors on top of each other, you can use just one actor and simply change its image when you need to. This will save you having dozens of extra actors in the scene.
  • jamie_cjamie_c ImagineLabs.rocks Member, PRO Posts: 5,772
    Like @Socks said above. Also if you are just changing color from say dark to light green to indicate the grass was cut you could also just change the color of the grass actor (using the change attribute, color behavior) and not the image itself.
  • MarcoColMarcoCol Member, PRO Posts: 279
    Yes. But I wand a very high detail-level. So if the area is for example 1000x600 - and each gras-quarder is about 10x10, I need a lot of. The main-area will be one single actor with a graphic. But I need at least a lot of hundret placed on the main-area.
    Must I put them each by hand? That would be a lot of work...
  • tatiangtatiang Member, Sous Chef, PRO, Senior Sous-Chef Posts: 11,949
    edited March 2013
    No, you don't have to place them by hand. And yes, it is going to be a lot of actors. But as long as those actors aren't moving and aren't animated and aren't using constrains or timers, I think you'll be okay.

    Use a spawner actor and a fast loop to spawn all of those actors onto the scene at positions determined by a table.

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

  • MarcoColMarcoCol Member, PRO Posts: 279
    Well, good to read. They will not have animations, will not move and also don't use timers or something else.
    Will the game slower using as much actors?

    So I must set each position in the table? Or can I also made something as a raster, set each same space, wich works like the duplicate-behavior?
  • tatiangtatiang Member, Sous Chef, PRO, Senior Sous-Chef Posts: 11,949
    I think you mean the Replicate behavior? If so, that won't work because replicated actors are just visual instances without rules or behaviors. You can't change them, collide with them, etc.

    You can either use a table or a mathematical formula (e.g. spawn at currentColumn*actorwidth, currentRow*actorHeight).

    I did a quick test and it's beast. Even spawning 1000 actors with a single HyperLoop (currently the fastest looping method) takes several seconds. Of course, you could create a spawning system that uses multiple spawner actors (e.g. one for each "row" on the screen"). It's going to take some complex coding, but if you're up to it, it is possible.

    I can't really speak to performance as I haven't worked with that many actors at a time but I did something similar to make a 2-dimensional mini map for a 3-dimensional maze and with about 400 actors there was no noticeable lag.

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

  • MarcoColMarcoCol Member, PRO Posts: 279
    Yes. I mean the replicate behavior (I was not sitting on my Mac as I've wrote that :) ).

    I had a look on the HyperLoop-Methode a but I didn't understand it. I will have a closer look in the next days.
    It would be good to place them not by hand. I think I will then choose the size of 5x5 for each actor and place them each 5px in the size of the area.
  • MarcoColMarcoCol Member, PRO Posts: 279
    I now had a look on the HyperLoop-Methode, but I didn't get it run and also I didn't really understand it, what to do, if I want to set the spawn actors.
    Did you have a hint for me?
  • tatiangtatiang Member, Sous Chef, PRO, Senior Sous-Chef Posts: 11,949
    The advanced Loop methods are not simple by any means. I can't offer a hint as I don't know what you're having trouble with and there are so many aspects of loops that can be confusing. I recommend starting with a simpler loop method. You can find several in the file I posted here: https://forums.gamesalad.com/discussion/comment/381275/#Comment_381275.

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

  • MarcoColMarcoCol Member, PRO Posts: 279
    Hi,

    I will have a closer look on it.

    I need "only" a loop at the start of the level, which spawned xxxx actors automatically all 5px (for example) in a field, which size is for example 800px x 250px.
  • tatiangtatiang Member, Sous Chef, PRO, Senior Sous-Chef Posts: 11,949
    You're talking about spawning 8000 actors. It's no small measure. But some of the fastest loops will let you do that relatively quickly (http://forums.gamesalad.com/discussion/55050/fast-for-loop-a-collection-from-the-community-merged-into-a-single-really-really-fast-loop#latest). The simpler loops will not... you're looking at MINUTES to loop and spawn that many actors.

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

  • RThurmanRThurman Member, Sous Chef, PRO Posts: 2,880
    Would something like this be useful?
  • tatiangtatiang Member, Sous Chef, PRO, Senior Sous-Chef Posts: 11,949
    Would something like this be useful?
    That seems a lot smarter unless each square of grass has to have its own rules for other reasons.

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

  • MarcoColMarcoCol Member, PRO Posts: 279
    A good try I think.
    But I think it would be more simple if I spawn all those actors and destroy them when collide with the player actor, right? I had a lot of tries, but I didn't get them spawned automatically. When I place them by hand for test, that what I want to do works great.
    So spawining the ground-actors is still my problem ...
  • tatiangtatiang Member, Sous Chef, PRO, Senior Sous-Chef Posts: 11,949
    But I think it would be more simple if I spawn all those actors and destroy them when collide with the player actor, right
    More simple? No, no and no. It's much, much harder. But again, if you need to have collide rules, then that's your only option. If you don't need to worry about collisions, then definitely use @RThurman's method. He's just spawning actors wherever the player "mows." You can even have those newly spawned actors have collide or other rules.

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

  • MarcoColMarcoCol Member, PRO Posts: 279
    I've made now a lot of tests with the example of RThurman. On the other side, I test a lot of with spawning (currenly by hand) a lot of actors, which then will be destroyed.
    The second methode works good and I can very easy and accurate count, how much area was finished.
    I have a very close look on the FastForLoop example, but sorry, I didn't understand it.
    Maybe my thinkings are wrong. But I am not able to get the machanism in my head to spawn fast thos actors in a set rectangle.
    Where am I wrong? Can you help me please?
Sign In or Register to comment.