GameSalad

How do I set which layer is chosen when they overlap?

marleemarlee Posts: 5Member

Hi!
Lets say I want to color a cartoon cat with stripes.
For example, I have a background/outline with black/transparent that is set to do nothing.
I then have several white/transparent images that I've placed where they should be on the background. Theese have rules that if touched they change to the colore I've chosen. (i'm thinking of using around ten different colors or so)

But how can I make it know that if I press the stripes of a cat to color only them and not the whole body?
Thankful for any help!
/Marléne

Comments

  • tatiangtatiang Posts: 10,917Member, Sous Chef, PRO, Senior Sous-Chef

    This can be tricky because all actors register touch regardless of what layers they are on. You can try something like this:

    Stripe actor:
    When touch is pressed
         Change attribute game.stripeTouched to true
         [change stripe color]
    Otherwise
         Change attribute game.stripeTouched to false

    Body actor:
    When touch is pressed AND game.stripeTouched is false
         [change body color]

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

  • marleemarlee Posts: 5Member

    Nope, can't seem to get that to work...
    I've looked at this thread http://forums.gamesalad.com/discussion/10407/coloring-book-app - and this foremost:
    -The actors when touched turn on a global attribute for themselves. Background items and anything underneath have a rule that if the above actor is selected then they do not change colour. This seems to work best but would require a few rules and attributes for many overlapping items.

    But I can't figure out what rule I can apply to the background items about the above actor...

  • SocksSocks London, UK.Posts: 12,711Member, PRO

    @tatiang said:
    This can be tricky because all actors register touch regardless of what layers they are on.

    I'm not sure if this is helpful in this specific case, but you can use the fact that GS scans actors from bottom to top (layers) to sort the order.

    The logic is . . . . we have overlapping actors:

    Actor A
    Actor B
    Actor C
    Actor D
    Actor E

    When you click on this stack of layers (they each have a self.ID) they are told to change a game.attribute to their self.ID . . . . this will be done in reverse order from bottom to top (E,D,C,B,A).

    That means the game.attribute will always end up with the self.ID of the topmost actor.

    After that it's a simple case of adding a rule, if self.ID = game.attribute, to trigger whatever you need triggering.

    Attached is an example (click on an actor and drag up and down to colour).

  • marleemarlee Posts: 5Member
    edited July 14

    Hi!
    Thanks @Socks but that made me seriously more confused... :P
    I've created a short version example of how my game looks, if anyone could help me understand what I need to code in it to make the nose and stripes (in this example) color only themselves and not the whole cat. :P

    I put it in my dropbox.
    https://www.dropbox.com/s/7oasvjbemcsyo92/example.rar?dl=0

  • marleemarlee Posts: 5Member

    Aaaand I posten in the mac-section when I have a PC. :P

  • tatiangtatiang Posts: 10,917Member, Sous Chef, PRO, Senior Sous-Chef

    Actually, I really like that idea, @Socks. :)

    I'll move this to the PC subforum.

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

  • marleemarlee Posts: 5Member

    Ok, I tried it and managed to get it to work. Then something else didn't work with my paintcolors, fixed that and now teh effing thing won't work again... I'm starting to really regret this...

  • tatiangtatiang Posts: 10,917Member, Sous Chef, PRO, Senior Sous-Chef

    If you're not already saving incremental versions, I highly recommend it. Basically, whenever I make a minor change to my project file, I save it with a new name. So I end up with Red Bouncing Ball Spikes 1, Red Bouncing Ball Spikes 2, Red Bouncing Ball Spikes 3, etc. I end up with hundreds of files before I finally publish the app. That way if something worked at one moment and then broke later, I can go back and look at how it worked in an earlier file.

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

Sign In or Register to comment.