I'm using object:setDrag( ) with a movie clip to perform a drag operation on an object along one axis, but not the other. However, the built in functions call immediately instead of "onDrag" or "onPress" ect. I'm not certain what it is i'm doing wrong. I'm trying to track the drag position, or at least, the resulting position using the onDrag -> dragFunction call.
Code as follows:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 | function splashScreen() local object = movieclip.newAnim({"CON Splash v3-01.png"},960,640) object.x = display.viewableContentWidth/2 object.y = display.viewableContentHeight/2 local function dragFunction() object.alpha = 0.5 end object:setDrag{ drag=true, limitX=false, limitY=true, onDrag=dragFunction()} --[[ if ((object.x >= display.viewableContentWidth *.75 or object.x <= display.viewableContentWidth *.25)) then ==print("transition") end print(object.x) --]] end <lua> |
Sorry. Fixed version:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 | function splashScreen() local bkg = display.newImage( "CON Stage v8-01.png", true ) bkg.x = display.contentWidth/2 bkg.y = display.contentHeight/2 local myAnim = movieclip.newAnim({"CON Splash v3-01.png"},960,640) myAnim.x = display.viewableContentWidth/2 myAnim.y = display.viewableContentHeight/2 local function pressFunction() --myAnim.alpha = 0.7 end local function releaseFunction() myAnim.alpha = 1.0 if (myAnim.x >= display.viewableContentWidth *.55) then transition.to(myAnim, {time = 800, x = 1440}) --transition.to(myAnim, {time = 500, alpha = 0}) main() end if (myAnim.x <= display.viewableContentWidth *.45) then transition.to(myAnim, {time = 800, x = -480}) main() end end -- Make 2nd sprite draggable myAnim:setDrag{ drag=true, limitY=true, onPress=pressFunction, onRelease=releaseFunction, --bounds = { 50, 200, 220, 200 } } end <lua> |
views:1777 update:2011/9/20 13:12:00