The student I have is making a game where Yoshi collects coins. He wants the coin to move to a random location after Yoshi comes in contact with it. Any ideas on how this could be possible?
Thanks in advance!
Hello,
if you have an if/then statement checking the collision of yoshi and the coin, you could then move the coin to a random position.
ex:
function checkCollect() {
if (yoshi.isTouching(coin)) {
score++;
do {
coin.x = randomNumber(0,400);
coin.y = randomNumber(0,400);
} while (yohi.isTouching(coin));
}
}
I thought is.Touching was only possible in Game Lab?
coin.x = randomNumber(0,400);
coin.y = randomNumber(0,400);
wouldn’t work either because the coin is an image id and needs to be in a string.
Thanks for the response but I don’t think that will work in this situation.
I thought is.Touching was only possible in Game Lab?
coin.x = randomNumber(0,400);
coin.y = randomNumber(0,400);
wouldn’t work either because the coin is an image id and needs to be in a string.
Thanks for the response but I don’t think that will work in this situation.
If collision support is not offered in app lab, I suggest implementing your own collision system. The simplest way is to use axis-aligned bounding box. It’s probably less efficient than using sprites but it works.