Quick Links: Download Gideros Studio | Gideros Documentation | Gideros Development Center | Gideros community chat | DONATE
move a sprite in a circular movement — Gideros Forum

move a sprite in a circular movement

a00zaa00za Member
edited February 2013 in General questions
i am trying to move a sprite in a circular movement but all i get information is about rotation or using the Gtween.
To explain more it is like the moon it moves circular around the earth..... that the movement i try to code but with no effort.

Comments

  • evsevs Member
    Accepted Answer
    Hello,

    Here's what I use (project attached)
    application:setBackgroundColor(0x000000)
     
    local logo = Bitmap.new(Texture.new("Gideros.png"))
     
    logo:setScale(0.5, 0.5) --scale image down to 64 * 64
    logo:setAnchorPoint(0.5, 0.5) -- nchor at center
     
    local centerX = application:getContentWidth() / 2 --center of screen x
    local centerY = application:getContentHeight() / 2 --center of screen y
    local rotationRadius = 160 --radius to rotate around
    local radius = rotationRadius - logo:getWidth() / 2 --radius = rotation radius minus bitmap radius
    local speed = 4 / rotationRadius --speed relative to the rotation radius
    local angle = 0 --initial angle
    local posX = centerX + radius --x position
    local posY = centerY --y position
     
    logo:setPosition(posX, posY); 
     
    stage:addChild(logo)
     
    function update()
     
    	angle = angle + speed
    	posX = centerX + radius * math.cos(angle)
    	posY = centerY + radius * -math.sin(angle)
    	logo:setPosition(posX, posY)
     
    end
     
    stage:addEventListener(Event.ENTER_FRAME, update)
    cheers

    evs
    zip
    zip
    Circular.zip
    12K
    +1 -1 (+3 / -0 )Share on Facebook
  • @evs thank you soo much it worked
  • There are some useful notes on programming movement (including various types of circular motion) in "ActionScript 3 - A Beginner's Guide". Circular Motion is on P122 - you can preview it on Google Books.

    http://books.google.co.uk/books?id=-LEW5C1jnuMC&q=122#v=snippet&q=122&f=false
  • a00zaa00za Member
    @BJG thanx for the care
  • jdbcjdbc Member
    edited January 2014
    Just use Movie.clip and rotation:
    local sphere = Bitmap.new(Texture.new("image.png"))
    local animation=MovieClip.new{{1, 500, sphere,{rotation={0,360,"linear"}}}}
    animation:setGotoAction(500,1)
    sphere:setPosition(180,160)
    self:addChild(sphere)
    self:addChild(animation)
    animation:play()
Sign In or Register to comment.