Sprite Group

Um, I have a ton of x. .y usage all over. Here’s an example.

local function move\_spring(event) event.target.x = event.x event.target.y = event.y if event.phase == "began" or event.phase == "ended" or event.phase == "cancelled" then bounce(event.target) end end [import]uid: 72845 topic_id: 34466 reply_id: 138633[/import]

Hi FL,
Hmmm… well let’s deal with that “warning” later. What I just noticed is that you’re using the deprecated .sprite library. I’m urging everybody to migrate to the current sprite methods, because the old library will receive no updates or additions going forward.

Here’s a tutorial I wrote on the current method:
http://www.coronalabs.com/blog/2012/10/02/animated-sprites-and-methods/

Best of luck, let me know how it goes!
Brent [import]uid: 200026 topic_id: 34466 reply_id: 138711[/import]

Hi FL,
Which method are you using when you exit the scene, “purge” or “remove”? The difference is that “purge” will retain the scene in the background memory, unless memory gets chewed up to the point where it can’t remain in memory, then it will be removed. Purging is useful if you’re going quickly back and forth between scenes, and you want to maintain each one for fast loading.

“remove” completely clears the scene and removes the module from Lua’s memory. If you don’t intend to come back to the scene anytime soon, and you want to free up its memory, remove it instead of purging it.

Brent [import]uid: 200026 topic_id: 34466 reply_id: 138341[/import]

I’m using purge scene but I’ve figured out my problem isn’t with the purging/removal of the scene but that I have another error making things operate funny.

This is the error I get in the terminal:
2013-01-10 16:01:03.670 Corona Simulator[388:903] WARNING: Attempting to set property(y) with nil
2013-01-10 16:01:03.670 Corona Simulator[388:903] WARNING: Attempting to set property(x) with nil

which in turn is making it so every time I purge a scene my sprite appears to hover instead of falling to the ground as it should. Not really sure why this is happening but I’ll post the sprite code and maybe you can see where the problem lies.

local data = require("marios").getSpriteSheetData();  
local sheet = sprite.newSpriteSheetFromData("marios.png",data);  
local set = sprite.newSpriteSet(sheet, 1, 16);  
  
local screen = display.newGroup()  
local instance = sprite.newSprite(set);  
instance.x = display.contentWidth/70   
physics.addBody(instance, {bounce = 0.2, friction = .1})  
 group:insert(screen)  
instance.name = "mario"  
instance.angularDamping = 5000  
instance.isFixedRotation = true  
instance.isAlive = yes  

Not even sure if the sprite is the problem being that I don’t have a code line number to reference.
And thanks again Brent for helping me out. You definitely have a special thanks in my credits. [import]uid: 72845 topic_id: 34466 reply_id: 138357[/import]

I’m a bit confused on this as when I first set up my sprite things were a bit different. I’m just not sure which code I put in which .lua or how many .luas I’m supposed to have. Once I get that out of the way I think I should be able to replace my old code. [import]uid: 72845 topic_id: 34466 reply_id: 139061[/import]

Hi FL,
You can do all of this in your main.lua file, if you want (or set up new sprites in each scene, the core scene, whatever). The code blocks that I put in that tutorial should just be pieced together into a consecutive series… but make sure you understand what each block is doing before you proceed to the next! :slight_smile: [import]uid: 200026 topic_id: 34466 reply_id: 139062[/import]

Ok I plug this code into my main.lua

require("sprite");  
local sheetData = { width=35, height=60, numFrames=16, sheetContentWidth=256, sheetContentHeight=256 }  
   
 local mySheet = graphics.newImageSheet( "mario.png", sheetData )  
   
 local sequenceData = {  
 { name = "normalRun", start=1, count=16, time=800 },  
  
 }  
   
local animation = display.newSprite( mySheet, sequenceData )  
animation.x = display.contentWidth/2 --center the sprite horizontally  
animation.y = display.contentHeight/2 --center the sprite vertically  
   
animation:play()  

Now the code works but my sprite doesn’t look right. It looks glitched but I don’t get why because I’m using the same 16 frame sprite sheet I was using before. [import]uid: 72845 topic_id: 34466 reply_id: 139071[/import]

Hi FL,
Cool, name in the credits! More than I would deserve… I’d just like to see your game making forward progress to market. :slight_smile:

So, this could be a few things, but first we need to track it down. Start by searching your entire document for “.x” and “.y” (don’t include the quotes). This should turn up where those errors are… and which line(s) it occurs on. Once you find that, let me know what code is around it. Probably a very simple fix!

Brent [import]uid: 200026 topic_id: 34466 reply_id: 138557[/import]

Um, I have a ton of x. .y usage all over. Here’s an example.

local function move\_spring(event) event.target.x = event.x event.target.y = event.y if event.phase == "began" or event.phase == "ended" or event.phase == "cancelled" then bounce(event.target) end end [import]uid: 72845 topic_id: 34466 reply_id: 138633[/import]

Hi FL,
Hmmm… well let’s deal with that “warning” later. What I just noticed is that you’re using the deprecated .sprite library. I’m urging everybody to migrate to the current sprite methods, because the old library will receive no updates or additions going forward.

Here’s a tutorial I wrote on the current method:
http://www.coronalabs.com/blog/2012/10/02/animated-sprites-and-methods/

Best of luck, let me know how it goes!
Brent [import]uid: 200026 topic_id: 34466 reply_id: 138711[/import]

I’m a bit confused on this as when I first set up my sprite things were a bit different. I’m just not sure which code I put in which .lua or how many .luas I’m supposed to have. Once I get that out of the way I think I should be able to replace my old code. [import]uid: 72845 topic_id: 34466 reply_id: 139061[/import]

Hi FL,
You can do all of this in your main.lua file, if you want (or set up new sprites in each scene, the core scene, whatever). The code blocks that I put in that tutorial should just be pieced together into a consecutive series… but make sure you understand what each block is doing before you proceed to the next! :slight_smile: [import]uid: 200026 topic_id: 34466 reply_id: 139062[/import]

Ok I plug this code into my main.lua

require("sprite");  
local sheetData = { width=35, height=60, numFrames=16, sheetContentWidth=256, sheetContentHeight=256 }  
   
 local mySheet = graphics.newImageSheet( "mario.png", sheetData )  
   
 local sequenceData = {  
 { name = "normalRun", start=1, count=16, time=800 },  
  
 }  
   
local animation = display.newSprite( mySheet, sequenceData )  
animation.x = display.contentWidth/2 --center the sprite horizontally  
animation.y = display.contentHeight/2 --center the sprite vertically  
   
animation:play()  

Now the code works but my sprite doesn’t look right. It looks glitched but I don’t get why because I’m using the same 16 frame sprite sheet I was using before. [import]uid: 72845 topic_id: 34466 reply_id: 139071[/import]