Sprite Issue

Hi guys,

I am using build 2012.762 (windows)

The code puts two animated sprites on screen, then after 1 second it removes the first animated sprite. The issue happens here as soon as the first animated sprite is removed, the second animated sprite stops animating, no error messages?

I have modularised the code. 3 files. main.lua, character2.lua and character2.lua.

I am using the newImageSheet… so maybe I am just missing something silly somewhere else is this a bug?

Vik

main.lua

  
-- Hide the status Bar  
display.setStatusBar( display.HiddenStatusBar )  
  
local physics = require "physics"  
local character1 = require "character1"  
local character2 = require "character2"  
physics.start( true )  
physics.setDrawMode("normal") -- set to "debug" or "hybrid" to see collision boundaries  
--physics.setDrawMode("hybrid")  
physics.setGravity( 0, 9.8 ) --\> 0, 9.8 = Earth-like gravity  
local C1 = character1.CreateCharacter1(100, 100)  
local C2 = character2.CreateCharacter2(200, 200)  
  
local function killCharacter1()  
  
 if (C1 ~= nil) then  
 C1:removeSelf()   
 C1 = nil  
 end   
end  
local function Game(e)  
  
 timer.performWithDelay(1000, killCharacter1, 1 )  
  
end  
Runtime:addEventListener( "enterFrame", Game)  
  

character1.lua

local M = {}  
local function CreateCharacter1(startX, startY)  
  
 -- create group to return  
 local localGroup = display.newGroup ()   
 -- load the imagesheet  
 local options ={  
 -- The params below are required   
 width = 87,  
 height = 116,  
  
 numFrames = 3,  
 -- The params below are optional; used for dynamic resolution support  
 sheetContentWidth = 261, -- width of original 1x size of entire sheet  
 sheetContentHeight = 116 -- height of original 1x size of entire sheet  
 }  
  
 local imageSheet1 = graphics.newImageSheet( "image1.png", options )  
  
  
 local sequenceData1 = { name="standing", start=1, count=3, time = 1000 }  
  
  
 local character1 = display.newSprite( imageSheet1, sequenceData1 )  
 character1.x = startX  
 character1.y = startY  
 physics.addBody(character1, "static")  
  
  
 --character.xScale = -1  
 character1:setSequence( "standing" )   
 character1:play()  
  
 localGroup:insert(character1)  
  
  
 -- return group   
 return localGroup  
end  
  
M.CreateCharacter1 = CreateCharacter1  
  
return M  
  

character2.lua

[code]

local M = {}
local function CreateCharacter2(startX, startY)
– create group to return
local localGroup = display.newGroup ()

localGroup.killZombie = false

– load the imagesheet
local options ={
– The params below are required
width = 78,
height = 111,

numFrames = 5,
– The params below are optional; used for dynamic resolution support
sheetContentWidth = 390, – width of original 1x size of entire sheet
sheetContentHeight = 111 – height of original 1x size of entire sheet
}

local imageSheet = graphics.newImageSheet( “image2.png”, options )

local sequenceData = { name=“walking”, start=1, count=5, time = 1000 }

local character = display.newSprite( imageSheet, sequenceData )
character.x = startX
character.y = startY
character.name = “zombie”
character.ID = zombieID
character.killZombie = false

physics.addBody(character, “static”, { density=0.2, friction=0.1, bounce=0 })

character:setSequence( “walking” )
character:play()

localGroup:insert(character)

– return group
return localGroup
end

M.CreateCharacter2 = CreateCharacter2

return M

[/code] [import]uid: 67619 topic_id: 23043 reply_id: 323043[/import]

[lua] sheetContentWidth = 261, – width of original 1x size of entire sheet
sheetContentHeight = 116 – height of original 1x size of entire sheet[/lua]

Power of 2 size. Your imageSheet should have size 512px x128px , 512px x256px or 256px x128px but BEST option is 512px x 512px or 256px x 256px. [import]uid: 12704 topic_id: 23043 reply_id: 92185[/import]

Nope… nothing to do with the power of 2 size… cause the sprites work properly… but as soon as I remove one, the other stops…

I resized the sprite canvas size so that all images were 256px x 256px… same issue [import]uid: 67619 topic_id: 23043 reply_id: 92543[/import]

There was a bug in the SDK for removing sprites created with the new sprites API… it was fixed in version 764…

Works fine so far :slight_smile:

Vik [import]uid: 67619 topic_id: 23043 reply_id: 92554[/import]