0

私はこのコードを持っています。この例では、Graphic:setAnchorPoint と Graphic:setRotation で「Graphic」を「self」に置き換えると、画像は画面に表示されますが、回転しません。理由は何ですか?

私は Gideros を初めて使用し、クラスを作成する際に行う必要がある変更を完全には理解していません。短い簡単な説明が本当に必要ですか?

私はGiderosでLuaを使用しています

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)
4

1 に答える 1

1

あなたの場合GraphicBitmap操作したいインスタンスですが、 self はあなたがいるクラスのインスタンスを参照していますが、あなたの場合はWatchHands

Graphic を回転すると、Graphic のみが回転しますが、WatchHands を回転すると、Graphic を含むすべての子が回転するはずです。

print("Angle:", self:getRotation())自分自身の角度が実際に増加しているかどうか、またはコードに他のエラーがあるかどうかを確認するように、ENTER_FRAME イベントに印刷を入れることができます。

于 2014-05-14T08:43:56.377 に答える