bml
bml

Reputation: 23

Using Corona SDK and trying to replace one line of code

I'm trying to replace a single line of code with another line in the same place but not sure where to put the (i-1) part back in...

In the actual code this tip is commented out below -- in a real app you would use a smooth dot image, circles at this size look pixellated. I've already created the smooth dot image to use ("images/slidedot.png").

Here are the original code lines:

for i=1, pageTotal do
    local dot = display.newCircle((i-1)*50, 0, 5)
    dotGroup:insert(dot)
    pageDots[i]=dot
end

I'm trying to replace display.newCircle((i-1)*50, 0, 5) with display.newImageRect ( "images/slidedot.png", 10, 10) at the line that starts as local dot =.

I'm just not sure where to put the (i-1) part back in...

So the final line should look like this: local dot = display.newImageRect ( "images/slidedot.png", 10, 10) with (i-1) somewhere.

Upvotes: 1

Views: 48

Answers (1)

ryanpattison
ryanpattison

Reputation: 6251

display.newCircle((i-1)*50, 0, 5)

That line creates a circle with radius 5 centred at (i-1) * 50, 0. ImageRect takes the width and the height as arguments, for the same size circle they are twice the radius (10). To set the centre point of the rectangle we can change the reference point to be the centre, and then set the x and y values to be the same as before.

local dot = display.newImageRect("images/sliderdot.png", 10, 10)
dot:setReferencePoint(display.CenterReferencePoint)
dot.x = (i - 1) * 50
dot.y = 0

Upvotes: 1

Related Questions