Hi guys!
I am a newbie.
I’ve got an sprite (elementos.png) and the elementos.lua file generated by Zwoptex.
--
--elementos.lua file
--
function getSpriteSheetData()
local sheet = {
frames = {
{
name = "barba.png",
spriteColorRect = { x = 0, y = 5, width = 40, height = 32 },
textureRect = { x = 2, y = 2, width = 40, height = 32 },
spriteSourceSize = { width = 40, height = 40 },
spriteTrimmed = true,
textureRotated = false
},
{
name = "boca.png",
spriteColorRect = { x = 3, y = 17, width = 34, height = 10 },
textureRect = { x = 38, y = 78, width = 34, height = 10 },
spriteSourceSize = { width = 40, height = 40 },
spriteTrimmed = true,
textureRotated = false
},
-- an so on..
}
}
return sheet
end
--
--main.lua
--
local datos=require("elementos")
local elementos = sprite.newSpriteSheetFromData( "elementos.png", datos.getSpriteSheetData() )
How can I access, for example, to the first image of the sprite?
Thanks in advance!
[import]uid: 44013 topic_id: 8269 reply_id: 308269[/import]
This isn’t directly about sprites but it does demonstrate how to use them:
http://developer.anscamobile.com/forum/2011/01/29/object-culling-render-process-when-not-content-area#comment-26394
Note the line in the code tile.currentFrame [import]uid: 12108 topic_id: 8269 reply_id: 29486[/import]
Thank you very much, jhocking!!
You’ve solved my problem! [import]uid: 44013 topic_id: 8269 reply_id: 29492[/import]
Mmmmm…
I want to display 2 images from the sprite but my code only display the last referenced. Could you tell me what am I doing wrong?
--
--main.lua
--
require "sprite"
local datos=require("elementos")
local ancho,alto=display.contentWidth,display.contentHeight
local fondo\_sprite=display.newRect(0,0,ancho,200)
fondo\_sprite:setFillColor(255,255,255,120)
local thumbs=display.newGroup()
local elementos = sprite.newSpriteSheetFromData( "elementos.png", datos.getSpriteSheetData() )
local conxunto = sprite.newSpriteSet(elementos,1,elementos.frameCount)
local instancia = sprite.newSprite(conxunto)
local posX=90
for i=1,2 do
instancia.currentFrame = i
instancia.x=90
instancia.y=70
thumbs:insert(instancia)
posX=posX+60
end
[import]uid: 44013 topic_id: 8269 reply_id: 29497[/import]
Ok, I know…
--
--main.lua
--
require "sprite"
local datos=require("elementos")
local ancho,alto=display.contentWidth,display.contentHeight
local fondo\_sprite=display.newRect(0,0,ancho,200)
fondo\_sprite:setFillColor(255,255,255,120)
local thumbs=display.newGroup()
local elementos = sprite.newSpriteSheetFromData( "elementos.png", datos.getSpriteSheetData() )
local conxunto = sprite.newSpriteSet(elementos,1,elementos.frameCount)
--local instancia = sprite.newSprite(conxunto)
local posX=90
for i=1,2 do
local instancia = sprite.newSprite(conxunto)
instancia.currentFrame = i
instancia.x=posX
instancia.y=70
thumbs:insert(instancia)
posX=posX+60
end
Sorry!
And thank you again! [import]uid: 44013 topic_id: 8269 reply_id: 29499[/import]