Hi guys!!!!!
Again with this tiny problem that I can't solve.
I have a sprite.sheet, after this sprite runs, I want to run other sprite, and so on. How I build the function-timing on they should appear?.
This is the code
(I want to run sprite II right after the sprite I ends.)
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 | --sprite I local sheet1 = sprite.newSpriteSheet( "image1.jpg", 250, 400 ) local spriteSet1 = sprite.newSpriteSet(sheet1, 1, 8) sprite.add( spriteSet1, "A", 1, 6, 170, 7 ) local instance1 = sprite.newSprite( spriteSet1 ) instance1.x = display.contentWidth / 4 + 16 instance1.y = baseline - 75 instance1.xScale = .5 instance1.yScale = .5 instance1:prepare("A") instance1:play() -- sprite II local sheet1 = sprite.newSpriteSheet( "image2.jpg", 250, 400 ) local spriteSet1 = sprite.newSpriteSet(sheet1, 1, 8) sprite.add( spriteSet1, "B", 2, 6, 2000, 1 ) local instance1 = sprite.newSprite( spriteSet1 ) instance1.x = display.contentWidth / 4 + 16 instance1.y = baseline - 75 instance1.xScale = .5 instance1.yScale = .5 instance1:prepare("B") instance1:play() |
That one is easy. Before you call instance1:play()
do this:
instance1:addEventListener( "sprite", nextSprite )
Up above that you will need a function
1 2 3 4 5 6 7 | local function nextSprite(event) -- assuming you don't want this to repeat itself -- instanc1:removeEventListener("sprite") instance1:prepare("B") instance1:play() return true end |
Hi Rob!, thanks for response.
I must be doing something wrong, because the code doesn't work.
I let you here the code to see what is missing.
Please take a look.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 | --BLOCK I local sheet1 = sprite.newSpriteSheet( "image1.jpg", 250, 400 ) local spriteSet1 = sprite.newSpriteSet(sheet1, 1, 8) sprite.add( spriteSet1, "A", 1, 6, 170, 7 ) local instance1 = sprite.newSprite( spriteSet1 ) instance1.x = display.contentWidth / 4 + 16 instance1.y = baseline - 75 instance1.xScale = .5 instance1.yScale = .5 instance1:prepare("A") instance1:play() local function nextSprite(event) -- assuming you don't want this to repeat itself -- instanc1:removeEventListener("sprite") instance1:prepare("B") instance1:play() return true end instance1:addEventListener( "sprite", nextSprite ) -- BLOCK II local sheet2 = sprite.newSpriteSheet( "image2.jpg", 250, 400 ) local spriteSet2 = sprite.newSpriteSet(sheet2, 1, 8) sprite.add( spriteSet2, "B", 2, 6, 2000, 1 ) local instance2 = sprite.newSprite( spriteSet2 ) instance2.x = display.contentWidth / 4 + 16 instance2.y = baseline - 75 instance2.xScale = .5 instance2.yScale = .5 instance2:prepare("B") instance2:play() |
Try this:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 | --BLOCK I local sheet1 = sprite.newSpriteSheet( "image1.jpg", 250, 400 ) local spriteSet1 = sprite.newSpriteSet(sheet1, 1, 8) sprite.add( spriteSet1, "A", 1, 6, 170, 7 ) local instance1 = sprite.newSprite( spriteSet1 ) instance1.x = display.contentWidth / 4 + 16 instance1.y = baseline - 75 instance1.xScale = .5 instance1.yScale = .5 -- BLOCK II local sheet2 = sprite.newSpriteSheet( "image2.jpg", 250, 400 ) local spriteSet2 = sprite.newSpriteSet(sheet2, 1, 8) sprite.add( spriteSet2, "B", 2, 6, 2000, 1 ) local instance2 = sprite.newSprite( spriteSet2 ) instance2.x = display.contentWidth / 4 + 16 instance2.y = baseline - 75 instance2.xScale = .5 instance2.yScale = .5 local function nextSprite(event) -- assuming you don't want this to repeat itself instanc1:removeEventListener("sprite") instance2:prepare("B") instance2:play() return true end instance1:addEventListener( "sprite", nextSprite ) instance1:prepare("A") instance1:play() |
I tried, but it doesn't work
we are still missing something.
Now I understand what you did, it looks ok, but the code is not working.
either way, thanks a lot
send message and call to a person
Forum: Report Spam + PM
[INSTALL_PARSE_FAILED_NO_CERTIFICATES]
[SOLVED] Director ERROR: Failed to execute new( params ) function on 'screen1'
Too many (200) local variables
Corona SVG Level Builder released. Drag and drop physics level editor with Inkscape and SVG.
Small bug in Collectible Items example
Pivot Joints and apparent elasticity
Can't make removeSelf() delayed
Developing first game, should I test on device during development?
Build works on iPhone but fails to install on iPad
IndeED Release #3 is available
Plants vs. Zombies Tutorial
Does anyone know about font license?
Performance in Image loading
Porting from Appcelerator to Corona
New Builds and Old Builds
Storyboard API Questions