Using a Spritesheet to fill an object ?

Hi !

Is it possible to use a spritesheet to fill a shape ?

I’ve tried this (but obviously, it doesn’t work :slight_smile: )

local sheetData = {width=128, height=128, numFrames=20, sheetContentWidth=640, sheetContentHeight=512} local mySheet = graphics.newImageSheet("spritesheet.png", sheetData) local sequenceData ={{name = "defaut", start=1, count=20, time=600, loopCount=0}} local spritesheetTexture = {type = "sprite", mySheet, sequenceData} local myObject = display.newRect(0,0,200,200) myObject.fill = spritesheetTexture

Mmh my bad !

It was actually clearly written in the documentation…

local options = { width = 40, height = 100, numFrames = 8, sheetContentWidth = 160, -- width of original 1x size of entire sheet sheetContentHeight = 200 -- height of original 1x size of entire sheet } local imageSheet = graphics.newImageSheet( "textures.png", options ) local paint = { type = "image", sheet = imageSheet, frame = 2 } local rect = display.newRect( 200, 200, 300, 300 ) rect.fill = paint

Sorry but… I’ve managed to load the imageSheet, but now, how can I actually play it ?

@evanspro,

I am pretty sure you need to create a sprite if you want to animate the image.

Your other option  is to write custom code to change the frame yourself.

-Ed

Something like:

local setFrame( obj, paint, frame ) paint.frame = frame obj.fill = paint end ... local paint = { type = "image", sheet = imageSheet, frame = 1 } local rect = display.newRect( 200, 200, 300, 300 ) setFrame( rect, paint, 1 ) timer.performWithDelay( 100, function() setFrame( rect, paint, 2 ) end ) timer.performWithDelay( 200, function() setFrame( rect, paint, 3 ) end )

@romainggamer : This is what I tried to do in my first post. First, I’m loading all the infos needed to build the sprite, but then, I’m not really sure on how to apply it as a “paint”…

Hi @evanspro,

Are you trying to fill some object with an animated sprite? This is not possible using a “paint”. You can fill (paint) an object with a static frame from an image sheet, but you can’t paint an object with an animated sprite.

Best regards,

Brent

Hi @Brent

Aw, that’s too bad !  I’m gonna try to do what romainggamer suggested then :slight_smile:

Thanks a lot !

Mmh my bad !

It was actually clearly written in the documentation…

local options = { width = 40, height = 100, numFrames = 8, sheetContentWidth = 160, -- width of original 1x size of entire sheet sheetContentHeight = 200 -- height of original 1x size of entire sheet } local imageSheet = graphics.newImageSheet( "textures.png", options ) local paint = { type = "image", sheet = imageSheet, frame = 2 } local rect = display.newRect( 200, 200, 300, 300 ) rect.fill = paint

Sorry but… I’ve managed to load the imageSheet, but now, how can I actually play it ?

@evanspro,

I am pretty sure you need to create a sprite if you want to animate the image.

Your other option  is to write custom code to change the frame yourself.

-Ed

Something like:

local setFrame( obj, paint, frame ) paint.frame = frame obj.fill = paint end ... local paint = { type = "image", sheet = imageSheet, frame = 1 } local rect = display.newRect( 200, 200, 300, 300 ) setFrame( rect, paint, 1 ) timer.performWithDelay( 100, function() setFrame( rect, paint, 2 ) end ) timer.performWithDelay( 200, function() setFrame( rect, paint, 3 ) end )

@romainggamer : This is what I tried to do in my first post. First, I’m loading all the infos needed to build the sprite, but then, I’m not really sure on how to apply it as a “paint”…

Hi @evanspro,

Are you trying to fill some object with an animated sprite? This is not possible using a “paint”. You can fill (paint) an object with a static frame from an image sheet, but you can’t paint an object with an animated sprite.

Best regards,

Brent

Hi @Brent

Aw, that’s too bad !  I’m gonna try to do what romainggamer suggested then :slight_smile:

Thanks a lot !