James L Posted March 15, 2016 Share Posted March 15, 2016 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 More sharing options...
P4nch0 Posted March 15, 2016 Share Posted March 15, 2016 You cant check it by collision function? WHe player is going and collide with any other sprite then do anything? game.physics.arcade.collide(sprite, sprite2); Link to comment Share on other sites More sharing options...
James L Posted March 17, 2016 Author Share Posted March 17, 2016 Hi P4nch0, it does not collide any thing. So I can't check it. Pls see attached photo http://postimg.org/image/kxk5g6b9l/. Circle changes velocity to move from A to B. It collides nothing on the road. My purpose is that stopping it in start place at C corner. Please advice how can I do. Thanks. Link to comment Share on other sites More sharing options...
P4nch0 Posted March 17, 2016 Share Posted March 17, 2016 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 More sharing options...
James L Posted March 25, 2016 Author Share Posted March 25, 2016 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 More sharing options...
Tom Atom Posted March 25, 2016 Share Posted March 25, 2016 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 More sharing options...
Recommended Posts