Can Someone Help Me with a split Screen Joystick On both sides only going Left Or Right

I can’t figure it our

What do you mean by “only going left or right”?

Maybe use translate? Sorry I don’t understand as well. You mean to move the screen?

Maybe he means a joystick on the bottom and top of the screen that only moves right or left. Like what would be used in a pong type of game. I’m not going to waste my time making something that might not be what he wants.

I think we should add a section to the FAQ, “How to ask a good question”

@yojimbo2000 They would actually have to read it. From past experience on this forum, very few new users read the faqs.

The joystick can only move left or right

@majied - why don’t you try explaining what you want, in more than 8 words? We can’t help you if you aren’t being clear.

Sorry
I meant a joy stick on the top and bottom of the screen that can only move left or right.
I know what I mean but I can’t explain it properly

Just Forget it

@majied We don’t forget things, you ask a question, we answer. Is this like what you want. Slide your finger back and forth near the top and/or bottom of the screen. Since I don’t know exactly what you’re going to do with the joysticks, I just added paddles.

displayMode(FULLSCREEN)

function setup()
    rectMode(CENTER)
    s1,s2=nil,nil
end

function draw()
    background(40, 40, 50)
    fill(255)   
    if s1 then
        s1:draw()
    end
    if s2 then
        s2:draw()
    end
end

function touched(t)
    if t.state==BEGAN then
        if s1==nil then
            s1=stick(t.x,t.y,t.id)
        elseif s2==nil then
            s2=stick(t.x,t.y,t.id)
        end
    end  
    if t.state==MOVING then
        if s1~=nil and t.id==s1.id then
            s1:touched(t)
        end
        if s2~=nil and t.id==s2.id then
            s2:touched(t)
        end
    end
    if t.state==ENDED then
        if s1~=nil and s1.id==t.id then
            s1=nil
        end
        if s2~=nil and s2.id==t.id then
            s2=nil
        end
    end
end

stick=class()

function stick:init(x,y,id)
    self.x=x
    self.y=y
    self.ox=x
    self.oy=y
    self.id=id
end

function stick:draw()
    fill(255,0,0)
    noStroke()
    ellipse(self.ox,self.oy,10)
    ellipse(self.x,self.y,10)
    stroke(255)
    strokeWidth(2)
    line(self.x,self.y,self.ox,self.oy)
    if self.y>HEIGHT/2 then
        rect(self.x,HEIGHT-150,100,30)
    else
        rect(self.x,150,100,30)
    end        
end

function stick:touched(t)
    self.x=t.x
    self.y=t.y
end

Ty

I made some improvements and limits

displayMode(FULLSCREEN)

function setup()
    rectMode(CENTER)
    s1,s2=nil,nil
end

function draw()
    background(40, 40, 50)
    fill(255)   
    line(0,HEIGHT/2,1000,HEIGHT/2)
    strokeWidth(5)
    noFill()
    ellipse(100,100,100)
    ellipse(665,915,100)
    if s1 then
        s1:draw()
    end
    if s2 then
        s2:draw()
    end
end

function touched(t)
    if t.state==BEGAN then
        if s1==nil and t.y > 50 and t.y < 150 and t.x > 50 and t.x < 150 then
            s1=stick(100,100,t.id)
        elseif s2==nil and t.y > 875 and t.y < 965 and t.x > 615 and t.x < 715 then
            s2=stick(665,915,t.id)
        end
    end  
    if t.state==MOVING then
        if s1~=nil and t.id==s1.id and t.y < HEIGHT/2 then
            s1:touched(t)
        end
        if s2~=nil and t.id==s2.id and t.y > HEIGHT/2 then
            s2:touched(t)
        end
    end
    if t.state==ENDED then
        if s1~=nil and s1.id==t.id then
            s1=nil
        end
        if s2~=nil and s2.id==t.id then
            s2=nil
        end
    end
end

stick=class()

function stick:init(x,y,id)
    self.x=x
    self.y=y
    self.ox=x
    self.oy=y
    self.id=id
end

function stick:draw()
    fill(255, 255, 255, 255)
    noStroke()
    ellipse(self.ox,self.oy,10)
    ellipse(self.x,self.y,10)
    stroke(255)
    strokeWidth(2)
    line(self.x,self.y,self.ox,self.oy)
    if self.y>HEIGHT/2 then
        rect(self.x,HEIGHT-150,100,30)
    else
        rect(self.x,150,100,30)
    end        
end

function stick:touched(t)
    self.x=t.x
    self.y=t.y
end

Nice update. If you’re just going to move the paddles back and forth, you can skip drawing the joystick. In fact, you can eliminate the stick class all together and just use the touch x,y values to move the paddles. But then you never really said exactly what you were trying to do.

Here’s an example of what I was saying about eliminating the stick class.

displayMode(FULLSCREEN)

function setup()
    tx,bx=WIDTH/2,WIDTH/2
end

function draw()
    background(40, 40, 50)
    stroke(255)
    strokeWidth(2)
    line(0,HEIGHT/2,WIDTH,HEIGHT/2)
    fill(255)
    rect(tx,HEIGHT-100,100,20)
    rect(bx,100,100,20)
end

function touched(t)
    if t.state==MOVING then
        if t.y>HEIGHT/2 then
            tx=t.x
        else
            bx=t.x
        end
    end
end

Thanks for the example
I was going to use it for a split screen game to move the charecter