local cannon = display.newImage("cannon.png") local number = 1 local knife = display.newImage("knife.png") local knifex = 250 local knifey = 425 local knifexs = 0.1 local knifeys = 0.1 local balloonx = 50 local balloony = 300 local radnum = 100 local mathlib = require ("mathlib") knife.x = knifex knife.y = knifey knife.xScale = knifexs knife.yScale = knifeys knife.rotation = 250 --knife:toBack() knife:toFront() cannon.xScale = 0.2 cannon.yScale = 0.2 cannon.x = 250 cannon.y = 425 local rotate = function (event) if event.y \< 420 and event.y \> 340 then rotate1 = (event.y / number) cannon.rotation = rotate1 knife.rotation = rotate1 + 250 --print(rotate1) print(event.x,event.y) end end Runtime:addEventListener("touch", rotate) local rotate1 = cannon.rotation local physics = require "physics" physics.start() local balloon = display.newImage("balloon.png") balloon.x = balloonx balloon.y = balloony balloon.xScale = 0.2 balloon.yScale = 0.2 physics.addBody(balloon, "static") --local rotate2 = (event.y / number) --local angle = rotate2 -341 --local angle1 = angle / 180 --local radian = angle1 / math.pi --local rad = math.sin(radian) --local shootpos = rad \* 100 --print (rad) local throw = function(event) radian = math.rad(rotate2) rad = math.sin(radian) shoot = rad \* radnum print (rad) if event.phase == "press" then transition.to(knife,{time = 1000,x=-25,y = shoot, rotation = 720}) end end Runtime:addEventListener("touch", throw) local remove = function() knife:removeSelf() knife=nil if knife == nil then print ("knife removed!") end end local ui = require "ui" local firebtn = ui.newButton{ defaultSrc = "button.png", defaultX = 100 , defaultY = 100 , overSrc = "button.png", overX = 100, overY = 100, onEvent = throw, } firebtn.x = 20 firebtn.y = 450
my new code