Home Tutorials Forums Articles Blogs Movies Library Employment Press
Old 05-24-2007, 11:18 AM   #1
van_doodle
Registered User
 
Join Date: May 2007
Posts: 15
Default jigsaw puzzle

Hi,
I'm trying to create a jigsaw puzzle,

I need code that allows the user to drag and drop, and snap into place if it is correct, or snap back into if its original position if it is incorrect.

Any ideas?

Thank you
van_doodle is offline   Reply With Quote
Old 05-24-2007, 01:20 PM   #2
sarumitai
Senior Member
 
Join Date: Apr 2007
Location: Japan
Posts: 111
Default Drag

Code:
target_mc.onPress = startDrag;

target_mc.onRelease = function () {
	this.stopDrag();
   	     if (this.hitTest(Goal_mc)) {
		this._x = 50;
		this._y = 50;
		this.enabled = false;
		this.filters = [gf];
	}
}

import flash.filters.GlowFilter;
var gf:GlowFilter  = new  GlowFilter(0x339900, 100, 3, 3, 5, 3, false, false);

Target_mc is simply the MC you want to drag around.
onPress = what happens when the mouse is PRESSED.
onRelease is what happens when the mouse is RELEASED.
Be careful of upper lower case.

this.stopDrag means "this MC that we are in" which is the target_mc.
IF the hitTest (overlap, touching) is true between this (target_mc) and another mc (here the Goal_mc), then do what is in the {}.
move the MC's X coordinate to 50
move the MC's Y coordinate to 50 (or wherever you want it to snap to)
this.enabled = false means they can't drag it anymore.
this.filters, along with the two lines at the bottom (which should be at the top) simply make it glow a bit once it has touched its target and then jumped into place. It's not needed, but it does make it clear it has been locked into place correctly.
sarumitai is offline   Reply With Quote
Old 05-24-2007, 01:25 PM   #3
sarumitai
Senior Member
 
Join Date: Apr 2007
Location: Japan
Posts: 111
Default but

But for a jigsaw you probably wouldn't want it to glow.

Also, you would do this with each piece of the puzzle. Each piece would be a Movie Clip and you would write this script for each (minus the glow parts).

4 puzzle pieces = puzzlePiece1, puzzlePiece2, etc.

puzzlePiece1.onPress = startDrag;

There is a way to do this via a FOR loop, but I just learned it and couldn't explain it.

http://www.actionscript.org/forums/s....php3?t=136767
sarumitai is offline   Reply With Quote
Old 05-25-2007, 07:33 AM   #4
van_doodle
Registered User
 
Join Date: May 2007
Posts: 15
Default hitTest recognition

once two movie clips(b1 and t1) touch(hitTest), i need the global to = 1;

but what do i need to add to code

b1.onPress = startDrag;
b1.onRelease = function () {
this. stopDrag ();
if (b1.hitTest (t1)) {
this._x = 266.2;
this._y = 489.1;
this. enabled = false;

}
}

but what and where do i add the text in?
van_doodle is offline   Reply With Quote
Old 05-31-2007, 12:45 PM   #5
sarumitai
Senior Member
 
Join Date: Apr 2007
Location: Japan
Posts: 111
Arrow

Code:
b1.onPress = startDrag;
b1.onRelease = function () {
this. stopDrag ();
if (b1.hitTest (t1)) {
this._x = 266.2;
this._y = 489.1;
global++;                    // if global is set to zero, now it's one
global = 1;                  // or global is now one. Either or, not both.
this. enabled = false;

}
}
Assuming global is a variable, just make it equal whatever in the IF condition. If they are touching via the hitTest, it will do everything in the {}. So here it moves the MC to 266.2 and 489.1, then it locks it, finally it adds one to the variable. Or it could just equal 1.
sarumitai is offline   Reply With Quote
Reply


Thread Tools
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
good jigsaw puzzle tutorial online drumn4life0789 Gaming and Game Development 0 02-21-2007 06:49 AM
Help with my actionscripts for jigsaw puzzle game manutd_20 Gaming and Game Development 0 10-05-2005 11:25 PM
jigsaw puzzle once complete johnsonn Gaming and Game Development 0 04-18-2005 11:30 AM
JigSaw Puzzle Problems mash_potatoe Gaming and Game Development 3 11-08-2004 03:46 PM


All times are GMT. The time now is 04:16 PM.

///
Follow actionscriptorg on Twitter

 


Powered by vBulletin® Version 3.8.5
Copyright ©2000 - 2014, Jelsoft Enterprises Ltd.
Ad Management plugin by RedTyger
Copyright 2000-2013 ActionScript.org. All Rights Reserved.
Your use of this site is subject to our Privacy Policy and Terms of Use.