Author Topic: Best way to handle multiple "collectbles"  (Read 4584 times)

chanpod

  • Visitor
  • *
  • Posts: 6
    • View Profile
    • Email
Best way to handle multiple "collectbles"
« on: 2013-03-15, 10:58:44 AM »
So I'm going to have multiple collectables. Some will do various things other than add points. So I want to group them by type. I thought I would keep all the point based collectables in one Tile Category but I can't seem to get a proper nested if statement to work

The logic is obviously

If TouchTile == TileCategory I want
     
      if TileCategory.Index == X //Not sure how to get this part to work? I'm trying to use tilecategory touched but that doesn't seem to work
          Play sound
          Update Score
          Remove tile X
      If TileCategory.Index == Y
          play sound
          update Score
          remove tile

That's my desired approach. My working approach is to create a different Tile Category for each collectable. This doesn't seem to be efficient.

bluemonkmn

  • SGDK Author
  • Administrator
  • Fanatic
  • *****
  • Posts: 2761
    • ICQ Messenger - 2678251
    • MSN Messenger - BlueMonkMN@gmail.com
    • View Profile
    • http://sgdk2.sf.net/
    • Email
Re: Best way to handle multiple "collectbles"
« Reply #1 on: 2013-03-18, 05:13:41 AM »
There's an example of exactly what you want in the sample project, but it may not be easy to find without some guidance. (It might be worth your while just looking through the whole Player sprite rule list, though.) The example is in Sprite Definitions in the Player sprite. Look on the Rules tab of the Player sprite definition and look at the top-level rule called "Tile interactions...". It calls a function called "TouchTiles". TouchTiles is a function that collects all the information it will need about all the touching going on between a sprite and a category of tiles. It returns true if there is any touching to process. Then inside that If, you'll see the first interaction it takes care of is for grapes. TakeTile will add to a counter and change the tile number to 0 (or any specified value) if the counter is not at the max value.