Welcome to Dream.In.Code
Become an Expert!

Join 150,116 Programmers for FREE! Get instant access to thousands of experts, tutorials, code snippets, and more! There are 1,964 people online right now. Registration is fast and FREE... Join Now!




bounce a balll

 
Reply to this topicStart new topic

bounce a balll

mnabbu
22 Jun, 2008 - 03:33 AM
Post #1

New D.I.C Head
*

Joined: 2 Sep, 2007
Posts: 6


My Contributions
Sir,
i want to know thw syntax to write a function in the action script area of flash. the code in java. i am beginner.. want to know some basics..i want 2 draw a ball and then want to make it bounce starting from the initial x position to the end.. ie, horizontally bouncing.. i don't know whether to write the function onClipEvent(enterFrame) or onClipEvent(load). pls pls help me..
User is offlineProfile CardPM
+Quote Post

WolfCoder
RE: Bounce A Balll
22 Jun, 2008 - 12:00 PM
Post #2

ギュウ~
Group Icon

Joined: 5 May, 2005
Posts: 3,723



Thanked: 8 times
Dream Kudos: 1450
My Contributions
You should try programming it yourself first and show us that you've attempted to solve the problem.

This way you can show us the code you've tried- please add many comments to the code. Then we can take a look at what exactly the problem is.
User is offlineProfile CardPM
+Quote Post

stayscrisp
RE: Bounce A Balll
22 Jun, 2008 - 12:07 PM
Post #3

D.I.C Regular
***

Joined: 14 Feb, 2008
Posts: 284



Thanked: 11 times
My Contributions
What he said smile.gif
User is offlineProfile CardPM
+Quote Post

Tom9729
RE: Bounce A Balll
22 Jun, 2008 - 04:33 PM
Post #4

Debian guru
Group Icon

Joined: 30 Dec, 2007
Posts: 1,592



Thanked: 12 times
Dream Kudos: 325
My Contributions
Sir?
User is online!Profile CardPM
+Quote Post

KYA
RE: Bounce A Balll
22 Jun, 2008 - 11:07 PM
Post #5

#include <nerd.h>
Group Icon

Joined: 14 Sep, 2007
Posts: 5,910



Thanked: 159 times
Dream Kudos: 1375
My Contributions
first!

argh, I mean fourth! wink2.gif
User is offlineProfile CardPM
+Quote Post

mensahero
RE: Bounce A Balll
23 Jun, 2008 - 02:35 AM
Post #6

c0mput3rz Are Only Human
Group Icon

Joined: 26 May, 2008
Posts: 664



Thanked: 17 times
Dream Kudos: 75
My Contributions
QUOTE

i want to know thw syntax to write a function in the action script area of flash. the code in java


What? You want to write a java code in the actionScript area of FLash? biggrin.gif cool.
User is offlineProfile CardPM
+Quote Post

3DrunkPandas
RE: Bounce A Balll
23 Jun, 2008 - 08:06 AM
Post #7

New D.I.C Head
*

Joined: 6 Oct, 2007
Posts: 22


My Contributions
I dont really know what you're asking for, but basically, you need two variables, xSpeed and ySpeed; ySpeed decreases with time (assuming your y axis reference points toward the sky) to mimic the gravity. When the ball touches the ground, ySpeed should be reversed and multiplied by a constant to apply some energy dissipation, else it would bounce forever.

You then need a loop that updates the value of ySpeed and that applies the movement to the ball.

Good luck with that.

P.S.: I know you asked for syntax, but I'm not a very good coder yet, so I can't help you with that.

This post has been edited by 3DrunkPandas: 23 Jun, 2008 - 08:07 AM
User is offlineProfile CardPM
+Quote Post

stayscrisp
RE: Bounce A Balll
24 Jun, 2008 - 02:35 AM
Post #8

D.I.C Regular
***

Joined: 14 Feb, 2008
Posts: 284



Thanked: 11 times
My Contributions
You probably dont want this in you enter frame or load clip events , you want to have some kind of handle collision function which is called every frame to check for collisions and react to them accordingly, this may seem like overkill if all you want to do is make a ball bounce, but it will have extensibility as well, this is how i would approach it in c++.

i used actionscript before and made something like this, basically you can make 4 wall objects and just hit test against them and change the balls direction after bounce accordingly, very nasty but also effective smile.gif

an excercise once you have made your ball bounce is to then make a kind of smaller square which can be like a cage to your bouncing balls then when you click the mouse you can drag the balls into the cage and they bound off the cage instead of the overall square, good practice smile.gif

This post has been edited by stayscrisp: 24 Jun, 2008 - 02:39 AM
User is offlineProfile CardPM
+Quote Post

Fast ReplyReply to this topicStart new topic
Time is now: 1/9/09 01:11AM

Be Social

Dream.In.Code RSS Feed Dream.In.Code LinkedIn Group Follow Us On Twitter

Live Help!

Tutorials

Programming

Web Development

Reference Sheets

Code Snippets

DIC Chatroom

Bye Bye Ads

Monthly Drawing

Thumb Drive

Top Contributors

Top 10 Kudos This Month