drag three or more sprites together
hello:
please, can tell me how drag 3 or more sprites not care sprite drag?
have sample?
many all
the simple answer keep list of sprites , use "call()" handler tell group something.
the actual implementation can take many forms. approach use requires several scripts, complicated explain. so, took code posted lets drag 1 sprite horizontally or vertically , added code radio button script grouping, , created behavior call "collective linear drag".
the behavior works assigning group name each set of sprites want move together. can have more 1 group on screen @ 1 time.
the behavior little different in uses static properties , handlers. means properties remember values after program stopped - inside ide - , handlers accessed through script member.
here need know use behavior:
use preparemove handler clear behavior's memory.
on preparemovie
script("collective linear drag").clear()
end
there handler returns last sprite click current groups.
ie put script("collective linear drag").getlastclicked()
that's it. paste code below behavior script , attach several sprites same group name, , drag.
-- collective linear drag
property sp -- sprite
property pdirection -- direction constain dragging, #horizontal, #vertical
property pstartloc -- sprite location upon mousedown
property pmousestart -- mouse location upon mousedown
property pmoving -- flag enterframe. true/false
property pgroupname -- name of group sprite part of
-- private static property
property pradiogroups -- property list of radio button group names , associated data
on getpropertydescriptionlist me
props = [:]
props[#pdirection] = [#default:#horizontal, #format:#symbol, #range:[#horizontal, #vertical], #comment:"pick direction drag"]
props[#pgroupname] = [#default:#group01, #format:#symbol, #comment:"group name."]
return props
end getpropertydescriptionlist
on beginsprite me
sp = sprite(me.spritenum)
if me.script.pradiogroups[pgroupname].voidp then -- need add new group name pradiogroups
me.script.pradiogroups[pgroupname] = [#sprites:[], #lastclicked:void]
end if
me.script.pradiogroups[pgroupname].sprites.add(sp) -- add sprite group.
pmoving = false
end beginsprite
on mousedown me
sprites = me.script.pradiogroups[pgroupname].sprites -- list of sprites sprite belongs to.
call(#startdrag, sprites) -- start dragging sprites in group.
me.script.pradiogroups[pgroupname].lastclicked = sp -- set sprite last 1 clicked group
end mousedown
on startdrag me
pstartloc = sp.loc
pmousestart = _mouse.mouseloc
pmoving = true
end
on mouseup me
sprites = me.script.pradiogroups[pgroupname].sprites
call(#enddrag, sprites)
end
on mouseupoutside me
sprites = me.script.pradiogroups[pgroupname].sprites
call(#enddrag, sprites)
end
on enddrag me
pmoving = false
end
on enterframe me
if not pmoving exit
deltamouse = _mouse.mouseloc - pmousestart
if pdirection = #horizontal then
sp.loc = pstartloc + point(deltamouse[1], 0)
else
sp.loc = pstartloc + point(0, deltamouse[2])
end if
end enterframe
--------------- grouping code ------------------------------
on new me,
if me.script.pradiogroups.voidp then -- no instance has been stored. stored 1 , instance allowed.
me.script.pradiogroups = [:] -- initialize property
end if
return me
end new
on clear me
me.script.pradiogroups = [:]
end
on getlastclicked me -- returns list of last buttons clicked/pressed each group
clicked = [:]
-- populate "clicked" list of group name / last clicked value pairs
total = me.script.pradiogroups.count
repeat cnt = 1 total
clicked[me.script.pradiogroups.getpropat(cnt)] = me.script.pradiogroups[cnt].lastclicked
end repeat
return clicked
end getlastclicked
More discussions in Director Lingo
adobe
Comments
Post a Comment