Hi guys,
i would like to do this:
i want 5 balls in various colors to circle around the center of the screen in a random speed,how cam i do this.
thanks in advance
[import]uid: 83418 topic_id: 22114 reply_id: 322114[/import]
Hi guys,
i would like to do this:
i want 5 balls in various colors to circle around the center of the screen in a random speed,how cam i do this.
thanks in advance
[import]uid: 83418 topic_id: 22114 reply_id: 322114[/import]
the formula for that would be
[lua]object.x = radius * math.cos( angle ) + originX
object.y = radius * math.sin( angle ) + originY[/lua]
on every frame you should change the angle value, the amount of angle you add will determine the speed, and origin is the point where you want your object to revolve around,
run the code below to see an example
[lua]local _W2 = display.contentWidth * 0.5
local _H2 = display.contentHeight * 0.5
local mRand = math.random
local mSin = math.sin
local mCos = math.cos
local obj = {}
local radius = {}
local angle = {}
local speed = {}
for i = 1, 5 do
obj[i] = display.newCircle( _W2, _H2, 30 - ( 3 * i ) )
obj[i]:setFillColor( mRand( 255 ), mRand( 255 ), mRand( 255 ))
radius[i] = ( 1 - i ) * 30
angle[i] = 0
speed[i] = ( 1 - i ) * ( mRand( 10 ) * 0.01 )
end
function enterFrame( )
for i = 1, 5 do
angle[i] = angle[i] + speed[i]
obj[i].x = radius[i] * mCos( angle[i] ) + _W2
obj[i].y = radius[i] * mSin( angle[i] ) + _H2
end
end
Runtime:addEventListener( “enterFrame”, enterFrame )[/lua] [import]uid: 114118 topic_id: 22114 reply_id: 87923[/import]
Hi xplatgaming,
Works Great, thank you so much…
[import]uid: 83418 topic_id: 22114 reply_id: 87970[/import]