Hi everyone…
I have a sprite that is moving everywhere…by the way
I don’t know if this is the best way, but it works
sequenceFish = { { name="fishy", start=1, count=6, time=800 } -- loopDirection = "bounce" } fishSheet = graphics.newImageSheet( "images/spriteFish.png", { width=200, height=105, numFrames=6 } ) local function swimming() if fishSprite then fishSprite:removeSelf() fishSprite = nil end --(math.random(-50, 50)) fishSprite = display.newSprite( fishSheet, sequenceFish ) sceneGroup:insert(fishSprite) fishSprite.x = display.contentCenterX - 300 fishSprite.y = display.contentCenterY + (math.random(-150, 150)) fishSprite.xScale = .4 fishSprite.yScale = .4 fishSprite.alpha = .3 fishSprite.rotation = 0 fishSprite:play() local function backFish() fishSprite.rotation = 180 transition.to(fishSprite, {time=9000, x=display.contentCenterX - 300, onComplete=swimming}) end transition.to(fishSprite, {time=9000, x=display.contentWidth + (math.random(-150, 150)), y=display.contentCenterY + (math.random(-150, 150)), onComplete=backFish}) end swimming()
– QUESTION –
when I go to another scene in composer
After a few seconds, I guess when the transition is complete
I get the error
File: mapa.lua
Line: 67
Attempt to index upvalue ‘fishSprite’ (a nil value)
I don’t find the sprite in the other scene …
so in the “hide” scene I am trying this but still is not working
if fishSprite then fishSprite:pause() fishSprite:removeSelf() fishSprite = nil end
Thanks for your help
---- Bonus Question For Challenging Programmers—
If you look at the code, the fish is traveling from point A to point B
in a straight line.
but the point of the fish is looking weird, because of the [rotation]
There is a way to detect if the math.random gets 98
then rotate like - 34 degerees
so automatically the fish follows the direction of the line
– I know, this is for VERY advanced programmers,
I just wanted to see if someone can actually do this