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
Toast
ADOXtra Lite
Rotate Click-Alphamania
Replace returns with PC line breaks
Generic Countdown Timer
MediaMacros
Effector Set 1 Behavior Support
AppSafe Xtra for Authorware and Director
vList Utility
cXtraGraphicEffect
 

 

 

Behavior Starfield Behavior

Added on 6/30/2000

 

Compatibilities:
behavior D7 D8 Mac PC Shockwave

Rating:

Author: BarrySwan (website)

Creates a 3d starfield you can "fly" through

Download PC Source    Download Mac Source
----------------------------------------
-- 3D stars behaviour

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

-- All rights reserved
----------------------------------------

property pSN
property pX, pY, pZ
property pSize
property pSpeed

property pCenterX, pCenterY
property pMaxX, pMaxY

property pStarSize, pRandomiseStarSize

property pMouseMove, pMouseSpeed
property pClipToStage

on beginSprite me
  
  -- Store the sprite number for fast access
  
  pSN = me.spriteNum
  
  -- Store center of screen
  
  pCenterX = (the stageRight - the stageLeft) / 2
  pCenterY = (the stageBottom - the stageTop) / 2
  
  -- Define clipping boundaries
  
  pMaxX = the stageRight
  pMaxY = the stageBottom
  
  -- Create default star size
  
  pSize = pStarSize * 4000
  
  -- Initialise rest of star properties
  
  me.mReset()
  pZ = random(1000) + 1000
  
end

on prepareFrame me
  
  -- Mouse movement (if switched on)
  
  if pMouseMove then
    tDX = (pCenterX - the mouseH) * pMouseSpeed / pCenterX
    tDY = (pCenterY - the mouseV) * pMouseSpeed / pCenterX
    
    -- Move the star
    
    me.mMove(tDX, tDY)
  end if
  
  -- Update the star position
  
  pZ = pZ - pSpeed
  
  -- If star is too close then reset
  
  if pZ < 20 then me.mReset()
  
  -- Find screen position of star
  
  tX = (pX * pCenterX / pZ) + pCenterX
  tY = (pY * pCenterY / pZ) + pCenterY
  
  -- If star is outside the screen and clipping is switched on then reset
  
  if pClipToStage AND (tX < 0 OR tX > pMaxX OR tY < 0 OR tY > pMaxY) then me.mReset()
  
  -- Find scaling factor for size of star onscreen
  
  tSize = pSize / pZ
  
  -- Draw the star sprite
  
  sprite(pSN).loc = point(tX, tY)
  sprite(pSN).width = tSize
  sprite(pSN).height = tSize
  
end

on mReset me
  
  -- Create new parameters for star
  
  if pRandomiseStarSize then pSize = random(pStarSize) * 4000
  
  pX = random(3001) - 1501
  pY = random(3001) - 1501
  pZ = 2000
  
end

on mMove me, tDX, tDY
  
  -- Move star according to specified amount
  
  pX = pX + tDX
  pY = pY + tDY
  
end

on getPropertyDescriptionList me
  
  -- Set up the properties
  
  tlData = [:]
  tlData[#pSpeed] = [#format: #integer, #default: 10, #range: [#min: 1, #max: 100], #comment: "Star speed (1: slow, 100: fast):"]
  tlData[#pStarSize] = [#format: #integer, #default: 5, #range: [#min: 1, #max: 10], #comment: "Star size (1: smallest, 10: largest):"]
  tlData[#pRandomiseStarSize] = [#format: #boolean, #default: TRUE, #comment: "Star size is randomised between 1 and value set above:"]
  tlData[#pMouseMove] = [#format: #boolean, #default: TRUE, #comment: "Use mouse to steer star direction:"]
  tlData[#pMouseSpeed] = [#format: #integer, #default: 20, #range: [#min: 1, #max: 100], #comment: "Mouse affect speed (1: Barely, 100: lots):"]
  tlData[#pClipToStage] = [#format: #boolean, #default: TRUE, #comment: "Clip star when outside the stage:"]
  
  return tlData
  
end

on getBehaviorDescription me
  
  -- Return description of behaviour
  
  tText = "[Sprite] 3D stars behaviour." & RETURN & RETURN  
  
  tText = tText & "Drop this behaviour on a group of sprites to have them act like a 3D star field." & RETURN
  tText = tText & "Switching off clipping to stage will result in much less visible stars overall, but will allow stars to be scrolled off the screen and back on again." & RETURN & RETURN
  
  tText = tText & "Properties -" & RETURN
  tText = tText & "pSpeed" & TAB & TAB & TAB & "= Speed of star zooming out of the screen (1: slow, 100: fast)." & RETURN
  tText = tText & "pStarSize" & TAB & TAB & TAB & "= Relative star size (1: smallest, 10: largest)." & RETURN
  tText = tText & "pRandomiseStarSize" & TAB & "= Whether star size is randomised between 1 and value set for pStarSize" & RETURN
  tText = tText & "pMouseMove" & TAB & TAB & "= Whether to use mouse position to steer star direction." & RETURN
  tText = tText & "pMouseSpeed" & TAB & TAB & "= How much the mouse steers the star (1: Barely, 100: lots)." & RETURN
  tText = tText & "pClipToStage" & TAB & TAB & "= Whether to clip the star when it is outside the stage." & RETURN & RETURN
  
  tText = tText & "Internal handlers -" & RETURN
  tText = tText & "mReset()" & TAB & TAB & TAB & "= Resets the star to far away and randomises position and size (according to properties set).." & RETURN
  tText = tText & "mMove( tDX, tDY )" & TAB & TAB & "= Moves the star left/right and up/down according to the passed parameters." & 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