Hello,
So, I need to play a sprite when the app starts, but from a frame different than 1. (ex. the 30th frame)
I tried using Object:setFrame(30) and Object:play(), but it doesn’t work, the sprite goes to the frame 30
but doesn´t play it (Tried many frame numbers and only with 1 it plays).
This is the code:
-- LOAD THE SPRITE-SHEET local sheetInfo = require("img") -- from texture packager local mySheet = graphics.newImageSheet( "img.png", sheetInfo:getSheet() ) local mySprite = { name="mySprite", start=1, count=131, time=1000, loopDirection = "bounce" } -- CREATE OBJECT local myObject = display.newSprite( mySheet, mySprite ) myObject.x = display.contentCenterX myObject.y = 400 myObject:setFrame(30) myObject:play()
By using try and error I found that It plays when I call it from a listener, but I have to tap something to play it, and I need it to play when the app starts.
-- LOAD THE SPRITE-SHEET local sheetInfo = require("img") -- from texture packager local mySheet = graphics.newImageSheet( "img.png", sheetInfo:getSheet() ) local mySprite = { name="mySprite", start=1, count=131, time=1000, loopDirection = "bounce" } -- CREATE OBJECT local myObject = display.newSprite( mySheet, mySprite ) myObject.x = display.contentCenterX myObject.y = 400 local function playSprite() myObject:setFrame(30) myObject:play() end myObject:addEventListener("tap", playSprite)
If I only put playSprite() in the end to start the function it doesn’t play neither.
Can someone help?