static sprites

Hi,

Playing with the Game Edition sprite stuff-- lots of fun. However, if I want to have all my sprites on one sheet (not like the Jungle demo) to save on draw calls, and don’t actually want a sprite to animate, what’s the best way to do this? Currently, my attempts work great in the Simulator but on the device the “static” sprites I’m trying to make start with one image and then switch to another shortly after the app launches.

I’m using a 512x512 PNG with 64x64 tiles on it; nothing special. Here’s the code:

require("math")  
require("sprite")  
--require("entity")  
  
local screenW = 1024  
local screenH = 768  
local tileW = 64  
local tileH = 64  
local scrTileW = screenW / tileW  
local scrTileH = screenH / tileH  
  
local mapSheet = sprite.newSpriteSheet("tilesetTest1.png", tileW, tileH)  
local mapSet = sprite.newSpriteSet(mapSheet, 1, 4)  
sprite.add(mapSet, "grass", 2, 1, 1)  
sprite.add(mapSet, "ground", 3, 1, 1)  
sprite.add(mapSet, "water", 4, 1, 1)  
  
for j = 1, tileH+1 do  
 for i = 1, tileW+1 do  
 local s = sprite.newSprite(mapSet)  
 local which = math.random(3)  
 if which == 1 then  
 s:prepare("grass")  
 elseif which == 2 then  
 s:prepare("ground")  
 elseif which == 3 then  
 s:prepare("water")  
 end  
  
 s.x = i \* tileW - (tileW \* 0.5)  
 s.y = j \* tileH - (tileH \* 0.5)  
 end  
end  
  

To my eyes this should set each tile to the one I’ve picked in its set. Am I doing something wrong? I tried using a single set with all tiles in it, then picking the tiles with sprite.currentFrame but that left me with a black screen.

Thanks,
~ k [import]uid: 2857 topic_id: 1482 reply_id: 301482[/import]

Hi,

to my knowledge, there is a bug with preparing Sprites by selecting aset of frames. At least for animated sprites I noticed this in ALPHA 1 and reported itvia email. I imagine that this could affect your code also. Not sure if it got fixed it alpha 2 as I did not test that version yet.#

Cheers
Michael Hartlef

http://www.whiteskygames.com
http://www.twitter.com/mhartlef
[import]uid: 5712 topic_id: 1482 reply_id: 4179[/import]

Good to know it’s not just me. :slight_smile:

Could someone from Ansca let me know if this was fixed, and if so, what the proper method for doing this might be? I’d like to atlas all background drawing onto one texture and all characters onto another, so I need to know how to make single-frame non-animated sprites work with spriteSets.

Thanks!
~ C [import]uid: 2857 topic_id: 1482 reply_id: 4182[/import]

The issue with frame discrepancies “should” be fixed in the next GE drop. There were several problems with initial frame and frame subsets that have been fixed.

Single-frame sprites may need some additional work, we have a work item for setting a frame # as well. Can you give some more details on how you plan to use this? [import]uid: 54 topic_id: 1482 reply_id: 4198[/import]

Sure thing:

Essentially, I want to batch all similar sprites by using 1k square atlases. All the player characters in the game will be on one texture, all the enemies on another, and all the background tiles on a third. Most characters, tiles, enemies, and items will be on a 64x64 square grid in the spriteSets, although some of the larger enemies will take up larger chunks of space on the same tile set.

So for example, I’d like to be able to do the following:

local regularEnemies = sprite.newSpriteSheet("enemies\_level24.png", 64, 64)  
local bossEnemies = sprite.newSpriteSheet("enemies\_level24.png", 128, 128)  
local enemySet = sprite.newSpriteSet(regularEnemies, 1, 4)  
local bossSet = sprite.newSpriteSet(bossEnemies, 2, 3)  
sprite.add(enemySet, "soldier", 1, 4, 500)  
sprite.add(bossSet, "BigBad", 1, 1, 1)  

So in this example, I’m expecting to have 64x64 enemies in the upper-left corner of the sprite sheet, and 128x128 enemy graphics in the other three quadrants. Using two separate spriteSheet sets, the same texture is used for drawing and would allow the 64x64 enemies and the larger 128x128 boss enemy to be batched into a single draw call.

I don’t want this to preclude the ability to make animated tiles for the background maps, or the ability to have non-animated tiles where I can pick the frame number with sprite.currentFrame. So for example, this should work but doesn’t seem to:

local spriteImage = sprite.newSpriteSheet("enemies\_level24.png", 64, 64)  
local spriteSet = sprite.newSpriteSet(regularEnemies, 1, 24)  
sprite.add(spriteSet, "backgroundTiles", 1, 24, 1000)  
  
-- I'd add as many of these as needed to generate a background tile map  
local s = sprite.newSprite(spriteSet)  
s:prepare("backgroundTiles")  
  
local which = math.random(3)  
s.currentFrame = which + 1  

Does that make sense? I’m assuming that’s how you intended it to work, but when run on the iPad the code in my first post either adds all my sprites twice or adds them with a random currentFrame and then sets them to a proper frame afterwards. If someone wants to see exactly what I’m seeing, please use the following PNG file:

http://skitch.com/kattkieru/dqbku/tilesettest1

[import]uid: 2857 topic_id: 1482 reply_id: 4207[/import]

Just wanted to let you know that in the most recent Game Edition drop, this is still an issue.

I really need the ability to man-handle sprite frames and have them stick. Is there any chance this will get fixed in the next version? [import]uid: 2857 topic_id: 1482 reply_id: 5639[/import]

Is there already a way to batch calls and reduce textureswitches? [import]uid: 5942 topic_id: 1482 reply_id: 63083[/import]