Colin's absolutely right -
There are several ways to bounce a sprite off the edge of the stage.
Your sprite is bouncing when the regPoint hits the border and since
bitmaps generally have their regPoints at the middle, I'm guessing
that your sprite is made from a bitmap member.
You stated that you want the sprite to bounce off 'right away'
I'm guessing that you mean that you want it to bounce when the edge
of the sprite hits the edge of the Stage.
So your script needs to take the sprite's width & height from the
center (the regPoint) into account in your 'IF' statements.
To make your Behavior work, I've added comments & altered the code slightly.
hope it's clear enough and helps
-Buzz
At 4:52 PM -0500 4/5/02, you wrote:
>this script works except the ball bounces off
>the stage border only when half of it is over the border.
>how do I make it bounce off right away?
>
>script:
>
>-- ball bounces off when hits stage border
>
>global horDir, verDir, stageWidth, stageHeight
property my -- declared as a property
property myH -- 1/2 height of the sprite
property myW -- 1/2 width of the sprite
on beginsprite me --> I added 'me'
> horDir = 5
> verDir = 5
>
> stageWidth = (the stageright - the stageleft)
> stageHeight = (the stagebottom - the stagetop)
my = sprite(me.spriteNum) -- only need to define this once
myW = my.right - my.left -- calculate 1/2 the width of the sprite
myH = my.bottom - my.top -- calculate 1/2 the height of the sprite
>end
>
>on exitFrame me
-- my = sprite(me.spriteNum) --> moved into beginSprite
> my.locH = my.locH + horDir -- horizontal
> my.locV = my.locV + verDir -- vertical
>
if (my.locH - myW/2) < 0 then horDir = 5 -- go right
if (my.locH + myW/2) > stageWidth then horDir = -5 -- go left
if (my.locV - myH/2) < 0 then verDir = 5 -- go down
if (my.locV + myH/2)> stageHeight then verDir = -5 -- go up
-- it now accounts for the sprite size in each direction
-- (note: it assumes that the regPoints are in the middle -
-- if they're not, then 4 separate offsets must be calculated & used)
> go to the frame
>end
>[To remove yourself from this list, or to change to digest mode, go
>to http://www.penworks.com/lingo-l.cgi To post messages to the
>list, email [EMAIL PROTECTED] (Problems, email
>[EMAIL PROTECTED]). Lingo-L is for learning and helping with
>programming Lingo. Thanks!]
[To remove yourself from this list, or to change to digest mode, go to
http://www.penworks.com/lingo-l.cgi To post messages to the list, email
[EMAIL PROTECTED] (Problems, email [EMAIL PROTECTED]). Lingo-L is for
learning and helping with programming Lingo. Thanks!]