Help on sprites

Hi Rob, Hi Brent, I really need your help, I’m going crazy.

I have more than a week with sprites, trying to make them work on storyboard.

I read a lot on Corona, and finally I got them to work more or less, but something funny

is happening, and I don’t understand why.

One button on createScene

buttonGun = widget.newButton{     defaultFile="buttonGun.png",     onRelease = buttonGunHandler     }     group:insert ( buttonGun )     buttonGun.x = 200; buttonGun.y = 550

plays this function on top of my file – an explosion sprite

local function buttonGunHandler()         audio.play(sfx4, { channel=1 } )                  local gunGraphics = graphics.newImageSheet("flames\_05.png", {width=128, height=128, numFrames=30})         gunSprite = display.newSprite(gunGraphics, { name="sp", start=1, count=30, time=1000, loopCount = 1 } )         gunSprite.x = 322; gunSprite.y = 505         gunSprite.xScale = .9; gunSprite.yScale = .9         gunSprite:play()         --gunSprite:pause()     return true end

The first time plays perfect. when I go to another scene works fine, – I have this on destroyScene

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

------------PROBLEM---------------

But if I touch the button two or more times, the program keeps adding the graphic

and the explosion looks more red every time, and when I go to another scene

the explosion graphic from the sprite it’s not removing itself.

This is the complete code

local storyboard = require( "storyboard" ) local widget = require "widget" local scene = storyboard.newScene() local buttonHome local buttonBack local buttonGun local buttonDynamite local fireSprite local fireSprite2 local dynamiteSprite local gunSprite local sfx1 = audio.loadSound( "sfxExplosion1.mp3") local sfx2 = audio.loadSound( "sfxExplosion2.mp3") local sfx3 = audio.loadSound( "sfxFire1.mp3") local sfx4 = audio.loadSound( "sfxGunsShot1.mp3") local function buttonHomeHandler()         storyboard.gotoScene( "mainMenu", "zoomInOutFade", 200 )         return true end local function buttonBackHandler()         storyboard.gotoScene( "more", "fromLeft", 200 )         return true end local function buttonGunHandler()         audio.play(sfx4, { channel=1 } )                  local gunGraphics = graphics.newImageSheet("flames\_05.png", {width=128, height=128, numFrames=30})         gunSprite = display.newSprite(gunGraphics, { name="sp", start=1, count=30, time=1000, loopCount = 1 } )         gunSprite.x = 322; gunSprite.y = 505         gunSprite.xScale = .9; gunSprite.yScale = .9         gunSprite:play()         --gunSprite:pause()     return true end local function buttonDynamiteHandler()         audio.play(sfx1, { channel=2 } )                  local dynamiteGraphics = graphics.newImageSheet("flames\_01.png", {width=128, height=128, numFrames=30})         dynamiteSprite = display.newSprite(dynamiteGraphics, { name="dynamite", start=1, count=30, time=1000, loopCount = 1 } )         dynamiteSprite.x = 512; dynamiteSprite.y = 200         dynamiteSprite.xScale = .9; dynamiteSprite.yScale = .9         dynamiteSprite:play()         --dynamiteSprite:pause()     return true end -- --==\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*[CREATE SCENE]\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*++-- -- function scene:createScene( event )     local group = self.view         local background = display.newImage( "spritesSample.png" )     group:insert ( background )               buttonHome = widget.newButton{     defaultFile="buttonHome.png",     onRelease = buttonHomeHandler     }     group:insert ( buttonHome )     buttonHome.x = 910     buttonHome.y = 710          buttonBack = widget.newButton{     defaultFile="buttonBack.png",     onRelease = buttonBackHandler     }     group:insert ( buttonBack )     buttonBack.x = 100     buttonBack.y = 710          buttonGun = widget.newButton{     defaultFile="buttonGun.png",     onRelease = buttonGunHandler     }     group:insert ( buttonGun )     buttonGun.x = 200; buttonGun.y = 550          buttonDynamite = widget.newButton{     defaultFile="buttonDynamite.png",     onRelease = buttonDynamiteHandler     }     group:insert ( buttonDynamite )     buttonDynamite.x = 300; buttonDynamite.y = 200 end --------------------------------------------------------------ENTER SCENE---------- function scene:enterScene( event )     local group = self.view              audio.play(sfx3, { channel=3, loops=-1, fadein=1000 } )              fireSprite = graphics.newImageSheet("flames\_04.png", {width=128, height=128, numFrames=30})         fireSprite = display.newSprite(fireSprite, { name="fire", start=1, count=30, time=1000 } )         fireSprite.x = 880; fireSprite.y = 400         fireSprite.xScale = 1.5; fireSprite.yScale = 1.5         fireSprite:play()                  fireSprite2 = graphics.newImageSheet("flames\_04.png", {width=128, height=128, numFrames=30})         fireSprite2 = display.newSprite(fireSprite2, { name="fire2", start=1, count=30, time=1000 } )         fireSprite2.x = 840; fireSprite2.y = 445         fireSprite2.xScale = 1.3; fireSprite.yScale = 1.3         fireSprite2:play()      end -------------------------------------------------------------------------------------- --------------------------------------------------------------EXIT SCENE---------- function scene:exitScene()          audio.stop (  )           end -------------------------------------------------------------------------------------- -- --==\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*[DESTROY SCENE]\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*++-- -- function scene:destroyScene( event )     local group = self.view             if buttonHome then             buttonHome:removeSelf()             buttonHome = nil         end                  if buttonBack then             buttonBack:removeSelf()             buttonBack = nil         end                  if buttonGun then             buttonGun:removeSelf()             buttonGun = nil         end                  if buttonDynamite then             buttonDynamite:removeSelf()             buttonDynamite = nil         end                  if fireSprite then             fireSprite:removeSelf()             fireSprite = nil         end                  if fireSprite2 then             fireSprite2:removeSelf()             fireSprite2 = nil         end                  if dynamiteSprite then             dynamiteSprite:removeSelf()             dynamiteSprite = nil         end                  if gunSprite then             gunSprite:removeSelf()             gunSprite = nil         end                        end ---------------------------------------------------------------------------------- scene:addEventListener( "createScene", scene ) scene:addEventListener( "enterScene", scene ) scene:addEventListener( "exitScene", scene ) scene:addEventListener( "destroyScene", scene ) return scene

Please help me out

Thnaks

Victor

I found this here

http://www.coronalabs.com/blog/2012/10/02/animated-sprites-and-methods/

The sprite is now a display object , just like static images, vector objects, etc.  It can be moved, manipulated, linked to a physics body, and more.  To remove a sprite object, simply use object:removeSelf() or display.remove( object ). Don’t forget to set the reference to nil after removal!

I put it here

local function buttonDynamiteHandler()         display.remove( dynamiteSprite )         audio.play(sfx1, { channel=2 } )                  local dynamiteSprite = graphics.newImageSheet("flames\_01.png", {width=128, height=128, numFrames=30})         dynamiteSprite = display.newSprite(dynamiteSprite, { name="dynamite", start=1, count=30, time=1000, loopCount = 1 } )         dynamiteSprite.x = 512; dynamiteSprite.y = 200         dynamiteSprite.xScale = .9; dynamiteSprite.yScale = .9         dynamiteSprite:play()         --dynamiteSprite:pause()     return true end

and it doesn’t work…

I also used this one

local function buttonDynamiteHandler()         dynamiteSprite:removeSelf()         audio.play(sfx1, { channel=2 } )                  local dynamiteSprite = graphics.newImageSheet("flames\_01.png", {width=128, height=128, numFrames=30})         dynamiteSprite = display.newSprite(dynamiteSprite, { name="dynamite", start=1, count=30, time=1000, loopCount = 1 } )         dynamiteSprite.x = 512; dynamiteSprite.y = 200         dynamiteSprite.xScale = .9; dynamiteSprite.yScale = .9         dynamiteSprite:play()         --dynamiteSprite:pause()     return true end

And it givis me an error

Attempt to index upvalue ‘dynamiteSprite’ (a nil value)

I will keep reading and trying, please…

someone out there who knows how to do this, please help me out…

Victor

Hi Victor,

This is a simple naming error. You’ve named the image sheet the same as the sprite. Also, watch out for your scoping… you’re trying to remove “dynamiteSprite” before you create it.

Brent

Hi Brent,

I changed the name like this

local function buttonDynamiteHandler()         audio.play(sfx1, { channel=2 } )                  dynimateSheet = graphics.newImageSheet("flames\_01.png", {width=128, height=128, numFrames=30})                  dynamiteSprite = display.newSprite(dynimateSheet, { name="dynamite", start=1, count=30, time=1000, loopCount = 1 } )         dynamiteSprite.x = 512; dynamiteSprite.y = 200         dynamiteSprite.xScale = .9; dynamiteSprite.yScale = .9         dynamiteSprite:play()         --dynamiteSprite:pause()     return true end

and on the exitScene I did this

function scene:exitScene()          audio.stop (  )          display.remove( dynamiteSprite )     display.remove( gunSprite )           end

And still did not work, the second, the third and so forth images are still there, when I go to another scene.


I also tried to use the logic. If the “graphics.newImageSheet” is an image

I created a group to insert that image into the group and it will remove like this

local function buttonDynamiteHandler()     local group5 = self.view             audio.play(sfx1, { channel=2 } )                  local dynimateSheet = graphics.newImageSheet("flames\_01.png", {width=128, height=128, numFrames=30})         group5:insert ( dynimateSheet )                           dynamiteSprite = display.newSprite(dynimateSheet, { name="dynamite", start=1, count=30, time=1000, loopCount = 1 } )         dynamiteSprite.x = 512; dynamiteSprite.y = 200         dynamiteSprite.xScale = .9; dynamiteSprite.yScale = .9         dynamiteSprite:play()         --dynamiteSprite:pause()     return true end

But no luck! Error

File: …ormbarba/Desktop/How to make an app/spriteSample.lua
Line: 50

Attempt to index global ‘self’ (a nil value)

I’m trying…

Hi Victor,
Image sheets aren’t designed to be placed into groups. They’re just an internal source from which you pull frames. Those display objects go into the display group.

Brent

Thanks Brent,

But how do I solve the problem?

I was just trying things, How do I remove the images from a sprite?

Victor

Hi Victor,

You just remove sprite objects (not sheets) like any normal display object: “display.remove()” or “object:removeSelf()”, followed by “object = nil” to completely remove it from memory.

If you’re getting the error where it says “Attempt to index upvalue ‘dynamiteSprite’ (a nil value)”, that means you have probably created the sprite inside the wrong scope of Storyboard, and then in the exit scene block, you attempt to remove it (but Lua doesn’t know what that object is because you created it in another scope).

Brent

Hi Brent: Still not working.

–I change the name.

–I create the sprite object, outside all the scens (create,enter,exit,destroy), very first on top of the file.

local function buttonDynamiteHandler()             audio.play(sfx1, { channel=2 } )                  local dynimateSheet = graphics.newImageSheet("flames\_01.png", {width=128, height=128, numFrames=30})                  dynamiteSprite = display.newSprite(dynimateSheet, { name="dynamite", start=1, count=30, time=1000, loopCount = 1 } )         dynamiteSprite.x = 512; dynamiteSprite.y = 200         dynamiteSprite.xScale = .9; dynamiteSprite.yScale = .9         dynamiteSprite:play()         --dynamiteSprite:pause()     return true end

Then on createScene, I have a button that “calls” the “function buttonDynamiteHandler()”

buttonGun = widget.newButton{     defaultFile="buttonGun.png",     onRelease = buttonGunHandler     }     group:insert ( buttonGun )     buttonGun.x = 200; buttonGun.y = 550

And on the destroyScene I have the remove “if”

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

To me that makes logic, I got no errors, but the images from the sprite are still there when I go to another scene.

any idea?

Victor

Hi Victor,

Did you up-reference this as a local variable? Try declaring it above the “buttonDynamiteHandler” function, as in:

[lua]

local dynamiteSprite

[/lua]

Then, when you reach the exit scene (before you attempt to check the “if” it exists), try printing out the value and see what it shows:

[lua]

print( dynamiteSprite )

[/lua]

Hi Brent, It’s good that you mention the “Famous”

“print”

I see that, every half a second, in many places, and I still don’t really get it.

When I put “print”  I see nothing in the simulator.

I read that you need the “terminal” or the “console” or something, I don’t really get. How to open it

how to use it, how to see it, what should I look for, nothing…

Could you help me get to understand this “print” and “terminal” command. once and for all

in a more than dummies way, I mean like really super step by step…please?

Hi Victor,

The “print()” function is very, very useful. Many developers use it as a quick-and-dirty “debugging” method, to check the value of some variables at different points in the code. This helps ensure that the variable values are what you expect them to be… and if they’re not, you can usually use more print() statements to figure out why not.

print() will never show anything in the Corona Simulator. It only displays the text (that you printed) in the Terminal/console. If you aren’t running the Terminal/console alongside the Simulator, please read the following guide about how to set it up:

http://docs.coronalabs.com/guide/start/helloWorld/index.html

Brent

I open the terminal first – Then the simulator, that was the key…

I type this in the exitScene as you told me

function scene:exitScene()     audio.stop (  )     print( dynamiteSprite ) end

And the terminal has this

----------------------------------------terminal-------------

2013-07-02 10:43:50.490 Corona Simulator[8382:f03] nil


I hope this help you to help me solve this problem

Hello Victor,

I don’t know if this “solves” the problem, but the print() message you see means that “dynamiteSprite” is either:

  1. undefined/undeclared in the scope

  2. it has been declared but it has not been assigned any value

  3. you already cleared it or set it to nil before this point

Please check your code flow carefully again, and see why this is occurring.

Take care,

Brent

Hi Brent:

I bought the Jay Videos, that Corona has in their web site. $37.00, I think they are good, and I’m learning a few things from there, but I still have many other simple questions.

How much do you think it will cost me, for somebody, to tell me the answer to this question? The sprites problem.

If you know somebody that will be willing to actually tell me how to do that?

I have the sprite and it works, only the first time. After that the image is there always when I go to another scene.

this is the complete code, there is nothing else

-- --==\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*++-- -- -- How to make an app -- By Victor M. Barba -- Copyright 2013 -- All Rights Reserved -- -- Version 1.0 -- --==\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*++-- -- ------------------------------------------------------------------------------------------ -- --==\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*[STORYBOARD REQUIRE]\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*++-- -- ------------------------------------------------------------------------------------------ local storyboard = require( "storyboard" ) local widget = require "widget" local scene = storyboard.newScene() ------------------------------------------------------------------------------------------ -- --==\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*[VARIABLES]\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*++-- -- ------------------------------------------------------------------------------------------ local buttonHome local buttonBack local buttonGun local buttonDynamite local fireSprite local fireSprite2 local dynamiteSprite local gunSheet local gunSprite local sfx1 = audio.loadSound( "sfxExplosion1.mp3") local sfx3 = audio.loadSound( "sfxFire1.mp3") local sfx4 = audio.loadSound( "sfxGunsShot1.mp3") ------------------------------------------------------------------------------------------ -- --==\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*[FUNCTIONS]\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*++-- -- ------------------------------------------------------------------------------------------ local function buttonHomeHandler()         storyboard.gotoScene( "mainMenu", "zoomInOutFade", 200 )         return true end local function buttonBackHandler()         storyboard.gotoScene( "animation", "fromLeft", 200 )         return true end local function buttonGunHandler()         audio.play(sfx4, { channel=1 } )                  gunSheet = graphics.newImageSheet("flames\_05.png", {width=128, height=128, numFrames=30})                  gunSprite = display.newSprite(gunSheet, { name="sp", start=1, count=30, time=1000, loopCount = 1 } )         gunSprite.x = 322; gunSprite.y = 505         gunSprite.xScale = .9; gunSprite.yScale = .9         gunSprite:play()         --gunSprite:pause()     return true end local function buttonDynamiteHandler()             audio.play(sfx1, { channel=2 } )                  local dynimateSheet = graphics.newImageSheet("flames\_01.png", {width=128, height=128, numFrames=30})                  dynamiteSprite = display.newSprite(dynimateSheet, { name="dynamite", start=1, count=30, time=1000, loopCount = 1 } )         dynamiteSprite.x = 512; dynamiteSprite.y = 200         dynamiteSprite.xScale = .9; dynamiteSprite.yScale = .9         dynamiteSprite:play()         --dynamiteSprite:pause()     return true end ------------------------------------------------------------------------------------------ -- --==\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*[CREATE SCENE]\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*++-- -- ------------------------------------------------------------------------------------------ function scene:createScene( event )     local group = self.view         local background = display.newImage( "spritesSample.png" )     group:insert ( background )               buttonHome = widget.newButton{     defaultFile="buttonHome.png",     onRelease = buttonHomeHandler     }     group:insert ( buttonHome )     buttonHome.x = 910     buttonHome.y = 710          buttonBack = widget.newButton{     defaultFile="buttonBack.png",     onRelease = buttonBackHandler     }     group:insert ( buttonBack )     buttonBack.x = 100     buttonBack.y = 710          buttonGun = widget.newButton{     defaultFile="buttonGun.png",     onRelease = buttonGunHandler     }     group:insert ( buttonGun )     buttonGun.x = 200; buttonGun.y = 550          buttonDynamite = widget.newButton{     defaultFile="buttonDynamite.png",     onRelease = buttonDynamiteHandler     }     group:insert ( buttonDynamite )     buttonDynamite.x = 300; buttonDynamite.y = 200 end ------------------------------------------------------------------------------------------ -- --==\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*[ENETER SCENE]\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*++-- -- ------------------------------------------------------------------------------------------ function scene:enterScene( event )     local group = self.view              audio.play(sfx3, { channel=3, loops=-1, fadein=1000 } )              fireSprite = graphics.newImageSheet("flames\_04.png", {width=128, height=128, numFrames=30})         fireSprite = display.newSprite(fireSprite, { name="fire", start=1, count=30, time=1000 } )         fireSprite.x = 880; fireSprite.y = 400         fireSprite.xScale = 1.5; fireSprite.yScale = 1.5         fireSprite:play()                  fireSprite2 = graphics.newImageSheet("flames\_04.png", {width=128, height=128, numFrames=30})         fireSprite2 = display.newSprite(fireSprite2, { name="fire2", start=1, count=30, time=1000 } )         fireSprite2.x = 840; fireSprite2.y = 445         fireSprite2.xScale = 1.3; fireSprite.yScale = 1.3         fireSprite2:play()      end -------------------------------------------------------------------------------------- --------------------------------------------------------------EXIT SCENE---------- function scene:exitScene()     audio.stop (  )                end -------------------------------------------------------------------------------------- -- --==\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*[DESTROY SCENE]\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*++-- -- function scene:destroyScene( event )     local group = self.view             if buttonHome then             buttonHome:removeSelf()             buttonHome = nil         end                  if buttonBack then             buttonBack:removeSelf()             buttonBack = nil         end                  if buttonGun then             buttonGun:removeSelf()             buttonGun = nil         end                  if buttonDynamite then             buttonDynamite:removeSelf()             buttonDynamite = nil         end                  if fireSprite then             fireSprite:removeSelf()             fireSprite = nil         end                  if fireSprite2 then             fireSprite2:removeSelf()             fireSprite2 = nil         end                  if dynamiteSprite then             dynamiteSprite:removeSelf()             dynamiteSprite = nil         end                  if gunSprite then             gunSprite:removeSelf()             gunSprite = nil         end                            end ---------------------------------------------------------------------------------- scene:addEventListener( "createScene", scene ) scene:addEventListener( "enterScene", scene ) scene:addEventListener( "exitScene", scene ) scene:addEventListener( "destroyScene", scene ) return scene

If you know anyone that can actually tell me how? Please let me know…

and how much it will cost me.

Thank you Brent.

Hi Victor,

Do you wish to hire somebody to basically solve/write this entire scene and its functionality? If so, you may want to post the request in the Corona Marketplace forum:

http://forums.coronalabs.com/forum/586-corona-jobs/

Otherwise, this is a big amount of code for us to look through and determine where the problem is. Somebody may help you out, but typically requests with large blocks of code (especially an entire Storyboard scene module) will not get as much response. With Storyboard, there are a lot of events and functions being triggered at different times, so it probably requires the entire scene to be reverse-engineered.

Sincerely,

Brent Sorrentino

Hi Brent, Thanks…

I did not know about the Corona Marketplace…

I will take a look at that

Thank you.

Victor

@helloworld2013d looks like you have gone through several changes. if you want to email me the part of the code to my email address which is my name doubleslashdesign ( at ) gmail then I’ll check it out and see if I can lend a hand.

Larry

I found this here

http://www.coronalabs.com/blog/2012/10/02/animated-sprites-and-methods/

The sprite is now a display object , just like static images, vector objects, etc.  It can be moved, manipulated, linked to a physics body, and more.  To remove a sprite object, simply use object:removeSelf() or display.remove( object ). Don’t forget to set the reference to nil after removal!

I put it here

local function buttonDynamiteHandler()         display.remove( dynamiteSprite )         audio.play(sfx1, { channel=2 } )                  local dynamiteSprite = graphics.newImageSheet("flames\_01.png", {width=128, height=128, numFrames=30})         dynamiteSprite = display.newSprite(dynamiteSprite, { name="dynamite", start=1, count=30, time=1000, loopCount = 1 } )         dynamiteSprite.x = 512; dynamiteSprite.y = 200         dynamiteSprite.xScale = .9; dynamiteSprite.yScale = .9         dynamiteSprite:play()         --dynamiteSprite:pause()     return true end

and it doesn’t work…

I also used this one

local function buttonDynamiteHandler()         dynamiteSprite:removeSelf()         audio.play(sfx1, { channel=2 } )                  local dynamiteSprite = graphics.newImageSheet("flames\_01.png", {width=128, height=128, numFrames=30})         dynamiteSprite = display.newSprite(dynamiteSprite, { name="dynamite", start=1, count=30, time=1000, loopCount = 1 } )         dynamiteSprite.x = 512; dynamiteSprite.y = 200         dynamiteSprite.xScale = .9; dynamiteSprite.yScale = .9         dynamiteSprite:play()         --dynamiteSprite:pause()     return true end

And it givis me an error

Attempt to index upvalue ‘dynamiteSprite’ (a nil value)

I will keep reading and trying, please…

someone out there who knows how to do this, please help me out…

Victor

Hi Victor,

This is a simple naming error. You’ve named the image sheet the same as the sprite. Also, watch out for your scoping… you’re trying to remove “dynamiteSprite” before you create it.

Brent

Hi Brent,

I changed the name like this

local function buttonDynamiteHandler()         audio.play(sfx1, { channel=2 } )                  dynimateSheet = graphics.newImageSheet("flames\_01.png", {width=128, height=128, numFrames=30})                  dynamiteSprite = display.newSprite(dynimateSheet, { name="dynamite", start=1, count=30, time=1000, loopCount = 1 } )         dynamiteSprite.x = 512; dynamiteSprite.y = 200         dynamiteSprite.xScale = .9; dynamiteSprite.yScale = .9         dynamiteSprite:play()         --dynamiteSprite:pause()     return true end

and on the exitScene I did this

function scene:exitScene()          audio.stop (  )          display.remove( dynamiteSprite )     display.remove( gunSprite )           end

And still did not work, the second, the third and so forth images are still there, when I go to another scene.


I also tried to use the logic. If the “graphics.newImageSheet” is an image

I created a group to insert that image into the group and it will remove like this

local function buttonDynamiteHandler()     local group5 = self.view             audio.play(sfx1, { channel=2 } )                  local dynimateSheet = graphics.newImageSheet("flames\_01.png", {width=128, height=128, numFrames=30})         group5:insert ( dynimateSheet )                           dynamiteSprite = display.newSprite(dynimateSheet, { name="dynamite", start=1, count=30, time=1000, loopCount = 1 } )         dynamiteSprite.x = 512; dynamiteSprite.y = 200         dynamiteSprite.xScale = .9; dynamiteSprite.yScale = .9         dynamiteSprite:play()         --dynamiteSprite:pause()     return true end

But no luck! Error

File: …ormbarba/Desktop/How to make an app/spriteSample.lua
Line: 50

Attempt to index global ‘self’ (a nil value)

I’m trying…