Jump to content

[TOPIC: topicViewTemplate]
[GLOBAL: userSmallPhoto]
Photo

extracting sprite from within a texture packed image
Started by smasherzz Oct 24 2013 03:06 AM

3 replies to this topic
texture packer sprite image sheet
[TOPIC CONTROLS]
This topic has been archived. This means that you cannot reply to this topic.
[/TOPIC CONTROLS]
[modOptionsDropdown]
[/modOptionsDropdown]
[reputationFilter]
[TOPIC: post.html]
#1

smasherzz

[GLOBAL: userInfoPane.html]
smasherzz
  • Observer

  • 26 posts
  • Corona SDK

Hi All,

I have two images and a sprite sheet (in the form of a png image) in my project. I used texture packer to pack the two images and one sprite sheet PNG into one file. Now I can easily get the two images using code like:

 

local star1 = display.newImage(gameAssets01Sheet, gameassets01_tp:getFrameIndex("starsone"));

 

I am not able to extract and play the sprite sheet though.

Can I also extract the sprite sheet from the texture packed file and play my sprite?

 

regards,

P.S. The sprite sheet play fine if it is not packed into the texture packer.



[TOPIC: post.html]
#2

retrofitProductions

[GLOBAL: userInfoPane.html]
retrofitProductions
  • Contributor

  • 321 posts
  • Corona SDK

Hi, 

 

Without seeing all your code it is hard to identify the problem.

Are you using newSprite and setting up the sequenceData so it knows what to animate??

 

Personally I use Level Director to import my TP files and use the built-in animator but if you want to do it manually then I suggest you take a look at the newSprite and newImageSheet documentation.



[TOPIC: post.html]
#3

smasherzz

[GLOBAL: userInfoPane.html]
smasherzz
  • Observer

  • 26 posts
  • Corona SDK

I am on MAC so Level Director won't work for me.



[TOPIC: post.html]
#4

jack95

[GLOBAL: userInfoPane.html]
jack95
  • Contributor

  • 190 posts
  • Corona SDK

This is how you would play the animation:

 

    myAnim = display.newSprite( parentGroup, gameAssets01Sheet, {
        time = 1000,
        loopCount = 0,
        frames = {
            gameassets01_tp:getFrameIndex("ico1"), -- notice you must know the name of each frame
            gameassets01_tp:getFrameIndex("ico2"),
            gameassets01_tp:getFrameIndex("ico3"),
        }
    })
    myAnim:setReferencePoint( display.CenterReferencePoint )
    myAnim.x = 384
    myAnim.y = 576
    myAnim:play()

--[[ Sometimes, when I have a lot of frames with a sequenced number suffix, I use a loop
    local animFrames = {}
    for i=1,3 do
        animFrames[#animFrames+1] = gameassets01_tp:getFrameIndex("ico"..i)
    end

    myAnim = display.newSprite( parentGroup, gameAssets01Sheet, {
        time = 1000,
        loopCount = 0,
        frames = animFrames
    })
]]--




[topic_controls]
[/topic_controls]