Jump to content

Detect if there is no any sprites around a sprite


James L
 Share

Recommended Posts

Hi, I'm learning Phaser. Please advice me how to detect when no sprites next to a sprite. 

For example, in my maze game, imaging player moves between sprite group of walls by changing velocity. When player moves right to a T-junction, he should stop automatically. I would like to know to check if player is in a T-junction (then, only a wall sprite is on top of player sprite, no any sprites on the left, bottom, right).

Thanks.

Link to comment
Share on other sites

So if i good understand you, You must create something in the middle, them collide with circle and turn to the corner C yeah?

You can try to add some sprite in the middle, it can looks like part of map, and them create collision, after it Sprite can turn to the corner C or B.

But maybe someone will give You better idea :)

Link to comment
Share on other sites

  • 2 weeks later...

Thanks. Following this link http://phaser.io/tutorials/coding-tips-005, I've changed my game to use title map and everything seems easier. I also tried to put an invisible sprite at the T-junction corner as your idea. But other problem is that circle stops at unwanted position because it's velocity is float value of pixel.
Assume that circle moves right to corner and exactly I want to stop it at (x = 64, y = 64). My purpose is to can move circle down without collision stop. Because circle velocity increases 0.6666px each frames, it will stop at x = 63.3333px or 64.333px. Then it can't move down:(
Please advice. Thanks so much. 

Link to comment
Share on other sites

Hi, if you want your player stop at junction and then move to another one (based on player's choice for example), I would place do this: place invisible markers at stop positions. When player selects direction or gives any input, then find nearest stop position. Then interpolate from current player's position to next stop position.

If your stop poisitons are at junction and (maybe) corners, you can load your maze and then make routine to analyze it and create stop positions on the fly (without loading any predefined data). You can even make your life easier if your stop position has structure like this (pseudocode):

class StopPos {
   // posiiton
   x : number;
   y : number;

   // links to other nodes - either another StopPos object or null
   leftStop : StopPos;
   rightStop : StopPos;
   upStop : StopPos;
   downStop : StopPos;
}

 Then just read linked next stop position and interpolate your player's position there.

Link to comment
Share on other sites

 Share

  • Recently Browsing   0 members

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