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
Havok Skittles / Bowling Game source code
Convert between bases-Integer to String
Increase/ Decrease FrameRate of a Flash Member
Animate Text By Font Size
XML TextRender v1.3
AX Icons
FlushEventsXtra
Flip Image Algorithm - Imaging Lingo
Rollover Toolkit
SaveScripts Xtra
 

 

 

Behavior Drag sprite around a snap grid

Added on 8/7/2002

 

Compatibilities:
behavior D8 PC

This item has not yet been rated

Author: davey001

Useful for some game type scripts, this behaviour allows you to drap a sprite around the screen, but constrains it to a grid. Unlike a normal drag and snap using the standard behaviours, this behaviour only moves the sprite from grid location to grid location. There are some extras which allow you to specify which grid locations can be dropped onto or not. Also I'm using a 32pix by 32 pix grid but that can be changed. Any suggestions would be most appreciated - btw I know that the allowable gid locations don't work properly, if you can think of an idea that works, let me know.

Download PC Source
property drag
property currmouse
property spritenum
property allowedx
property allowedy
property allowed
property lastokx
property lastoky
property allowedxok
property allowedyok

on beginsprite
  
  -- set up a default ok location, this can be changed as required
  lastokx=sprite(spritenum).loch-sprite(spritenum).width/2
  lastoky=sprite(spritenum).locv-sprite(spritenum).height/2
  
  -- x and y grid positions which are dropable onto - doesn't work properly as at present can't identify specific grid locations, just areas.
  set allowedx=[0,1,2,4]
  set allowedy=[1,2]
end


on mouseup
  if allowed=true then
    drag=false
    lastokx=sprite(spritenum).loch
    lastoky=sprite(spritenum).locv
  else
    drag=false
    sprite(spriteNum).loch=lastokx
    sprite(spriteNum).locv=lastoky
  end if
end

on mousedown
  drag=true
  
end
on exitframe
  
  allowedxok=false
  allowedyok=false
  if drag=true then
    put drag
    set currmouse= the mouseloc
    
    -- does the hard work. change the x and y multipliers as required for your grid, also change x and y to fit in with your stage size    
    
    repeat with x=0 to 19
      repeat with y=0 to 19    
        
        if inside(currmouse,rect(x*32,y*32,((x+1)*32),((y+1)*32))) then
          repeat with s in allowedx
            if x=s then
              allowedxok=true
            end if
            
          end repeat
          repeat with s in allowedy
            if y=s then
              allowedyok=true
            end if
          end repeat
          if allowedxok=true and allowedyok=true then
            sprite(spriteNum).member = member(1)
            allowed=true
          else
            sprite(spriteNum).member = member(2)
            allowed=false
          end if
          
          sprite(spriteNum).loch = x*32+sprite(spritenum).width/2
          sprite(spriteNum).locv= y*32+sprite(spritenum).height/2
          
          updateStage
        end if
        
      end repeat
      
    end repeat
  end if
  
  go the frame
  
end

 


Contact

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

Send e-mail