Copy link to clipboard
Copied
Hello!
I am currently doing game design at university and Have recently started looking at action script 3. I am not struggling too much and can usually find the answer to what I am looking for but this really has me stumped. I want to add an item to a game I am making so that when it is touched it gives some points and disappears. We have been taught to do this (so far) with hitTestObject and I am having an issue where I can get the symbol of the item to disappear but it I stay in the position I keep gaining points. I have tried looking this up but I am not finding anything that works. So any help would be greatly appreciated as I feel like throwing this laptop out of a window right now
This is what I have for my 'coin' right now, please excuse anything crazy as I am only just learning action script and probably have something crazy in there
// if character touches coin if (thief_mc.hitTestObject(coin_mc)){ if(stage.contains(coin_mc)) removeChild(coin_mc); // increase points by 5 score += 5; score_txt.text=String(score); }
Is there a way to stop at 5 points for the symbol or to remove it to stop any other points being gained?
oh, you're missing a curly bracket:
// if character touches coin | ||
if (thief_mc.hitTestObject(coin_mc)){ | ||
if(stage.contains(coin_mc)){ | ||
removeChild(coin_mc); | ||
// increase points by 5 | ||
score += 5; | ||
score_txt.text=String(score); } | ||
}
Copy link to clipboard
Copied
I'm guessing that this hitTest is happening inside a for() loop or something similar. If that's the case then you could probably use break; or return(); to get out of the loop.
Copy link to clipboard
Copied
something else is causing your points to increase. use a trace() function to confirm:
// if character touches coin if (thief_mc.hitTestObject(coin_mc)){ if(stage.contains(coin_mc)) removeChild(coin_mc); // increase points by 5 trace("coin_mc hit");
score += 5; score_txt.text=String(score); }
Is there a way to stop at 5 points for the symbol or to remove it to stop any other points being gained?
Copy link to clipboard
Copied
As I suspected when my character is standing where the coin was/is it is continually hitting the movie clip so it keeps adding the points.
Copy link to clipboard
Copied
oh, you're missing a curly bracket:
// if character touches coin | ||
if (thief_mc.hitTestObject(coin_mc)){ | ||
if(stage.contains(coin_mc)){ | ||
removeChild(coin_mc); | ||
// increase points by 5 | ||
score += 5; | ||
score_txt.text=String(score); } | ||
}
Copy link to clipboard
Copied
Thank you so much O_O I had a very similar problem and because people on my course have the same knowledge as me(ish) I had to wait over a week to see my lecturer to figure this out. Thank you so much
Copy link to clipboard
Copied
you're welcome.