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
XML TextRender v1.3
Amara Flash Intro and Banner Builder
WinGroup Xtra
Happy Hour Fonts
Text scrolling effect
Dynamic Pie Charts
Toggle ImageEnabled Property of a Flash Sprite
DirectTransition3D Xtra Set I
Mundo Director
 

 

 

Behavior Simple Sprite Mover Behavior

Added on 6/30/1999

 

Compatibilities:
behavior D6_5 D7 D8 Mac PC

This item has not yet been rated

Author: LorenMork

This simple behavior moves a sprite across the screen either left to right - or right to left - or top to bottom - or bottom to top, and after the sprite vanishes it appears and goes across again ie it wraps

-- SimpleSpriteMover

-- This simple behavior moves a sprite
-- across the screen either
-- left to right - or
-- right to left - or
-- top to bottom - or
-- bottom to top,
-- and after the sprite
-- vanishes it reappears
-- and goes across again;
-- ie it "wraps".

-- It moves at
-- any "speed" you wish,
-- on each enterframe event.

-- Attach this behavior to a sprite.

-- Hacked by
-- Loren Mork   1997
-- Seattle, Washington    
-- LMork@aol.com
-- LMork@accessone.com

-- properties

property  pi_theSprite     -- Contains the number of the sprite we are moving - integer
property  pi_theLocH       -- Contains the LocH of the sprite we are moving - integer
property  pi_theLocV       -- Contains the LocV of the sprite we are moving - integer
property  pi_stageWidth    -- Contains the width of the stage we are on - integer
property  pi_stageHeight   -- Contains the height of the stage we are on - integer
property  pi_AmountToMove  -- Contains the amount to move each time - integer
property  ps_Direction     -- Contains a string indicating the direction to move in   - string

on beginsprite me
  set pi_theSprite   = the spritenum of me
  set pi_theLocH     = the loch of sprite the spritenum of me
  set pi_theLocV     = the locv of sprite the spritenum of me
  set pi_stageWidth  = the stageright - the stageleft
  set pi_stageHeight = the stagebottom - the stagetop
  
  if pi_AmountToMove < 0 then
    set pi_AmountToMove = pi_AmountToMove * -1
  end if
    
  if ps_Direction = "left" then
    set pi_AmountToMove = pi_AmountToMove * -1
  end if
  
  if ps_Direction = "up" then
    set pi_AmountToMove = pi_AmountToMove * -1
  end if
end beginsprite

on enterframe me  
  if ps_Direction = "down" then
    
    set pi_theLocV = pi_theLocV + pi_AmountToMove
    set the locv of sprite pi_theSprite = pi_theLocV
    
    if the top of sprite pi_theSprite > pi_stageHeight then    
      set pi_theLocV = -1 * ( the height of sprite pi_theSprite / 2 )
      set the locv of sprite pi_theSprite = pi_theLocV      
    end if
  end if
  
  if ps_Direction = "up" then    
    set pi_theLocV = pi_theLocV + pi_AmountToMove
    set the locv of sprite pi_theSprite = pi_theLocV    
    if the bottom of sprite pi_theSprite < 0 then      
      set pi_theLocV = pi_stageheight + ( the height of sprite pi_theSprite / 2 )
      set the locv of sprite pi_theSprite = pi_theLocV
     end if
  end if
  
  
  if ps_Direction = "right" then  
    set pi_theLocH = pi_theLocH + pi_AmountToMove
    set the loch of sprite pi_theSprite = pi_theLocH    
    if the left of sprite pi_theSprite > pi_stageWidth then
       set pi_theLocH = -1 * ( the width of sprite pi_theSprite / 2 )
      set the loch of sprite pi_theSprite = pi_theLocH
    end if
  end if
    
  if ps_Direction = "left" then
  
    set pi_theLocH = pi_theLocH + pi_AmountToMove
    set the loch of sprite pi_theSprite = pi_theLocH    
    if the right of sprite pi_theSprite < 0 then
            set pi_theLocH =  ( the width of sprite pi_theSprite / 2 ) + pi_stagewidth
      set the loch of sprite pi_theSprite = pi_theLocH    
    end if
  end if
end enterframe

on getPropertyDescriptionList me  
  set pl_proplist = [:]
  
  addProp pl_proplist,#ps_Direction,[#default:"right", #format:#string,#range:
["Left","Right", "Up","Down"] ,#comment:"Which direction should the sprite
move?"]
    
  addProp pl_proplist,#pi_AmountToMove,[#default:10,
#format:#integer,#comment:"Amount of pixels to move each move?"&return&"Note :
this should be a positive number "]
  
  return pl_proplist
  
end getPropertyDescriptionList

on getBehaviorDescription me  
  set ps_string  to "SimpleSpriteMover"&RETURN&"By Loren Mork, LMork@aol.com, LMork@accessone.com, Seattle/ Washington/ USA"&RETURN&"This behavior moves a sprite across the screen left to right - or - right to left - or - top to bottom - or - bottom to top - and after the sprite vanishes it reappears on the other side of the screen and goes across (or up/down ) again; ie it wraps."& RETURN &"It moves at any speed you wish, on each enterframe event." & RETURN &"Parameters are direction and amount to move (speed). Amount to move should be a positive number. A higher number will result in a faster speed"
return  ps_string  
end getBehaviorDescription

 


Contact

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

Send e-mail