The second one is a png and it still doesn’t work
The point is, all images for the same sequence need to be on a single-layer png. Imagine the letters below (A - L) are frames in an animation - you would lay out your spritesheet in the same way.
A B C
D E F
G H I
J K L
Then you need to define your options table based on how big each frame is and the gaps between each frame. The values will be unique to your file so can’t just be copied from here, otherwise you will just get fragments of a frame and a jumbled mess.
How do I create this ?
You could use GIF splitter online and then just put the images together on Photoshop. Or use a free trial of Texture Packer:
Highly recommend texture packer. What it does is take individual images and position them neatly as a single image, ready to use in Corona. It will even generate the lua code for you so you don’t have to calculate the options table.
I’d also recommend buying a few assets from graphic river to practice with. For as little as $9 you can have a complete character, including all the typical animations you’d need like walk, jump, punch, die, slide etc. Put those into texture packer and you’re away.
Couldn’t find any good tutorials that explain the process of creating the sprites . Any other good makers ?
You should definitely use Texture Packer, they give you a free trial and explain how to use on their website:
The website is saying just drop the image and press publish but nothing is happening
You have to split the GIF into different png images and then drop all the separate files into TexturePacker.
How do I split the image in different png images ?
Maybe this site can help: http://gif2sprite.com/
I’ve never used it, but it sounds like it will do the trick.
Rob
That worked but how do I show the image in my game ?
spritesheet.lua:
-- -- created with TexturePacker (http://www.codeandweb.com/texturepacker) -- -- $TexturePacker:SmartUpdate:d1805432715519b8c34272654540b10c:ce413b6e41be378fafcac5fd6113a88a:c46243f411ca86fe596665ab352bd775$ -- local sheetInfo = require("mysheet") local myImageSheet = graphics.newImageSheet( "sprite-zombieed4d7c54ace483fe0fef59a87ed1c5a17.jpg", sheetInfo:getSheet() ) local sprite = display.newSprite( myImageSheet , {frames={sheetInfo:getFrameIndex("sprite")}} ) local SheetInfo = {} SheetInfo.sheet = { frames = { { -- sprite-zombieed4d7c54ace483fe0fef59a87ed1c5a17 x=1, y=1, width=1356, height=104, }, }, sheetContentWidth = 1358, sheetContentHeight = 106 } SheetInfo.frameIndex = { ["sprite-zombieed4d7c54ace483fe0fef59a87ed1c5a17"] = 1, } function SheetInfo:getSheet() return self.sheet; end function SheetInfo:getFrameIndex(name) return self.frameIndex[name]; end return SheetInfo
game.lua:
-- requires local storyboard = require( "storyboard" ) local scene = storyboard.newScene() local physics = require "physics" physics.start() -- background function scene:createScene(event) local screenGroup = self.view local background = display.newImageRect("images.png",display.contentWidth,display.contentHeight) background.x = display.contentCenterX background.y = display.contentCenterY screenGroup:insert(background) centerX = 230 centerY = 60 round = 1 roundTxt = display.newText( "Round: "..round, centerX, centerY, native.systemFontBold, 20 ) gun = display.newImage("pistol.gif") gun.x = 50 gun.y = 300 screenGroup:insert(gun) cart = display.newImage("cart.png") cart.x = 100 cart.y = 70 screenGroup:insert(cart) end local sheetOptions = { width = 512, height = 256, numFrames = 8 } local moving\_zombie = graphics.newImageSheet( "sprite-zombieed4d7c54ace483fe0fef59a87ed1c5a17.png", sheetOptions ) -- sequences table local sequences\_movingZombie = { { name = "normalRun", start = 1, count = 8, time = 800, loopCount = 4 }, { name = "fastRun", frames = { 1,3,5,7 }, time = 400, loopCount = 0 }, } local moving\_Zombie = display.newSprite( sheet\_movingZombie, sequences\_movingZombie ) -- sprite listener function local function spriteListener( event ) local thisSprite = event.target -- "event.target" references the sprite if ( event.phase == "ended" ) then thisSprite:setSequence( "fastRun" ) -- switch to "fastRun" sequence thisSprite:play() -- play the new sequence end end local bullet = {} local bCounter = 1 local function shootBullet(event) if event.phase == "ended" then bullet[bCounter] = display.newImage( "bullet4.png",gun.x, gun.y, 6, 6 ) bullet[bCounter].value = bCounter physics.addBody( bullet[bCounter], "dynamic" ) bullet[bCounter].gravityScale = 0 bullet[bCounter].myName = "bullet" bullet[bCounter]:setLinearVelocity( 2100, -20 ) bCounter = bCounter + 1 end end Coins = 0 centerX = 350 centerY = 60 CoinsTxt = display.newText( "Coins: "..Coins, centerX, centerY, native.systemFontBold, 20 ) local onCollision=function( event ) if event.phase =="began" then Coins = Coins + 5 CoinsTxt.text="Coins: "..Coins end end function scene:enterScene(event) Runtime:addEventListener("collision", onCollision) gun:addEventListener( "touch", shootBullet ) moving\_Zombie:addEventListener( "sprite", spriteListener ) end function scene:exitScene(event) Runtime:removeEventListener("collision", onCollision) end function scene:destroyScene(event) end scene:addEventListener("createScene", scene) scene:addEventListener("enterScene", scene) scene:addEventListener("exitScene", scene) scene:addEventListener("destroyScene", scene) return scene
i have an error on this line :
local moving\_Zombie = display.newSprite( sheet\_movingZombie, sequences\_movingZombie )
error :
game.lua:64: bad argument #1 to 'newSprite' (ImageSheet expected, got nil)
please help