need help

15 posts

Flag Post

k well i have a game
http://www.kongregate.com/games/phore_eyes/only-preview_preview
what i did was i have it so that when the ball hits a coin the variable coins goes up by 1 and when coins = 5 it goes to frame one but it always goes to frame one after i hit two or three.

 
Flag Post

i cant help you much cuz i cant see your code.

the only thing i can think of off the top of my head is that you don’t remove the coin MovieClip at the same location where you increment coins, resulting in multiple counts per coin.

can you post the code responsible for coin collision detection(and the location of that code)?

p.s.try placing this code right after you increment coins:

trace(“collision!! , coins ==”+coins)
and this code right before you remove the coin MovieClip:
trace(“removing”)

then run the game and post the results from the output panel

 
Flag Post

No idea what you just said…

Put the AS in pre tags (With “<” before the p and “>” after the e). Thanks.

 
Flag Post

if i only hit the first coin the output box says

removing

collision!! , coins ==1

removing

collision!! , coins ==2

removing

collision!! , coins ==3

removing

collision!! , coins ==4

removing

collision!! , coins ==5>

the code for the detection and the rest off the ball movie clip is

onClipEvent (load) {

turn = 0;
coins = 0;
yspeed = 0;
xspeed = 0;
gravity = 0.2;
radius = 5;
friction = 0.90;
precision = 360;
bounces = 0;

}

onClipEvent (enterFrame) {

if (root.go == true) {
collisions = 0;
sum_x = 0;
sum_y = 0;
yspeed = yspeed+gravity;
for (x=1; x<precision; x++) {
spot
x = x+radius*Math.sin(x*360/precision);
spot
y = y-radius*Math.cos(x*360/precision);
if (root.terrain.hitTest(spotx, spot
y, true)) {

collisions++;
sum_x = spot_x;
sum_y += spot_y;
}
}
if (collisions>0) {
root.last_hit._x = oldx;
root.last_hit._y = oldy;
bounces
;
_root.collisions.text = "Bounces: "
bounces;
ball_dir = Math.atan(yspeed/(xspeed*-1))/(Math.PI/180);
if ((xspeed*-1)<0) {
ball_dir = 180;
}
if ((xspeed*-1)>=0 && yspeed<0) {
ball_dir += 360;
}
spot_x = sum_x/collisions;
spot_y = sum_y/collisions;
x_cat = spot_x-x;
y_cat = spot_y-y;
ball_coll = Math.atan(y_cat/x_cat)/(Math.PI/180);
if (x_cat<0) {
ball_coll += 180;
}
if (x_cat>=0 && y_cat<0) {
ball_coll += 360;
}
ground_rotation = ball_coll-90;
if (ground_rotation<0) {
ground_rotation += 180;
}
bounce_angle = 180-ball_dir-2*(ground_rotation);
if (bounce
angle<0) {
bounce
angle += 360;
}
speed = Math.sqrt((yspeed*yspeed)
(xspeed*xspeed));
xspeed = speed*Math.cos(bounce_angle*Math.PI/180)friction;
yspeed = (speed
Math.sin(bounce_angle*Math.PI/180))-1friction;
x = oldx;
y = old_y;
}
else{
old
x = x;
old
y = _y;
}
_y = _y+yspeed;
_x = x+xspeed;
}
if (root.coin.hitTest(spotx, spot
y, true)) {

root.coin.visible = false;
trace(“removing”)

coins =1;
trace(“collision!! , coins ==”
coins)

}

if (root.coin2.hitTest(spot_x, spoty, true)) {
root.coin2.visible = false;
trace(“removing”)
coins =1;
trace(“collision!! , coins ==”
coins)

}

if (root.coin3.hitTest(spot_x, spoty, true)) {
root.coin3.visible = false;
trace(“removing”)
coins =1;
trace(“collision!! , coins ==”
coins)

}

if (root.coin4.hitTest(spot_x, spoty, true)) {
root.coin4.visible = false;
trace(“removing”)
coins =1;
trace(“collision!! , coins ==”
coins)

}

if (root.coin5.hitTest(spot_x, spoty, true)) {
root.coin5.visible = false;
trace(“removing”)
coins =1;
trace(“collision!! , coins ==”
coins)

}
if (coins == 5) {_root.gotoAndPlay(1)
}
}

 
Flag Post

Your problem is here (by the look of it):

root.coin.visible = false;

Invisible movieclips still cause collision detection.

Try root.coin.x=-1000;

 
Flag Post

try replacing this:


root.coin.visible = false;

with this:

_root.coin.removeMovieClip();

the collision is still detected when the coin is not visible

 
Flag Post

Things still show up on hitTests when they have _visible turned off.

You could either check whether each coin is visible when you hitTest, like:


if (root.coin2.visible && root.coin2.hitTest(spot_x, spoty, true))

or, change your remove code to actually remove the coin entirely instead of just making it invisible:


root.coin._visible.swapDepths(root.getNextHighestDepth());
_root.coin.removeMovieClip();
trace(“removing”);

hmm.. must type faster :p

 
Flag Post

thanks everyone.
EDIT:that doesn’t work for some reason

 
Flag Post

what doesn’t work?

 
Flag Post

the code they gave me

 
Flag Post

well if you tried typing in

root.coin._visible.swapDepths(root.getNextHighestDepth());

you might get an error, I don’t know what he was thinking when he wrote that one.

 
Flag Post

try replacing this:

root.coin.visible = false;

with this:

_root.coin.removeMovieClip();

the collision is still detected when the coin is not visible

 
Flag Post

You may need to swap depths, too, before removing the movieclip. Just try coin.swapDepths(0); then call remove MovieClip like pel suggests (add _root. if you must). Also, this assumes you are leaving the 0 depth open for removals, otherwise pick a depth that is clear…. I wouldn’t use getNextHighestDepth inside swapDepths as that might return a depth outside the range of removeMovieClip.

 
Flag Post

Ch00se, I’ve never had a problem removing MovieClips from the stage that were assigned to getNextHighestDepth… sounds like an odd problem to encounter. Anyway, whatever works…

 
Flag Post

Indie… this is probably a very rare case. But might as well handle it. Edit: according to the adobe flash documentation this is only a problem with version 2 components. I could have sworn I’ve seen this issue elsewhere, but I guess I was mistaken. So it’s up to you.