Help on sprites -- Make it work on storyboard

On June 28 at 1:40 – 43 views and still no solution for the sprite problem

I know that there is a way to fix it, thanks for all your help, to all of you out there…

On June 26 at 4:24 – 34 Views and 0 reply –

Maybe it’s a difficult topic, I will find the answer…some day

Well, maybe nobody knows this answer

28 views and nothing – 0 reply – on June 26 at 10:28 am

So far 21 views – 0 reply – on June 25, at 11:41 am

let me know if I put too much, maybe you want 1 question at a time

I’m trying to make the sprite work on my storyboard. The sprite is the one on Corona sample, the one with the cat and the green dude.

The problem it’s that the code works in one view, main.lua, but I’m trying to find the logic to make it work on storyboard, and I’m going crazy, please I need some help.

************************************* ONE************************************

it has a table

-- a bunch of foliage local tree = {} tree[1] = display.newImage( "a2.png" ) tree[1].xScale = 0.8; tree[1].yScale = 0.8 tree[1]:setReferencePoint( display.BottomCenterReferencePoint ) tree[1].x = 20; tree[1].y = baseline tree[1].dx = 0.1 tree[2] = display.newImage( "a3.png" ) tree[2].xScale = 0.6; tree[2].yScale = 0.6 tree[2]:setReferencePoint( display.BottomCenterReferencePoint ) tree[2].x = 120; tree[2].y = baseline tree[2].dx = 0.2

with many trees, where do I create the table,

in the createScene, or the enterScene? and how do I remove the table when I leave the scene?

in the exitScene, or the destroyScene?

Does it need a special code to remove the table, like the remove on exitScene

display.remove(spider1)

or the button one in destroyScene

if buttonBack then             buttonBack:removeSelf()             buttonBack = nil         end

************************************* 2************************************

The background I think I know how to do that.

Then is the actual sprite sheet

-- an image sheet with a cat local sheet1 = graphics.newImageSheet( "a10.png", { width=512, height=256, numFrames=8 } ) -- play 8 frames every 1000 ms local instance1 = display.newSprite( sheet1, { name="cat", start=1, count=8, time=1000 } ) instance1.x = display.contentWidth / 4 + 40 instance1.y = baseline - 75 instance1.xScale = .5 instance1.yScale = .5 instance1:play()

I guess the image sheet I have to insert that in to the group of the scene. is that correct?

local sheet1 = graphics.newImageSheet( "a10.png", { width=512, height=256, numFrames=8 } ) group:insert ( sheet1 )

and the actual sprite sheet, do I treat  like a .png file

local instance1 = display.newSprite( sheet1, { name="cat", start=1, count=8, time=1000 } ) group:insert ( instance1 )

Is it like that or is there another way?, to create it and to remove it.

*********************************3***************

Then we have the grass movement, do I do that in what scene, and how do I

remove it later

-- Grass -- This is doubled so we can slide it -- When one of the grass images slides offscreen, we move it all the way to the right of the next one. local grass = display.newImage( "a13.png" ) grass:setReferencePoint( display.CenterLeftReferencePoint ) grass.x = 0 grass.y = baseline - 20 local grass2 = display.newImage( "a13.png" ) grass2:setReferencePoint( display.CenterLeftReferencePoint ) grass2.x = 480 grass2.y = baseline - 20

same with the rec for the baseline

-- solid ground, doesn't need to move local ground = display.newRect( 0, baseline, 480, 90 ) ground:setFillColor( 0x31, 0x5a, 0x18 )

*************************4***************************

The we have the actual function that makes everything works

-- A per-frame event to move the elements local tPrevious = system.getTimer() local function move(event) &nbsp;&nbsp; &nbsp;local tDelta = event.time - tPrevious &nbsp;&nbsp; &nbsp;tPrevious = event.time &nbsp;&nbsp; &nbsp;local xOffset = ( 0.2 \* tDelta ) &nbsp;&nbsp; &nbsp;grass.x = grass.x - xOffset &nbsp;&nbsp; &nbsp;grass2.x = grass2.x - xOffset &nbsp;&nbsp; &nbsp; &nbsp;&nbsp; &nbsp;if (grass.x + grass.contentWidth) \< 0 then &nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;grass:translate( 480 \* 2, 0) &nbsp;&nbsp; &nbsp;end &nbsp;&nbsp; &nbsp;if (grass2.x + grass2.contentWidth) \< 0 then &nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;grass2:translate( 480 \* 2, 0) &nbsp;&nbsp; &nbsp;end &nbsp;&nbsp; &nbsp; &nbsp;&nbsp; &nbsp;local i &nbsp;&nbsp; &nbsp;for i = 1, #tree, 1 do &nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;tree[i].x = tree[i].x - tree[i].dx \* tDelta \* 0.2 &nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;if (tree[i].x + tree[i].contentWidth) \< 0 then &nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;tree[i]:translate( 480 + tree[i].contentWidth \* 2, 0 ) &nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;end &nbsp;&nbsp; &nbsp;end end -- Start everything moving Runtime:addEventListener( "enterFrame", move );

I guess I have to put that function first on top of the file, before all the create scenes functions?

but where do I put the

-- Start everything moving Runtime:addEventListener( "enterFrame", move );

at the end, - after or before the

scene:addEventListener( "createScene", scene ) scene:addEventListener( "destroyScene", scene ) return scene

*********************5**********************

I want to have a button that makes the sprite move

I guess I create a button normally, and use – onRelease

to call the function – move(event)

to actually start the animation.

In the sample as soon as you load the app, the cat is running

I want the cat to run when people push the button.

And how do you stop the animation, or the sprite

in the sample, is running forever, never stops.

**********************6**********************

Sorry for so many questions, but I guess I want to make this work

and I have no clue, where to find all these answers, instead of asking

one at a time and back an forth, I hope I can get all the answers to’

actually make a sprite work in storyboard.

Thanks for your help.

PS. - This is for my second app, the first one is already on the app store

thanks to all of you, thank you a lot.

Victor