Quick Links: Download Gideros Studio | Gideros Documentation | Gideros Development Center | Gideros community chat | DONATE
How would you do a "swipe to unlock" control? — Gideros Forum

How would you do a "swipe to unlock" control?

I think of a draggable button that triggers the action when moved to a certain position, but it also should come back to its original state with a smooth movement if it's released before reaching it..

Does anybody already made one and is willing to share it? :)

Thank you

Comments

  • olegoleg Member
    edited August 2018 Accepted Answer
    https://github.com/razorback456/gideros_tools/blob/master/Button.lua

    I did it in a button class for the sound
    --кнопка звук
    		local b_muz1=Button.new(Bitmap.new(Texture.new("img/muz.png")))
    		b_muz1:setScale(0.5)
    		b_muz1:setAnchorPoint(0.5,0.5)
     
    		local koef=((centrX+128)-(centrX-128))  -- 1% довжини =  пікс  
     
     
    			koef=(centrX-128)+ SoundCh:getVolume() *koef
     
    		b_muz1:setPosition(koef,centrY+64+13)
    		puz:addChild(b_muz1)
     
    a		b_muz1:addEventListener("clickMove", 
    			function(e)	
    			e:stopPropagation()
    				 --print(e.x, e.y)
                                     if e.x >centrX+128 then fl=true end
    				 if e.x>centrX-128 and e.x<centrX+128 then
    					b_muz1:setX(e.x)
                                            fl=nil
    					local koef=((centrX+128)-(centrX-128))/100
    					koef=(e.x-centrX+128)/koef/100
    					conf.vol=koef
    					if conf.vol<0 then conf.vol=0 end
     
    					 if SoundCh:isPlaying()==true then
    						SoundCh:setVolume(conf.vol)
    						if	 koef<0.1 then	SoundCh:stop()  end
    					elseif  koef>0.1 then
     
    						  f_sound()
     
    					 end
    				 end
    			end)
     
     
    ------------------------------------
    -- ПЕРЕМІСТИТИ З ЗАДАНОЮ ШВИДКІСТЮ
    function speed_move(sprite,x2,y2,speed)
            speed=speed/1000*60  --60fps
            x1, y1 = sprite:getPosition()
     
            sprite.move = MovieClip.new{
                            {1, speed, sprite, {x = {x1, x2, "linear"},y = {y1, y2, "linear"}}}  -- відтворити з 1 до 100 кадру з рухом по осі  Х від 0 до 200
                    }
            sprite.move:gotoAndPlay(1)
    end
    -----------------------------------------
    --speed_move(sprite,x2,y2,speed)
    	b_muz1:addEventListener("clickUP", 
    		function(e)	
    		e:stopPropagation()
    			knopka:play()
    if not fl then
    			 speed_move(b_muz1,centrX-128,centrY+64+13,300)
                            fl=true
    then
    		end)



    my games:
    https://play.google.com/store/apps/developer?id=razorback456
    мій блог по гідерос https://simartinfo.blogspot.com
    Слава Україні!
  • olegoleg Member
    edited August 2018
    the forum cuts the code


    4444444.PNG
    763 x 540 - 29K
    my games:
    https://play.google.com/store/apps/developer?id=razorback456
    мій блог по гідерос https://simartinfo.blogspot.com
    Слава Україні!
  • Indeed, the forum has become annoying when pasting code :(
  • hgy29hgy29 Maintainer
    edited August 2018
    When pasting code, just surround it with
    <code>
    and
    &lt;/code>
    and it should be displayed ok. How did you insert code to have that
    <pre class="CodeBlock">
    tag inserted too ?
  • olegoleg Member
    edited August 2018
    @hgy29
    -- the forum deletes part of the message between the <> characters
    my games:
    https://play.google.com/store/apps/developer?id=razorback456
    мій блог по гідерос https://simartinfo.blogspot.com
    Слава Україні!
  • olegoleg Member

    image.png
    510 x 238 - 27K
    my games:
    https://play.google.com/store/apps/developer?id=razorback456
    мій блог по гідерос https://simartinfo.blogspot.com
    Слава Україні!
  • hgy29hgy29 Maintainer
    edited August 2018
    Yes, I know you added that tag, but how ? Was it by clicking somewhere on the forum UI ? '< code>' is sufficient, no need for < pre class="CodeBlock">, and in fact it may disturb the code block processing

    Likes: antix

    +1 -1 (+1 / -0 )Share on Facebook
  • piepie Member
    Thank you @oleg :) I will use it as soon as I get to my laptop
  • olegoleg Member
    @hgy29 I just click the "code"
    sdfsdfsdf.PNG
    247 x 230 - 10K
    my games:
    https://play.google.com/store/apps/developer?id=razorback456
    мій блог по гідерос https://simartinfo.blogspot.com
    Слава Україні!
Sign In or Register to comment.