owen Posted November 1, 2014 Share Posted November 1, 2014 Hi, very simple newbie question again sorry. I need to check if a sprite (or, any sprite at all) exists at x/y coordinates within the game. The reason I want to check is when I spawn a sprite I want it to be within a free space instead of on top of an existing sprite. Any ideas? So something like this:If (game.spriteExistsAt(150,380)==false) { // there's nothing there, spawn a sprite}ThanksOwen Link to comment Share on other sites More sharing options...
valueerror Posted November 2, 2014 Share Posted November 2, 2014 sprite or body?there is a checkhit function that checks at given x,y coordinates for a physics body and returns an array of bodies.. owen 1 Link to comment Share on other sites More sharing options...
Kiwi404 Posted May 23, 2018 Share Posted May 23, 2018 On 11/2/2014 at 8:54 PM, valueerror said: Hi @valueerror what is the true name of the "checkhit" which you are talking about ? Link to comment Share on other sites More sharing options...
samme Posted May 23, 2018 Share Posted May 23, 2018 https://photonstorm.github.io/phaser-ce/Phaser.Physics.Arcade.html#getObjectsAtLocation Kiwi404 1 Link to comment Share on other sites More sharing options...
Kiwi404 Posted May 23, 2018 Share Posted May 23, 2018 On 11/2/2014 at 8:54 PM, valueerror said: sprite or body? there is a checkhit function that checks at given x,y coordinates for a physics body and returns an array of bodies.. Thanks you @samme exactly what i need ! Link to comment Share on other sites More sharing options...
Kiwi404 Posted May 23, 2018 Share Posted May 23, 2018 37 minutes ago, samme said: https://photonstorm.github.io/phaser-ce/Phaser.Physics.Arcade.html#getObjectsAtLocation Just a last question @samme, is there an equivalent of getObjectsAtLocation based on sprite's physics body or i need to check it manually by iterating over the array returned by this function ? Link to comment Share on other sites More sharing options...
samme Posted May 25, 2018 Share Posted May 25, 2018 @Kiwi404 getObjectsAtLocation checks physics bodies (the docs don't make that clear). It's actually using Arcade.Body#hitTest so you could us that too if you prefer. Link to comment Share on other sites More sharing options...
Kiwi404 Posted May 25, 2018 Share Posted May 25, 2018 Indeed I saw it while experimenting, it use physics bodies coord instead of sprite's coord. Thanks ! Link to comment Share on other sites More sharing options...
Recommended Posts