我有这段代码。在此示例中,如果我在 Graphic:setAnchorPoint 和 Graphic:setRotation 处将 'Graphic' 替换为 'self',则图像会出现在屏幕上但不会旋转。是什么原因?
我对 Gideros 还很陌生,并不完全理解创建课程时需要进行的更改。真的需要简短的快速解释,好吗?
我正在使用 Lua 和 Gideros
WatchHands= Core.class(Sprite)
W, H = application:getDeviceWidth(), application:getDeviceHeight()
H, W = W, H
ori = Application.LANDSCAPE_LEFT
application:setOrientation(ori)
function WatchHands:init(Image, posx, posy)
posx = posx or 0
posy = posy or 0
Graphic = Bitmap.new(Texture.new(Image))
Graphic: setAnchorPoint(0.2257, 0.5)
self:addChild(Graphic)
self: setPosition( posx, posy)
self.width = self: getWidth()
self.height = self: getHeight()
self: setScale(0.5, 1)
Graphic:setRotation(math.random( 1,360))
self:addEventListener(Event.ADDED_TO_STAGE, self.onAddedToStage, self)
return self
end
function WatchHands: playsound(sound)
local channel = sound:play()
return channel
end
function WatchHands: onAddedToStage()
self:addEventListener(Event.ENTER_FRAME,
function()
self:setRotation( Graphic:getRotation() + 5)
Timer.delayedCall(math.random(30000, 60000),
function()
self:setRotation( self:getRotation() + math.random(6,10) )
end)
end)
end
sechand = WatchHands.new("secondshand.png", W/2, H/2)
minhand = WatchHands.new("minutehand.png", W/2, H/2)
stage: addChild(sechand)
stage: addChild(minhand)