It is better than Soda. I tried my best to make it like the real one. I used a lot of tweens.
Here is the code.
-- Install function setup() local successFunc=function(data) saveProjectTab("UISwitch",data) print("Compelet to download the code.") end http.request("https://raw.githubusercontent.com/Thecivilizations/Old-Project/master/UISwitch",successFunc) end
Don’t mind the Chinese words in my code. I’m a Chinese
It’s really COOL! I quite like it!!
That’s an impressive switch! I love that you can drag it slowly like the iOS one. Very cool UI control.
@Simeon Does it possible to draw rounded rectangles more easily with Codea in the future? Now drawing them is a bit difficult.
@DayLightTimer , nice work. A well done switch.
But it is not better than Soda. Not even close, imho.
@DayLightTimer I can’t say if your switch is better than Soda because I’ve never loaded/run Soda. I like to keep code as simple as possible, so here’s an example I did for a switch class.
function setup()
s1=switch(100,400)
s2=switch(100,200)
end
function draw()
background(40, 40, 50)
s1:draw()
s2:draw()
end
function touched(t)
s1:touched(t)
s2:touched(t)
end
switch=class()
function switch:init(x,y)
self.x=x
self.y=y
self.v=0
end
function switch:draw()
stroke(180, 207, 224, 255)
if self.v==1 then
stroke(13, 183, 249, 255)
end
strokeWidth(50)
line(self.x,self.y,self.x+50,self.y)
noStroke()
fill(255,0,0)
ellipse(self.x+self.v*50,self.y,45)
-- do what you want with self.v
text(self.v,self.x+150,self.y)
end
function switch:touched(t)
if t.state==MOVING then
if t.x>self.x-25 and t.x<self.x+75 and t.y>self.y-25 and t.y<self.y+25 then
if t.deltaX>0 then
self.v=1
elseif t.deltaX<0 then
self.v=0
end
end
end
end