I have this line of code that make hands move across the screen.. When its reached the other side of the screen I want them to move back from where they came from.. So essentially what I am trying to accomplish is hands moving back and forth on the bottom of the screen..
With the code I have here they just stop after the first time..Does anybody know how to fix this?
1 2 3 4 5 6 7 8 | local function moveHand() local hands = display.newImageRect("hands.png", 200, 127) hands.x = screenW + hands.contentWidth; hands.y = 700 local moveSpeed = 5000 local moveRight = transition.to(hands, {time=moveSpeed, x= 550}) transition.to(hands, {time=moveSpeed, x=-50, onComplete=moveRight}) end |
ok with some tests I was able to move the hand back but I don't know how to loop the function can somebody help me with that..
1 2 3 4 5 6 7 8 9 10 | local function moveRight (_t) transition.to(_t, {time=moveSpeed, x= 1024}) end local function moveHand() local hands = display.newImageRect("hands.png", 200, 127) hands.x = screenW + hands.contentWidth; hands.y = 700 transition.to(hands, {time=moveSpeed, x=-50, onComplete=moveRight}) end |
here you go
1 2 3 4 5 6 7 8 9 10 11 12 | local box = display.newRect(0,0,50,50) box.x = 0 box.y = 500 function transition_to_left() transition.to(box, {time=2000, x = 0, y = box.y, onComplete = transition_to_right}) end function transition_to_right() transition.to(box, {time=2000, x = 300, y = box.y, onComplete = transition_to_left}) end transition_to_right() |
Thank you so much dark consoles!! Looks just pong!!
Hey dark Console!! Can you help me figure out how I can tell the program to only dispatch the dispatcher when the hands are inside the hit spot that I have created? Heres the code that I have so far
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 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 | display.setStatusBar( display.HiddenStatusBar ) -- HIDE STATUS BAR -- LOAD PARTICLE LIB local loqsprite = require('loq_sprite') local physics = require ("physics") local director = require("director") physics.start() physics.setGravity(0,0) local rand = math.random local moveSpeed = 4000 local screenW = display.contentWidth local screenH = display.contentHeight local BG = display.newImageRect("background.png", 1024, 768) BG.x = screenW/2; BG.y = screenH/2 local gfactory = loqsprite.newFactory('girl') local girl = gfactory:newSpriteGroup() girl.x = 508; girl.y = 443 local wfactory = loqsprite.newFactory('water') local water = wfactory:newSpriteGroup() water.x = 300; water.y = 310 water.alpha = 0 local hfactory = loqsprite.newFactory('hands') local hands = hfactory:newSpriteGroup() hands.x =130; hands.y = 460 physics.addBody (hands, {radius = sensorRect, isSensor = true}) hands.myName = "hands" atrace(xinspect(hands:getSpriteNames())) function moveLeft() transition.to(hands, {time=moveSpeed, x = 130, y = hands.y, onComplete = moveRight}) end function moveRight() transition.to(hands, {time=moveSpeed, x = 870, y = hands.y, onComplete = moveLeft}) end local hitSpot = display.newImageRect("hitSpot.png", 240, 150) hitSpot.x = 510; hitSpot.y = 555 hitSpot.alpha = 0 physics.addBody (hitSpot, {radius = sensorRect, isSensor = true}) hitSpot.myName = "hitSpot" local screenTouch = function( _e ) if _e.phase == "ended" then dispatcher() end end function dispatcher() water:play("water splash") water.alpha = 1 hands:play("handmove splash") girl:play("washFace cleanFace") end function hitSpot:collision(_e) if _e.other.myName == "hands" then print("hands Passed") end end hitSpot:addEventListener("collision", hitSpot) Runtime:addEventListener ("touch", screenTouch) moveRight() |
1 2 3 4 5 6 7 | local screenTouch = function( _e ) if _e.phase == "ended" then if (hands.x + hands.width/2 > hitSpot.x - hitSpot.width/2 and hands.x - hands.width/2 < hitSpot.x + hitSpot.width/2) then dispatcher() end end end |
THANK YOU SO MUCH NE.HANNA!! THATS EXACTLY WHAT I WANTED!!!!!!!!!!!!!!!
I just tested ne.hannah and it worked great!! Thanks again!
how would you "stop" the transition ? I am looking to pressing a button and stopping the transition and then have that "object" turn into a "static" object.
You can do something like this to stop it
1 | Runtime:removeEventListener ("touch", screenTouch) |
You can also erase moving objects and put static ones in their place. The use case for this would be an explosion replace an enemy object.
@crssmn
do you mean changing the alpha=0 on the transition.to ?
that just makes it "invisible".
"You can also erase moving objects and put static ones in their place.", do you mean like setting the object = nil ?
send message and call to a person
Forum: Report Spam + PM
[INSTALL_PARSE_FAILED_NO_CERTIFICATES]
[SOLVED] Director ERROR: Failed to execute new( params ) function on 'screen1'
Too many (200) local variables
Corona SVG Level Builder released. Drag and drop physics level editor with Inkscape and SVG.
Small bug in Collectible Items example
Pivot Joints and apparent elasticity
Can't make removeSelf() delayed