Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/lua/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/video/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
更改电晕/LUA对象的方向_Lua_Coronasdk_Corona Storyboard - Fatal编程技术网

更改电晕/LUA对象的方向

更改电晕/LUA对象的方向,lua,coronasdk,corona-storyboard,Lua,Coronasdk,Corona Storyboard,嗨,我的对象正在从右向左移动,如何将其更改为从上到下 function movebadc1(self,event) if self.x < -50 then self.x =300 self.y = 300 self.speed = math.random (2,6) self.initY = self.y self.amp = math.random (20,100) self

嗨,我的对象正在从右向左移动,如何将其更改为从上到下

function movebadc1(self,event)
        if self.x < -50 then
        self.x =300
        self.y = 300
        self.speed = math.random (2,6)
        self.initY = self.y
        self.amp = math.random (20,100)
        self.angle = math.random (1,360)

        else 
                self.x = self.x - self.speed
                self.angle = self.angle + .1
                self.y = self.amp * math.sin(self.angle)+self.initY
        end
end
函数movebadc1(自身,事件)
如果self.x<-50,则
self.x=300
self.y=300
self.speed=math.random(2,6)
self.initY=self.y
self.amp=math.random(20100)
self.angle=math.random(1360)
其他的
self.x=self.x-self.speed
自转角=自转角+0.1
self.y=self.amp*math.sin(self.angle)+self.initY
结束
结束

考虑到Kevin要从右到左,从上到下进行更改,假设您也希望其他行为保持不变,请更改以下三行:

            self.x = self.x - self.speed
            self.angle = self.angle + .1
            self.y = self.amp * math.sin(self.angle)+self.initY


也可以使用Cos()代替sin()。希望它能起作用。

首先,你用的是度而不是弧度。尝试:self.angle=math.random()*math.pi*2以获取以弧度为单位的角度。弧度和度一样描述角度,但不是从0到360,而是从0到2π(~6.28)。唯一的区别是,可以在三角法中使用弧度。
            self.y = self.y + self.speed
            self.angle = self.angle + .1
            self.x = self.amp * math.sin(self.angle)+self.initX