I tried to break the code apart so I could make a circleWrapper that works without physics but when I tried to do it like the screen wrapper the code does not work.
Can someone please help me make the wrapper so myBall stays inside the circle when I tilt the device.
[code]
display.setStatusBar(display.HiddenStatusBar)
system.setAccelerometerInterval( 100 )
local centerX = display.contentWidth/2;
local centerY = display.contentHeight/2;
local _W = display.contentWidth;
local _H = display.contentHeight;
local halfWidth = 114;
local halfHeight = 114;
local acc = {}
– The ring the ball can not go outside.
local circle = display.newCircle(centerX, centerY, halfWidth, halfHeight)
circle:setReferencePoint(display.CenterReferencePoint);
circle:setFillColor( 123, 123, 123, 0)
circle:setStrokeColor(211, 199, 1 )
circle.strokeWidth = 2
local myBall = display.newCircle(centerX, centerY, 16, 16)
myBall:setReferencePoint(display.CenterReferencePoint);
myBall:setFillColor( 232, 111, 255)
function acc:accelerometer(event)
myBall.x = centerX + (centerX * event.xGravity);
myBall.y = centerY - (centerY * event.yGravity);
end
Runtime:addEventListener( “accelerometer”, acc )
–[[
function circleWrapper(x,y,w,h,angle1,angle2)
local xStart,yStart = x,y
local startAngle = math.rad(angle1) or math.rad(0)
local endAngle = math.rad(angle2) or math.rad(360)
i = startAngle,endAngle
if myBall.x < (xStart + w * math.cos(i),yStart - h*math.sin(i),xStart + w * math.cos(i) - 1, yStart - h*math.sin(i) -1) then
myBall.x = (xStart + w * math.cos(i),yStart - h*math.sin(i),xStart + w * math.cos(i) - 1, yStart - h*math.sin(i) -1)
end
if myBall.x > (xStart - w * math.cos(i),yStart + h*math.sin(i),xStart - w * math.cos(i) + 1, yStart + h*math.sin(i) 1) then
myBall.x = (xStart - w * math.cos(i),yStart + h*math.sin(i),xStart - w * math.cos(i) + 1, yStart + h*math.sin(i) 1)
end
if myBall.y < (xStart + w * math.cos(i),yStart - h*math.sin(i),xStart + w * math.cos(i) - 1, yStart - h*math.sin(i) -1) then
myBall.y = (xStart + w * math.cos(i),yStart - h*math.sin(i),xStart + w * math.cos(i) - 1, yStart - h*math.sin(i) -1)
end
if myBall.y > (xStart - w * math.cos(i),yStart + h*math.sin(i),xStart - w * math.cos(i) + 1, yStart + h*math.sin(i) 1) then
myBall.y = (xStart - w * math.cos(i),yStart + h*math.sin(i),xStart - w * math.cos(i) + 1, yStart + h*math.sin(i) 1)
end
end
myBall = circleWrapper(display.contentWidth/2, display.contentHeight/2, halfWidth, halfHeight,0,360)
–]]
[/code] [import]uid: 34126 topic_id: 9781 reply_id: 37365[/import]