00:00
00:00
Newgrounds Background Image Theme

PalmMan just joined the crew!

We need you on the team, too.

Support Newgrounds and get tons of perks for just $2.99!

Create a Free Account and then..

Become a Supporter!

As: Go to Clicked postiton

1,337 Views | 12 Replies
New Topic Respond to this Topic

As: Go to Clicked postiton 2006-01-12 12:59:08


My first AS thread , I hope it's useful...
What it does basicly is make your character or whatever go to the place you last clicked. Useful for Point 'n Click games.

open the actionscript window of the frame you want to be moved in...
Put your character in it and give it the instance name 'char' ( without '')

Give THE FRAME ( not the character) following code :

clickedx = _root.char._x
//the initial clickedx is the x-position of your character
clickedy = _root.char._y
//the initial clickedy is the y-position of your character
clicking = false;
//this is just to make sure you can only define the clickedx and y once while you're mouse- //button is down

onMouseDown = function () {
if (clicking == false) {
clicking = true;
clickedx = _xmouse;
clickedy = _ymouse;
//defines position of clicked X and Y
}
};
onMouseUp = function () {
clicking = false;
};

Now Give the character 'char' the following code :
onClipEvent(load){
ms = 10
//defines the moving speed
}
onClipEvent (enterFrame) {
// Tells the character to go to the clicked x-position
if (_root.clickedx>_x) {
_x += ms;
}
}
onClipEvent (enterFrame) {
if (_root.clickedx<_x) {
_x -= ms;
}
}

onClipEvent (enterFrame) {
// Tells the character to go to the clicked y-position
if (_root.clickedy>_y) {
_y += ms;

}
}
onClipEvent (enterFrame) {
if (_root.clickedy<_y) {
_y -= ms;
}
}

Test it out , This Should work...

Response to As: Go to Clicked postiton 2006-01-12 13:04:27


Its really nice thanks! But you forgot AS: Main

Response to As: Go to Clicked postiton 2006-01-12 13:05:17


Post an example please!

Response to As: Go to Clicked postiton 2006-01-12 13:08:49


It could be good as a foss... The point in AS: Main is that you explain and teach, not post a code. nice anyway...

Response to As: Go to Clicked postiton 2006-01-12 13:14:43


http://img28.imageshack.us/my.php?image=cl
icked5nr.swf

There, that should make some things clear
The Numbers in the Upper-left corner are the clicked x and Clicked y

Response to As: Go to Clicked postiton 2006-01-12 13:16:14


At 1/12/06 01:14 PM, Loomkind wrote: http://img28.imageshack.us/my.php?image=cl
icked5nr.swf
There, that should make some things clear
The Numbers in the Upper-left corner are the clicked x and Clicked y

You typed the info in the wrong order, so that link is broken xD

Example

Thats how it's done


BBS Signature

Response to As: Go to Clicked postiton 2006-01-12 13:16:39


Woops, I switched the link and title here's the real
Example

Response to As: Go to Clicked postiton 2006-01-12 13:27:51


At 1/12/06 01:08 PM, BrotherToast wrote: It could be good as a foss... The point in AS: Main is that you explain and teach, not post a code. nice anyway...

Yes, it's a FOSS for all I know.

Anyway, you don't need to set a new onClipEvent handler for every new action. All of the onClipEvent (enterFrame) blocks can be merged into one.

Or it could be totally replaced by:

onClipEvent (enterFrame) {
distX = _root.clickedx - _x, distY = _root.clickedy - _y;
dist = Math.sqrt (distX * distX + distY * distY);
radA = Math.atan2 (distY, distX);
_x += Math.cos (radA) * Math.min (dist, ms);
_y += Math.sin (radA) * Math.min (dist, ms);
}


BBS Signature

Response to As: Go to Clicked postiton 2006-01-21 05:51:32


that kinda sucked...


I have done the deed. Didst thou not hear a noise?

BBS Signature

Response to As: Go to Clicked postiton 2006-01-21 06:11:23


Be nice to the moron, he's trying to help. Unlike evil Rantzien who's showing off! >=(


BBS Signature

Response to As: Go to Clicked postiton 2006-01-21 06:14:13


At 1/21/06 06:11 AM, -Gust- wrote: Be nice to the moron, he's trying to help. Unlike evil Rantzien who's showing off! >=(

Sarcasm I hope -_-


BBS Signature

Response to As: Go to Clicked postiton 2006-01-21 06:17:30


What else, what else?


BBS Signature

Response to As: Go to Clicked postiton 2006-01-21 06:23:43


At 1/21/06 06:17 AM, -Gust- wrote: What else, what else?

=) I should know by know not to take anything you say seriously ;)


BBS Signature