Contents
Articles
Behaviors
Books
Director News
Director Web Sites
FAQ
Games
Mailing Lists
News Groups
Project Examples
Reviews
Software
Tools
Useful Web Sites
Utilities
Xtras

Don't miss these
Put stream percentage
FFT
Icon Shop
System Tools
Space Invaders
Set ImageEnabled Property of a Flash Member
Alphamania
Ripple Rain-Alphamania
Cuberoids
createSpecList
 

 

 

Behavior Orbiting Behavior

Added on 6/28/2000

 

Compatibilities:
behavior D7 D8 Mac PC Shockwave

Rating:

Author: BarrySwan (website)

The first object must me a central object to act as the root for all rotations. To create a central object simply leave the parent name empty. The radius property for a central object is ignored. You can have multiple central objects for multiple 'sets' of orbiting objects. Distances are measured in pixels and angles are measured in degrees.

----------------------------------------
-- Orbiting objects behaviour

-- Barry Swan, 28/06/2000
-- gerbil@theburrow.co.uk
-- http://www.theburrow.co.uk

-- All rights reserved

-- Inspired by (although not based upon)
-- behaviours by Danial Plaenitz
-- dp@lingo.de
-- http://www.lingo.de
----------------------------------------

property pName
property pParent, pParentSN
property pRadius
property pSN
property pAngle, pSpeed
property pRadiansAngle, pRadiansSpeed
property pRotate

on beginSprite me
  
  pSN = me.spriteNum  
  
  tMultiplier = pi() / 180.0
  pRadiansAngle = pAngle * tMultiplier
  pRadiansSpeed = pSpeed * tMultiplier
  
  pParentSN = sendAllSprites(#mParentSN, pParent)
  
end

on prepareFrame me
  
  if pParent <> "" then
    
    -- Get position of parent object
    
    tpCenter = sprite(pParentSN).loc
    
    -- Calculate new values for object
    
    pRadiansAngle = pRadiansAngle + pRadiansSpeed
    
    tX = sin(pRadiansAngle) * pRadius
    tY = cos(pRadiansAngle) * pRadius
    
    -- Draw sprite
    
    if pRotate then
      pAngle = pAngle + pSpeed
      sprite(pSN).rotation = -pAngle
    end if
    
    sprite(pSN).loc = tpCenter + point(tX, tY)    
  else
    
    -- Treat central object differently
    
    if pRotate then
      pAngle = pAngle + pSpeed
      sprite(pSN).rotation = -pAngle
    end if
  end if
  
end

on mParentSN me, tName
  
  -- Return sprite number if this is the correct parent
  -- Only correct answers return any data so the return
  -- value of 'sendallsprites()' will be correct
  
  if tName = pName then return pSN
  
end

on getPropertyDescriptionList me
  
  -- Set up the properties
  
  tlData = [:]
  tlData[#pName] = [#format: #string, #default: "center", #comment: "Name this object:"]
  tlData[#pParent] = [#format: #string, #default: "", #comment: "Name of parent object (if any):"]
  tlData[#pRadius] = [#format: #float, #default: 0.0, #comment: "Distance from parent object (in pixels):"]
  tlData[#pAngle] = [#format: #float, #default: 0.0, #comment: "Starting angle of object (in degrees):"]
  tlData[#pSpeed] = [#format: #float, #default: 0.0, #comment: "Rotational velocity per frame (in degrees):"]
  tlData[#pRotate] =[#format: #boolean, #default: TRUE, #comment: "Rotate the sprite itself:"]
  
  return tlData
  
end

on getBehaviorDescription me
  
  tText = "[Sprite] Orbiting behaviour." & RETURN & RETURN  
  
  tText = tText & "The first object must me a central object to act as the root for all rotations." & RETURN
  tText = tText & "To create a central object simply leave the parent name empty." & RETURN
  tText = tText & "The radius property for a central object is ignored." & RETURN
  tText = tText & "You can have multiple central objects for multiple 'sets' of orbiting objects." & RETURN
  tText = tText & "Distances are measured in pixels and angles are measured in degrees." & RETURN & RETURN
  
  tText = tText & "Properties -" & RETURN
  tText = tText & "pName" & TAB & "= Name of this object." & RETURN
  tText = tText & "pParent" & TAB & "= Name of object this object rotates around." & RETURN
  tText = tText & "pRadius" & TAB & "= Distance in pixels from the parent." & RETURN
  tText = tText & "pAngle" & TAB & "= Starting angle of this object." & RETURN
  tText = tText & "pSpeed" & TAB & "= Rotational velocity of ths object per frame." & RETURN
  tText = tText & "pRotate" & TAB & "= Whether to rotate the actual sprite itself." & RETURN & RETURN
  
  tText = tText & "Written by Barry Swan (gerbil@theburrow.co.uk)."
  
  return tText
  
end

 


Contact

MMI
36 South Court Sq
Suite 300
Newnan, GA 30263
USA

Send e-mail