View Full Version : i need a counter
daman2k
03-01-2005, 02:52 PM
its for a flash jigsaw, i want one so that when each piece snaps into place 16 in total, the counter counts down, how do i go about this?
gusion
03-01-2005, 03:08 PM
for the pieces, create flags that are set to true when the piece is in its place
//eg.
piece1.inplace=true
//and to count how much are placed right
pcnt=0;
for (i=1;i<=16;i++) {
if (this["piece"+i].inplace==true) {
pcnt++;
}
}
trace(pcnt);
notice, if the pieces indices start at 0, it must be for(i=0;i<=15;i++) ...
daman2k
03-01-2005, 03:21 PM
so do i put these both in the jigsaw puzzle piece? also how do i output this on screen, soz ima noob
gusion
03-01-2005, 03:24 PM
can't tell, because i don't know where you evaluate if the piece is in the right position
daman2k
03-01-2005, 03:25 PM
this is whats in the pieces
on(press)
{
startDrag("aa1");
}
on(release)
{
stopDrag();
if(aa1._x >80 &aa1._x < 170 && aa1._y> 70 && aa1._y<160)
{
setProperty("aa1",_x,"128.9")
setProperty("aa1",_y,"113.5")
aa1.inplace=true
}
}
gusion
03-01-2005, 03:46 PM
ok, then add the rest as a function to the timeline (either before the puzzle is started or at the first frame of the puzzle action)
function countsnaps() {
pcnt=0;
for (i=1;i<=16;i++) {
if (this["aa"+i].inplace==true) {
pcnt++;
}
}
if (pcnt==16) {
// insert here whatever you want to be done if the puzzle is solved
}
}
// and into the pieces, instead of the inplace-loop
if(aa1._x >80 &aa1._x < 170 && aa1._y> 70 && aa1._y<160)
{
setProperty("aa1",_x,"128.9");
setProperty("aa1",_y,"113.5");
aa1.inplace=true;
} else {
aa1.inplace=false;
}
countsnaps();
oh my god, there's an easier way... but this will only work if a snapped piece cant be moved away anymore
// into a frame in the timeline before the puzzle starts
pcnt=0;
function evalsnaps() {
if (pcnt==16) {
//do whatever shall be done if all on right position
}
}
// and to the pieces, for the loop
if(aa1._x >80 &aa1._x < 170 && aa1._y> 70 && aa1._y<160)
{
setProperty("aa1",_x,"128.9");
// btw, you could also set this by -> aa1._x=128.9;
setProperty("aa1",_y,"113.5");
pcnt++; //this increases the counter by one, if piece is snapped
}
|
vBulletin® v3.8.4, Copyright ©2000-2009, Jelsoft Enterprises Ltd.