I have an animation of an elevator opening when I push a button. The original image is too large for where its supposed to be in the background so I set width and height on the sprite. Problem is, whenever I start the animation the sprite resets to its original image.
Even if I set width and height after calling animation:play() only the first frame is the size I wanted, from the next frame and onwards all frames are again reset to its original size! Is this intended behaviour? Why is it happening?
I know I could just resize the original image but I’d like to be able to control this in code if possible for experimentation.
local sheetData = { width=449, height=925, numFrames=3, sheetContentWidth=1347, sheetContentHeight=925 } local mySheet = graphics.newImageSheet("images/elevator.png", sheetData) local sequenceData = { { name = "open", start=1, count=3, time=800 }, } local animation = display.newSprite(mySheet, sequenceData) animation.x = 100 animation.y = 0 common.room:addObject(1, animation) local elevatorButtonTrigger = display.newRect(-240, 0, 50, 100) elevatorButtonTrigger.alpha = 0.2 elevatorButtonTrigger:setFillColor(0) elevatorButtonTrigger.isHitTestable = true elevatorButtonTrigger.tap = function() if animation.isPlaying then animation:pause() else animation:play() animation.width = 100--animation.width / 2048 \* 480 animation.height = 100--animation.height / 1536 \* 360 end end elevatorButtonTrigger:addEventListener("tap", elevatorButtonTrigger)