Welcome Guest ( Log In | Register )

 
Reply to this topicStart new topic
> Bouncing Ball Tutorial, SwishMax - Beginner
fudoki
post May 21 2004, 08:06 AM
Post #1


Techno Cow
Group Icon
Group: Honored
Posts: 618
Joined: 19-May 04
From: londoniatansomataville
Member No.: 7





[color=#669900]the script for the ball in my sig, i was not the original creator of the ball script although i learnt from it and tweaked it, so this should not be used for commercial use. That said here is the script for the ball in my sig.

create a circle and give it this script

QUOTE(circle script)
on (press) {
startDragUnlocked();
dragging = true;
}
on (release,releaseOutside) {
stopDrag();
dragging = false;
}


then group the circle as a sprite and give the sprite this script

QUOTE(sprite script)
onFrame (1) {
_x=0;
_y=0;
xspeed=Math.random()*60-30;
yspeed=Math.random()*60-30;
rightedge=300;
leftedge=0;
topedge=0;
bottomedge=40;
gravity=1;
drag=.98;
bounce=.9;
}
onFrame (2) {
if (!dragging) {
_x = _x+xspeed;
if (_x+_width/2>rightedge) {
_x = rightedge-_width/2;
xspeed = -xspeed*bounce;
}
if (_x-_width/2_x = leftedge+_width/2;
xspeed = -xspeed*bounce;
}
_y = _y+yspeed;
if (_y+_height/2>bottomedge) {
_y = bottomedge-_height/2;
yspeed = -yspeed*bounce;
}
if (_y-_height/2 _y = topedge+_height/2;
yspeed = -yspeed*bounce;
}
yspeed = yspeed*drag+gravity;
xspeed = xspeed*drag;
} else {
xspeed=_x-oldx;
yspeed=_y-oldy;
oldx=_x;
oldy=_y;
}
}
onFrame (3) {
gotoAndPlay(2);
}
 
+Quote Post  Go to the top of the page
Koldplay
post Oct 28 2005, 11:32 PM
Post #2


New Member
Group Icon
Group: Member
Posts: 4
Joined: 3-September 05
Member No.: 6,686



i did this and it didnt work it flew all over the place i jsut want the circle to repeat it self but going up and down
QUOTE
onFrame (1) {
_x=0;
_y=0;
xspeed=Math.random()*60-30;
yspeed=Math.random()*60-30;
rightedge=300;
leftedge=0;
topedge=0;
bottomedge=40;
gravity=1;
drag=.98;
bounce=.9;
}
onFrame (2) {
if (!dragging) {
_x = _x+xspeed;
if (_x+_width/2>rightedge) {
_x = rightedge-_width/2;
xspeed = -xspeed*bounce;
}
if (_x-_width/2<leftedge) {
_x = leftedge+_width/2;
xspeed = -xspeed*bounce;
}
_y = _y+yspeed;
if (_y+_height/2>bottomedge) {
_y = bottomedge-_height/2;
yspeed = -yspeed*bounce;
}
if (_y-_height/2<topedge) {
_y = topedge+_height/2;
yspeed = -yspeed*bounce;
}
yspeed = yspeed*drag+gravity;
xspeed = xspeed*drag;
} else {
xspeed=_x-oldx;
yspeed=_y-oldy;
oldx=_x;
oldy=_y;
}
}
onFrame (3) {
gotoAndPlay(2);
}
 
+Quote Post  Go to the top of the page
Faakher
post Dec 28 2005, 04:30 AM
Post #3


Regular Dot
Group Icon
Group: Member
Posts: 57
Joined: 28-December 05
Member No.: 8,750





Grate Codes i like it very much.

Faakher
 
+Quote Post  Go to the top of the page
mpfeiffer
post Jan 12 2006, 03:00 PM
Post #4


New Member
Group Icon
Group: Member
Posts: 10
Joined: 3-December 05
Member No.: 8,460





Tried this but variables aren't all initialized. I tried to initialize them from _root but that didn't work, so I tried to initialize them within the same scope and while that worked, all I end up with is a ball that moves right to left slower and slower and does not respond to my dragging.

Bummer.
 
+Quote Post  Go to the top of the page
wcnktm
post Dec 28 2006, 10:08 PM
Post #5


New Member
Group Icon
Group: Member
Posts: 7
Joined: 28-December 06
Member No.: 14,318





Good begining. Hope to see more experiments here!
 
+Quote Post  Go to the top of the page
fedhater
post Dec 29 2006, 03:39 AM
Post #6


Mad Scientist
Group Icon
Group: *Premier*
Posts: 629
Joined: 19-May 04
From: .RO
Member No.: 10





A good experiment would be 3d collision meshing.
Great work Fudoki
 
+Quote Post  Go to the top of the page
MrCradler
post Oct 5 2007, 08:38 AM
Post #7


New Member
Group Icon
Group: Member
Posts: 16
Joined: 5-October 07
From: United Kingdom
Member No.: 17,875





Great Code...
 
+Quote Post  Go to the top of the page
Andrew_F
post Nov 5 2009, 01:38 AM
Post #8


New Member
Group Icon
Group: Member
Posts: 20
Joined: 12-April 09
Member No.: 24,863





Too much errors!!! blink.gif
The code do not work! g[1].gif
I'll try repair it later...
 
+Quote Post  Go to the top of the page
Andrew_F
post Nov 5 2009, 02:15 AM
Post #9


New Member
Group Icon
Group: Member
Posts: 20
Joined: 12-April 09
Member No.: 24,863





tryed to initialise variable "dragging" as _global
Then named object ball as "bb", sprite as mm thou, in Scene code:
on (press) {
mm.bb.startDrag(false);
mm.bb.dragging = true;
}
on (release,releaseOutside) {
stopDrag();
mm.bb.dragging = false;
}
in sprite "mm" in this string made:
if (!_root.mm.bb.dragging)
Yeah-h-h-h? after testing no errors, but bouncing only from left to right and does not respond to my dragging!!!
What the matter?
 
+Quote Post  Go to the top of the page
Andrew_F
post Nov 5 2009, 02:45 AM
Post #10


New Member
Group Icon
Group: Member
Posts: 20
Joined: 12-April 09
Member No.: 24,863





By the way in SwishMax3 I've done something working NOT in internal player (embedded in Swish),but in external.
May be this is a reason?
And what the result from the author himself? His source file swi or flv?
Attached File(s)
Attached File  Movie2.swi ( 5.35K ) Number of downloads: 98
 
 
+Quote Post  Go to the top of the page

Reply to this topicStart new topic
1 User(s) are reading this topic (1 Guests and 0 Anonymous Users)
0 Members:

 

RSS Lo-Fi Version Time is now: 29th July 2010 - 10:57 PM
WoW Gold | Loans | Broadband | Package Holidays | Life Insurance