PDA

View Full Version : Drag and Drop game help


jen86
11-17-2007, 12:11 AM
Hi
I was just wondering if anyone could help with this!:)
I'm in the process of making a simple drag and drop game where the user has to drag images of teeth onto an image of gums,placing them in the correct positions (i know,sounds kind of weird,but its for an biology elearning piece!!:rolleyes: )

Anyway i have it working so that when the user places the tooth in the correct position,it remains there and a message saying "correct" appears. When positioned in the worng place, it goes back to its original position and a "Wrong" message appears.
Where i'm having trouble is once the tooth is placed in the correct place, it is still dragable and can be moved again. How do i get it to lock in that position??At the moment i'm using the followin piece of code:

on(press){
StartDrag(this,true);
}
on(release){
stopDrag();
if(_root.Leftincisor.hitTest(_root.target1)==true) {
_root.feedback.gotoAndPlay("correct");
}else{
setProperty(this,_x,128);
setProperty(this,_y,152);
_root.negfeedback.gotoAndPlay("wrong");
}
}


Also, I would like the game to also recognise when the user has positioned all the teeth correctly and perhaps play a "Well done!" message or something along those lines.

If anyone could help me with this, I would really appreciate it!!
Thanks!
Jen;)

jen86
11-17-2007, 11:01 PM
Hi
I was just wondering if anyone could help with this!
I'm in the process of making a simple drag and drop game where the user has to drag images of teeth onto an image of gums,placing them in the correct positions (i know,sounds kind of weird,but its for an biology elearning piece!! )

Anyway i have it working so that when the user places the tooth in the correct position,it remains there and a message saying "correct" appears. When positioned in the worng place, it goes back to its original position and a "Wrong" message appears.
Where i'm having trouble is once the tooth is placed in the correct place, it is still dragable and can be moved again. How do i get it to lock in that position??At the moment i'm using the followin piece of code:

on(press){
StartDrag(this,true);
}
on(release){
stopDrag();
if(_root.Leftincisor.hitTest(_root.target1)==true) {
_root.feedback.gotoAndPlay("correct");
}else{
setProperty(this,_x,128);
setProperty(this,_y,152);
_root.negfeedback.gotoAndPlay("wrong");
}
}


Also, I would like the game to also recognise when the user has positioned all the teeth correctly and perhaps play a "Well done!" message or something along those lines.

If anyone could help me with this, I would really appreciate it!!
Thanks!
Jen

rrh
11-19-2007, 04:13 PM
on(press){
if (this.correctspot==true) {
} else
StartDrag(this,true);
}
on(release){
stopDrag();
if(_root.Leftincisor.hitTest(_root.target1)==true) {
this.correctspot=true;
_root.feedback.gotoAndPlay("correct");

...

TJones
11-21-2007, 07:50 PM
Also, I would like the game to also recognise when the user has positioned all the teeth correctly and perhaps play a "Well done!" message or something along those lines.

Simple. You want to reference all your teeth in an array and process that array on every onMouseUp event (each time you drop a tooth). So each tooth needs a variable that is set to true when it's in the right position.

So assuming you have your teeth in an array called toothArray and the variable is called inPlace


function processTeeth()
{
var len:Number = toothArray.length;
// begin loop
for (var i=0; i<len; i++)
{
if (toothArray.inPlace == false)
{
// a tooth was found out of place so stop
// processing and return out of function
return;
}
}
// you made it through the array so call your congradulations
// function here, dispatch message, or take whatever action...
congradulations();
}


TJ