ActionScript 3.0 :: Bouncing Ball Off Edges Of Stage?
Jun 22, 2009
I have recently started Learning Actionscript 3.0 out of my own interest. I was trying on making a ball bounce off the edges of the stage using the Actionscript 3.0. But the code not working. The Ball happens to move on X and Y, till it hits the end of the stage, and then it just does not reverse its direction to give the effect of bounce, it gets stuck to the X axis and moves out of the stage. I tried to make changes, but failed.
Code:
function bounceBall(evt:Event):void {
var vx:Number=Math.random()*10+5;
var vy:Number=Math.random()*10+5;
var radius:Number=mcBall.height/2;
var top:Number=0;
[Code] .....
View 2 Replies
Similar Posts:
Jan 5, 2010
When I bounce a ball off the walls of the stage using the following technique.[code]Not only is the ball jumpy and skippy. but after so often it begins to go either in a vertal motion y = 5; x = 0; or a horzontal motion x = 5, y = 0. And stays that way. Why is it that the first method works fine but the other method works terrible. Could it be because the Math.cos and Math.sin returns very large decimals.I really prefer to use the second method.
View 5 Replies
Mar 8, 2011
I have a ball bouncing on a paddle. I want the "stage" to move vertically in order to always keep the ball centered.
View 2 Replies
Nov 5, 2009
I have added full screen code on my movie so that the user can extend the size of the movie. eg If the user expands the browser window to 1200 X 900, then my movie will become 1200 X 900 without the movie deforming.
Code:
Stage.scaleMode = "noScale";
Stage.align = "TL";
[code]....
View 3 Replies
Jun 20, 2006
i wanna ask how do i make a ball bounce off something like a ball bouncing off a bumper in a pinball game? i've tried a lot of times but everytime the ball get stucked to the box and it doesn't move anymore...will be grateful if anyone noes the actionscript of it..
View 3 Replies
Jan 15, 2003
i have just came across the tutorial with physics/bouncing ball - so far i have encountered no problems in understanding it, but just a question:how do i stop the ball bouncing? do i have to equal it to a certain value or just drop in another if/else statement, because now the ball seems to bounce forever, since it gets every time multpilicated by a negative number.
View 2 Replies
Nov 3, 2006
im was wondering if anyone knows the script for a ball bouncing off a paddle. I want the ball to bounce off the paddle in different directions depending on:
1) which side of the paddle it hits
2) which direction it came from
Ive only got this so far : script for the paddle
onClipEvent(enterFrame)
{
if (this.hitTest(_parent.ball)) //if this movieclip hits the movieclip 'ball'
tellTarget(_root.ball) //tell the ball to:[code]....
View 1 Replies
Apr 26, 2010
I have created a flash AS3 file with two movieclips. One is a ball (ball_mc) and a wall (wall_mc). The ball bounces around off the outer walls of the stage, in horizontal lines.
The ball also changes direction if it bounces off the wall. However its not bouncing off the wall in the right direction?
Code:
var dx:Number=3; //the amount the ball will move horizontally each frame
var dy:Number=5; //the amount the ball will move vertically each frame
this.addEventListener(Event.ENTER_FRAME,moveBall); // call the function moveBall every frame
[Code].....
View 6 Replies
Apr 12, 2005
below is the code I am useing I have created a simple frame with 2 layers one named body and one named Code in the code frame I have
[Code]...
In the body I have 4 walls all named top bottom right and left they are movies and they are named in there instance the same I have a circle I named ball and made it into a movie and named it ball yet when I run the flash file the ball flys off the page and doesnt bounce inside the boxes?
View 7 Replies
May 15, 2009
I am currently making a brick breaker game, so I want to make the ball bounce from the paddle. My paddle's name is pwn and the ball's name is ball.
My code for ball is currently:
onClipEvent (enterFrame) {
this._y += 5;
this._x += 4;
}
[Code]....
I just want the ball to bounce somewhere else other than stopping the ball at the place. I already made sure the paddle can move and the boundaries block the paddle from leaving the stage. So can someone give me the codes (please simple for me to copy-paste) for having me to bounce the ball some opposite direction or whatsoever. Like once the ball touches the paddle, it reflects somewhere else at the same speed and a different direction without any errors.
View 1 Replies
May 22, 2010
What I need is a ball to be bouncing. It needs it needs to slow down when it reaches its peak and increase speed as it falls. It needs to bounce forever at the same height. And last ... I need a button to make the ball look like its moving in slow motion (while still bouncing at the same height).
This is the closest I have come to getting it right. if you click the button when the ball is at its peak it works. but if you click any other time the ball will fly up to far (it needs to bounce the same height when in slow motion and in regular motion).
movieclips - "ball", "ground"
button - "btn"
[Code].....
View 1 Replies
Feb 28, 2010
I 'm looking for something like this but for free [URL]
View 0 Replies
Jul 29, 2009
I'm looking for a bouncing ball script, but one which is easily editable. I'm not a coder of any sort, but I can work out small sections of script.Basically, I want somewhere to set the number of balls, somewhere to set the speed and somewhere to set rotation. The objects I will be using will not be completely spherical, and need to look natural as they bounce off each other and off the walls, rotating as they do so.So, to clarify, I need an actionscript file that:
* Allows me to create objects that will bounce off all four walls. Gravity isn't a requirement.
* Allows me to create objects that have collision detection, allowing them to bounce off each other and rotate as they do so.
* Allows me to have the objects bouncing as soon as the flash file plays. In other words, clicking and dragging is not a requirement.
* Allows me to create x amount of objects at a randomised size.
* Allows me to specify the speed of the objects.
* Allows me to specify the rotation speed of the objects.
View 1 Replies
Jan 14, 2011
trying to basically using AS3 to make a ball bounce around the stage but never lose motion and have the chance to speed it up or slow it down through code.
View 3 Replies
Aug 19, 2009
I'm using the actionscript below to Move Object Using The Arrow Keys and it works fine but I want to modify it so that when I press the up key it goes to and play a movie clip. Basically it's a ball movie clip that responds to the arrow key but on the up key it plays a bouncing movieclip and everything remains aligned.
Here is the script-
var speed =5;
this.onEnterFrame =function(){
if(Key.isDown(Key.UP)) {
circle._y -= speed;
} if(Key.isDown(Key.DOWN)) {
circle._y += speed;
} if(Key.isDown(Key.LEFT)) {
circle._x -= speed;
} if(Key.isDown(Key.RIGHT)) {
circle._x += speed;
}};
View 13 Replies
Feb 25, 2012
trying to animate the ball in 3d space. Is there a formula for this?
var xPos:Number = tennis_ball.x;
var yPos:Number = tennis_ball.y;
var xVel:Number = (Math.random() * 10) - 5;
[code]....
View 1 Replies
Apr 29, 2011
how to stop a ball from bouncing up and down when I grab the ball with my cursor?Currently, I have two sections of code, one for a drop and drag, and one to reenact the effects of gravity on my ball.I don't want the ball to start bouncing right away,I want it to either start bouncing when I drag it and let go, or start bouncing when I click a button.I would also like it to STOP bouncing altogether if I grab the ball. (because even though I can drag it around, the bouncing animation is still running!)Here's my current code: (With one "ball_mc" on the stage)
// creating some gravity
var spring:Number=.1;
var frizione:Number=.98;[code]........
View 1 Replies
May 21, 2010
I have a ball bouncing that works great. What I want is a button that will make the ball look like its in slow motion (while still bouncing at the same height) and another button to put it back in regular motion. After hours of experimenting I still couldn't get it perfect. The following code is on the ball movieclip.
Code:
onClipEvent (load) {
var acceleration = 0.005;
var termVelocity = 20;
[Code]......
View 9 Replies
Feb 24, 2012
So in my level 1, here's what I wanted it to look like:on enter frame, a few of my "drag-gable" buttons are going to fall to the ground, bounce a little bit and stop when they ran out of speed.Attached the file that I've already scripted the drag n drop on each button, now how do i script the "fall to the ground part"?
View 0 Replies
Nov 8, 2004
I am trying to work out a way to achieve the bouncing ball effect over text known from karaoke players? I would like this to be done programmatically with actionscript, so the ball follows the text and the soundfile (looking for pauses or DB rises?maybe not). I have heard its a question of finding the right algorithm? Its use will be in a language lab-like flash app based on Communication server, where the user can :
1) Hear the correct pronunciation of a sentence (with bouncing ball over text)
2) Record their own voice
3) Compare the two
View 1 Replies
Mar 11, 2011
I have been trying to figure out a good strategy to perform a bitmap crop using Actionscript3. For example: I have a picture of a car and I want to crop out the car from the image alone and feather the edges so that they do not look jagged.
I am a flash noob and have only been using it for a couple of weeks. I've tried a couple of options and here is the last one that I have come up with it: I place red dots on stage that are draggable so that you can outline the object you want to crop and the dots are the bounds for a gradientFill that is used as the bitmap's mask. (I am using a radial gradient ... so the results are far from what I want, since the car is not an oval).
[Code]...
1) How can I fade just the edges of this custom-shaped fill outlined by the red dots?
2) I want to save the image out to a file once it's cropped. What strategy would be better for doing this using a BitmapFill or a GradientFill as a Mask (If it's possible with both)?
3) I may be using this strategy to crop faces later on.. anyone know of any good face detection APIs for as3? (also edge detection APIs)
View 1 Replies
Feb 26, 2007
Recently a client of mine decides he wanted rounded edges for his page vs. the typical square edges. This was after the initial design and at the point where it is almost complete.I told the client that in order to do this we would have to go to a full Flash web page meaning a full browser Flash page (everything is already flash).Now I told him that we could do this but because it was a new design and as you know that there is much involved in doing something like this i.e. all the paths will have to be changed because it will have to reside inside a mc etc.if there is an actual way to make the stage rounded only for future knowledge.I know I can make a round edge square or rectangle but it still has square edges at outer edge of the stage.
View 5 Replies
Jul 10, 2008
Do you know any tutorial similar to this one [URL]...y=ActionScript) that shows how to make a bouncing image that resizes during bouncing?
View 3 Replies
Feb 23, 2005
[code]...
I want the map's movement to be constrained to the edges of the stage. Or in other words, if you move your mouse from the left edge of the stage to the right, you only just see the right edge map, whereas now, it dissappears off the other side of the stage.
View 3 Replies
Sep 16, 2010
Im having multiple movieclips moving randomly and bouncing of the stage border, however, my problem is, first of all that the movieclips get half their body into the border on the right and top, and on the left and bottom the movieclip stops before the border. My other problem is that the movieclips have a tendency to get stuck in the border and just bounce rapidly along the border side. Im gonna asume that i only need to show you the code which the bounce back at border is created not to make the code to long (so hopefully im right):
[Code]...
View 1 Replies
Feb 23, 2005
Scrolling Map And this is the code...
[Code]...
I want the map's movement to be constrained to the edges of the stage. Or in other words, if you move your mouse from the left edge of the stage to the right, you only just see the right edge map, whereas now, it dissappears off the other side of the stage.
View 3 Replies
Dec 7, 2010
This is sort of a multi-layered question- I have a movie clip that I sectioned off in quadrants:The red dot is the player, the stage is the size of one square. My goal is to, when the player moves to either of the 4 edges, the next section of the quadrant comes up (meaning if the player moves to the right edge, the section that borders the right edge will slide on screen, and the old section will slide off screen).I was wondering if there was a way to hitTest if an object is touching any part of the edges? Is the hitTestPoint method something I should look into? What I have so far is an object off screen (black rectangle), that when the player touches the quadrants slide like I want them to (at least I'm trying to make that work).Here is my code. I know some of it's wrong and/or I'm missing something.
if(leftKeyIsDown && player_mc.x > -15)
//-15 is half the size of the temporary player_mc
{
[code]......
View 18 Replies
Feb 28, 2012
Im trying to get the sprite overlay to stick to the edges of the stage when I resize the swf window. It works when you resize the width, but not the height.
[Code]...
View 2 Replies
Nov 3, 2010
I have this code to make a ball bounce. it works fine, however, everything on the stage bounces. I only want the ball to bounce.
Here is my code
/* Actionscript 3.0 Bounce Effect. ball = movieclip instance name*/
var velocity = 0;
var gravity = 2;
var speed = 0.03;
var ground = 300;
Object(this).ball.addEventListener(Event.ENTER_FRAME, fl_bounce);
function fl_bounce(event:Event) {
[Code] .....
View 5 Replies
May 1, 2005
I haven't done much actionscript stuff ...and at the moment im trying to make a ball bounce across the stage, but im unsure how to go about doing that.
View 3 Replies