It looks like you're new here. If you want to get involved, click one of these buttons!
local block1Texture = Texture.new("block1.png",true) local block1 = Bitmap.new(block1Texture) block1:setAnchorPoint(0.5,0.5) stage:addChild(block1) block1:setPosition(50,50) local block2Texture = Texture.new("block2.png",true) local block2 = Bitmap.new(block2Texture) block2:setAnchorPoint(0.5,0.5) stage:addChild(block2) block2:setPosition(350,450) local block3Texture = Texture.new("block3.png",true) local block3 = Bitmap.new(block3Texture) block3:setAnchorPoint(0.5,0.5) stage:addChild(block3) block3:setPosition(300,700) local timer = Timer.new(500, 1) local rotateAroundBlock = block2 function getCharAngleFromRope(startX, startY, targetX, targetY) local xdiff = targetX - startX local ydiff = targetY - startY local ang = math.atan2( ydiff, xdiff ) ang = math.deg(ang) + 90.0 if ang < 0 then ang = 360.0 + ang end return ang end local dx = application:getLogicalTranslateX() / application:getLogicalScaleX() local dy = application:getLogicalTranslateY() / application:getLogicalScaleY() local function onTimerComplete(event) timer:reset() timer:start() if(rotateAroundBlock==block1) then angle = angle - 0.1 else angle = angle + 0.1 end local px = rotateAroundBlock:getX() + dist*math.cos(angle) local py = rotateAroundBlock:getY() + dist*math.sin(angle) if(px<=0 or px>=application:getDeviceWidth()) then --print("1") --px = block3:getX() end if(py<=0 or py>=application:getContentHeight()) then --print("2") --py = block3:getY() --px = block3:getX() end block3:setPosition(px,py) end dist = math.sqrt((rotateAroundBlock:getX()-block3:getX())^2+(rotateAroundBlock:getY()-block3:getY())^2) angle = getCharAngleFromRope(block3:getX(),block3:getY(),rotateAroundBlock:getX(),rotateAroundBlock:getY()) timer:addEventListener(Event.TIMER_COMPLETE, onTimerComplete) function startMoving() timer:start() end stage:addEventListener(Event.TOUCHES_BEGIN, startMoving) |