-- Touch Test
-- Use this function to perform your initial setup
function setup()
print("Hello World!")
back = color(16, 13, 13, 255)
where = vec2(0,0)
end
function draw()
background(back)
strokeWidth(5)
local t = tostring(where.x) .. ", " .. tostring(where.y)
text(t, WIDTH/2,HEIGHT/2)
end
function touched(touch)
where = vec2(touch.x,touch.y)
if touch.state == BEGAN then
back = color(0, 255, 0, 255)
elseif touch.state == MOVING then
back = color(255, 255, 0, 255)
elseif touch.state == ENDED then
back = color(255,0,0, 255)
end
end
Touching most anywhere gives a green flash,followed by red, if you pick up, or yellow then red if you drag first.
But touching in lower left hand corner, with x and y less than about 30, you see no green flash, as if there is no BEGAN just ENDED.
Will try in a non Pro iPad Asap, can someone with a Pro please verify? Thanks
(Also, editing in Forum in Codel on Pro seems very messed up. Is that common?)
I can confirm that the problem also exists on (old) iPad 2. The “dead” rectangle is indeed approximately 0,0,30,30.
MOVING and ENDED events do work, just BEGAN does not.
Using this program with FULLSCREEN_NO_BUTTONS and turning my iPad Air so the corner being tested is the lower left corner, after several tries of touching in the corner of the screen, I can get an x value of 0.0 or 0.5 and a y value of 6.5 or 7.0 in all 4 corners.
displayMode(FULLSCREEN_NO_BUTTONS)
function setup()
x,y=-10,-10
end
function draw()
background(40, 40, 50)
fill(255)
ellipse(x,y,4)
text(x.." "..y,WIDTH/2,HEIGHT/2)
end
function touched(t)
if t.state==BEGAN or t.state== MOVING then
x,y=t.x,t.y
end
end
It seems that in new iPad Pro 10.5” 2017 I also cannot press in corners… Only MOVING works… no BEGIN. Even in FULLSCREEN_NO_BUTTONS.
But I found one thing. When I press in the corner with two fingers, it works perfectly if second finger not in the corner.
I think it is defenetly a BUG, and it needs to be fixed.
But BEGIN not working at those coords. Tough I can press it normally with two fingers. Right now it is a solution for me, until it will be fixed. Can someone else confirm it?
@Compozitor On my 12.9" iPad Pro, when I use BEGAN, I can get a value of 0 on the left edge, values equal to HEIGHT at the top edge and equal to WIDTH at the right edge. On the bottom edge, I can only get a value of 7.
@Compozitor Here’s another program for you and anyone else with an iPad Pro 10.5” to try. On my iPad Air, the resolution for width is 0 to 768. For height it’s 0 to 1024. Using this program with only BEGAN for touch and touching as close to the edges as I can, I can get an xMin value of 0 on the left edge, a yMax value of 1024 on the top edge, an xMax value of 767.5 on the right edge, and a yMin value of 6.5 on the bottom edge. You can try this and anyone else to see what you get. Just keep touching near an edge for the min and max values.
displayMode(FULLSCREEN)
function setup()
tx,ty=0,0
xMin, xMax,yMin,yMax=9999,0,9999,0
end
function draw()
background(40, 40, 50)
fill(255)
text("xMin="..xMin,100,HEIGHT/2)
text("xMax="..xMax,WIDTH-100,HEIGHT/2)
text("yMin="..yMin,WIDTH/2,100)
text("yMax="..yMax,WIDTH/2,HEIGHT-100)
text("width X=0 to "..WIDTH.." height Y=0 to "..HEIGHT,WIDTH/2,HEIGHT/2)
ellipse(tx,ty,5)
end
function touched(t)
if t.state==BEGAN then
tx=t.x
ty=t.y
if tx>xMax then
xMax=tx
end
if tx<xMin then
xMin=tx
end
if ty>yMax then
yMax=ty
end
if ty<yMin then
yMin=ty
end
end
end
@dave1707 Can you please test my code? Try to click with one finger close to the left bottom corner, or opposite.
Btw in my “Main”, I have settled scale(2,2), noSmooth(), that’s why my everything is doubled in the touch section…
Sprites are 96,32 px
Thank you in advance…
I’m using last iOS version.
I added sprites. Name them please btn_img and btn_img_2
Button class:
Button = class()
function Button:init(name, x, y, flip)
-- you can accept and set parameters here
self.name = name
self.images = {"Project:btn_img", "Project:btn_img_2"}
self.pos = vec2(x, y)
self.action = nil
self.i = 1
self.flip = flip
self.w = 96
self.h = 32
if self.flip then
self.w = -self.w
end
end
function Button:draw()
-- Codea does not automatically call this method
spriteMode(CORNER)
if self.selected == true then
sprite(self.images[2],self.pos.x,self.pos.y, self.w, self.h)
else
sprite(self.images[1],self.pos.x,self.pos.y, self.w, self.h)
end
end
function Button:touched(t)
-- Codea does not automantically call this method
-- print(t.x)
-- print(t.y)
-- Flipped button
if self.flip then
if t.state == BEGAN and
t.x < self.pos.x*2 and t.x > self.pos.x*2 - math.abs(self.w*2) and
t.y > self.pos.y*2 and t.y < self.pos.y + self.h*2 then
self.selected = true
end
if t.state == ENDED and
t.x < self.pos.x*2 and t.x > self.pos.x*2 - math.abs(self.w*2) and
t.y > self.pos.y*2 and t.y < self.pos.y + self.h*2 then
self.selected = false
self.action()
end
else
-- Normal button
if t.state == BEGAN and
t.x > self.pos.x and t.x < self.pos.x + math.abs(self.w*2) and
t.y > self.pos.y and t.y < self.pos.y + math.abs(self.h*2) then
self.selected = true
end
if t.state == ENDED and
t.x > self.pos.x and t.x < self.pos.x + math.abs(self.w*2) and
t.y > self.pos.y and t.y < self.pos.y + math.abs(self.h*2) then
self.selected = false
self.action()
end
end
end
Main:
function setup()
displayMode(OVERLAY)
print("Hello World!")
print(WIDTH)
print(HEIGHT)
left_btn = Button("left", 0, 0)
right_btn = Button("right", WIDTH/2, 0, true)
left_btn.action = function() buttonPressed() end
right_btn.action = function() buttonPressed2() end
end
-- This function gets called once every frame
function draw()
-- This sets a dark background color
background(40, 40, 50)
noSmooth()
scale(2,2)
-- This sets the line thickness
strokeWidth(5)
-- Do your drawing here
left_btn:draw()
right_btn:draw()
end
function touched(t)
left_btn:touched(t)
right_btn:touched(t)
end
function buttonPressed()
print("Left Button pressed")
end
function buttonPressed2()
print("Right Button pressed")
end
@Compozitor I get an error on ReadXML. Also, anytime you use your own images, no one else has access to them. If you want others to see images, you either have to use images/sprites that come with Codea or you have to supply the images. Try running the program that I just wrote above to see what values you get for the min and max x and y values. If you can get within a few pixels of the edges with that program but you can’t with your program, then you have an issue with your program.
Hi all, will check out on my iPad pro later, does this just happen in portrait mode or is it also occuring in landscape.
This could fit in with my problem with poor response on the bottom left since the intro of ios 11. I suggested a vertical control box option, there were also issues with capturing screen images.
@Bri_G In portrait mode I get xMin of 0 (0), xMax of 767.5 (768), yMin of 6.5 (0) and yMax of 1024 (1024). In landscape mode I get xMin of 0 (0), xMax of 1024 (1024), yMin of 7 (0) and yMax of 768 (768).
@Compozitor I’m not exactly sure what you’re trying to do, but I took your code and made changes to what I think you might be trying to do. If not, let me know and we can change it.
Edit: Code changed. The buttons are larger and change color when pressed. The buttons were also moved above the 25 pixel error area.
function setup()
spriteMode(CORNER)
textMode(CORNER)
left_btn = Button("LEFT", 0, 50)
right_btn = Button("RIGHT", WIDTH-150, 50)
left_btn.action = function() buttonPressed1() end
right_btn.action = function() buttonPressed2() end
end
function draw()
background(40, 40, 50)
left_btn:draw()
right_btn:draw()
end
function touched(t)
left_btn:touched(t)
right_btn:touched(t)
end
function buttonPressed1()
print("Left Button pressed")
end
function buttonPressed2()
print("Right Button pressed")
end
Button = class()
function Button:init(name, x, y)
self.name = name
self.pos = vec2(x, y)
self.action = nil
self.w = 150
self.h = 75
end
function Button:draw()
stroke(255)
strokeWidth(4)
fill(0,255,0)
if self.selected == true then
fill(255,0,0)
end
rect(self.pos.x,self.pos.y, self.w, self.h)
fill(0,0,255)
text(self.name,self.pos.x+25,self.pos.y+15)
end
function Button:touched(t)
if t.state == BEGAN and
t.x > self.pos.x and t.x < self.pos.x + math.abs(self.w*2) and
t.y > self.pos.y and t.y < self.pos.y + math.abs(self.h*2) then
self.selected = true
self.action()
elseif t.state == ENDED and
t.x > self.pos.x and t.x < self.pos.x + math.abs(self.w*2) and
t.y > self.pos.y and t.y < self.pos.y + math.abs(self.h*2) then
self.selected = false
end
end