×
INTELLIGENT WORK FORUMS
FOR COMPUTER PROFESSIONALS

Are you a
Computer / IT professional?
Join Tek-Tips Forums!
• Talk With Other Members
• Be Notified Of Responses
• Keyword Search
Favorite Forums
• Automated Signatures
• Best Of All, It's Free!

*Tek-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

#### Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

# Random bird

## Random bird

(OP)
Hi do you know which code i should use in order to make a bird fly around the screen randomly and without leaving the screen

Thanks a lot!!!

### RE: Random bird

There are many ways, but here's one example:

#### CODE

-- Behaviour script attached to a Sprite
property pSprite
property pSpeed
property pIdle
property pStageWidth, pStageHeight
property pCounter
property pLimit
property pVector

on beginSprite me
pSprite = sprite(me.spriteNum)
pSpeed = 3
pIdle = 30
stageRect = _movie.stage.rect
pStageWidth = stageRect[3]-stageRect[1]
pStageHeight = stageRect[4]-stageRect[2]
pCounter = 0
setNewVector()
end beginSprite

on enterFrame me
currentLoc = pSprite.loc
if currentLoc[1] < pSpeed then reverseVector(1)
if currentLoc[1] > (pStageWidth - pSpeed) then reverseVector(1)
if currentLoc[2] < pSpeed then reverseVector(2)
if currentLoc[2] > (pStageHeight - pSpeed) then reverseVector(2)
if pCounter > pLimit then setNewVector()
pSprite.loc = pSprite.loc + pVector
pCounter = pCounter + 1
end enterFrame

on reverseVector arg
pVector[arg] = -pVector[arg]
pSprite.loc = pSprite.loc + pVector
end reverseVector

on setNewVector
pCounter = 0
pLimit = random(pIdle)
pVector = point(random(3)-2, random(3)-2)*pSpeed
if pVector = point(0, 0) then
setNewVector()
else
return
end if
end setNewVector
--
As you see I wrote this in such a way so that the Sprite moves about very randomly. (Not very "bird".) Adjusting "pSpeed" and "pIdle" value is the first place to tweak.

Kenneth Kawamoto
www.materiaprima.co.uk

#### Red Flag This Post

Please let us know here why this post is inappropriate. Reasons such as off-topic, duplicates, flames, illegal, vulgar, or students posting their homework.

#### Red Flag Submitted

Thank you for helping keep Tek-Tips Forums free from inappropriate posts.
The Tek-Tips staff will check this out and take appropriate action.

Close Box

# Join Tek-Tips® Today!

Join your peers on the Internet's largest technical computer professional community.
It's easy to join and it's free.

Here's Why Members Love Tek-Tips Forums:

• Talk To Other Members
• Notification Of Responses To Questions
• Favorite Forums One Click Access
• Keyword Search Of All Posts, And More...

Register now while it's still free!