Jump to content

How to override collide behaviour with tiles?


Elgan
 Share

Recommended Posts

            if (this.game.physics.arcade.collide(this, this.game.level.blockedLayer, null, this.checkHitsHardblock))            {                        blocked = true; //checked, NEVER CALLS            }        checkHitsHardblock(ob1: any, obj2: any) {            return false;        }
 
The character still hits into hard blocks?
 
but when i delete the above collide check. he does not. (no checks)
So he is still colliding, even though collide is always returning false.

 

Link to comment
Share on other sites

You can set callbacks for when the player hits a specific type of tile, for example...

// Make the layerrockLayer=map.createLayer('Rocks');// Set collision for only these tile indexesmap.setCollision([0,3,6,7,8,9,10],true,'Rocks');// Set a custom callback for tile of index 3    map.setTileIndexCallback(3, hitDifferentBlock, player, 'Rocks');

Then in custom function hitDifferentBlock, you do your custom hit action, then return false or true to the general hit check.

Link to comment
Share on other sites

thank you, i am looking into it.

 

However, I really dont get the whole setCollision and setTileIndexCallback.

I have maybe 1200 tiles. How am i supposed to know all of the tile indexes!

i'm going to try looping through a blocked layer and adding callbacks to each tile returned. I assume it will return it's index too.

 

there should be a setCollisionAll() and a setCallBackAll()

That way you can build a map from layers, and all the tiles on layer "rocks" act in that way etc.

 

 

However collide still is not working how its supposed to; Im wondering if this is related to this bug?

http://www.html5gamedevs.com/topic/6864-sprite-vs-tilemaplayer-separates-even-when-processcallback-returns-false-even-when-using-overlap-instead-of-collide/

Link to comment
Share on other sites

You have 1200 types of tiles or 1200 total tiles?

setTileIndexCallback applies the callback to every tile that uses the same indexed tile graphic.

So if you have a tile that is, a mario question mark block, and you apply the setTileIndexCallback to that index from the tileset, every tile that uses that graphic with fire the callback upon collision/overlap.

Without seeing it in action I can only guess at what the issue is.

Link to comment
Share on other sites

 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...