I want to make a carousel in landscape orientation. I’ve been successful replacing the center poledisplay.newRect with my image I want. Next the images that rotate around the object are just numbered rectangles and I want to place individual images that when using ‘touch’ a different url is opened for each one. The carousel can also be dragged and I need it to be fixed. I think this would be similiar to tableViewXL because it calls on i=1 but not sure.Can anyone shed light on this?
[code]
– Main function - MUST return a display.newGroup()
function new()
local localGroup = display.newGroup()
local nImages = 8
local range = 360
local sectionSize = range / nImages
local xCentre = display.contentWidth / 1.75
local yCentre = display.contentHeight / 1
local diameter = display.contentWidth - xCentre/2
local r = diameter / 1.75
local points = {}
local images = {}
local visual = display.newGroup()
local lastTime = system.getTimer()
local interval = 30
local yRotScale = 0.375
local yScale = 1.25
local xScale = 1.25
local depthCounter = 0
– Just a visual cue
local pole
pole = display.newImage(“html.png”)
pole:setReferencePoint(display.CenterReferencePoint)
pole.x = display.contentWidth/3
pole.y = display.contentHeight/2.8
local function sort()
table.sort(images,
function(a, b)
return a.y < b.y
end
)
–
– Just re-insert. Removing firstly seems to destroy DisplayObjects,
– even if the return value from remove() is put into a table.
for i = 1, #images do
visual:insert(images[i])
if i == math.floor(nImages/2) then
visual:insert(pole)
end
end
end
local function rotate()
for i = 1, #images do
local img = images[i]
local cntr = img.counter
local xy = points[cntr]
img.width = img.origWidth
img.height = img.origHeight
img.x = xy[1]
img.y = xy[2] * yRotScale
local s = xy[2] / (yCentre + r)
img.xScale = s * xScale
img.yScale = s * yScale
cntr = cntr + 1
if cntr > range then
cntr = 1
end
images[i].counter = cntr
end
end
– Defaults to first-in, furthest-back. Reverse i for opposite:
local counter = 1
for i = 1, nImages do
local img = display.newGroup()
local imageone = display.newImage(“violet.png”)
img:insert(imageone)
---------------------------------------------------------------------Started to place my images here
local img = display.newGroup()
local imagetwo = display.newImage(“jb.png”)
img:insert(imagetwo)
----------------------------------------------------------------------But only one will show
img.counter = counter
img.origWidth = img.width
img.origHeight = img.height
images[#images + 1] = img
counter = counter + sectionSize – placement in pairs array
end
for i = 1, range do
local x = r * math.cos(math.rad(i))
local y = r * math.sin(math.rad(i))
points[#points + 1] = {x + xCentre, y + yCentre}
end
sort()
–
– Depending on layout (number of images), may need to call this
– after a few beats in case image is about to overlap at start.
rotate()
local function onFrame(event)
local curTime = system.getTimer()
if curTime - lastTime >= interval then
rotate()
lastTime = curTime
end
– Don’t sort every frame.
– sectionSize is granularity of sorting.
if depthCounter % sectionSize == 0 then
sort()
end
depthCounter = depthCounter + 1
end
Runtime:addEventListener(“enterFrame”, onFrame)
local function onTouch(self, event)
if event.phase == “began” then
self.startX = event.x
self.startY= event.y
display.getCurrentStage():setFocus(self)
elseif event.phase == “moved” then
local movedX = event.x - self.startX
local movedY = event.y - self.startY
print(movedX, movedY)
self.x = self.x + movedX
self.y = self.y + movedY
self.startX = event.x
self.startY = event.y
elseif event.phase == “ended” then
display.getCurrentStage():setFocus(nil)
end
end
visual.touch = onTouch
visual:addEventListener(“touch”, visual)
[/code] [import]uid: 88495 topic_id: 30730 reply_id: 330730[/import]