setFrame on Image

I do the following :

mysheet = graphics.newImageSheet( "images/mysheet.png", sheetinfo)  
-- and  
myImage = display.newImageRect( mysheet, 1,20, 20 )  
-- I'd like to change from frame 1 to 2, as if it were  
myImage = display.newImageRect( mysheet, 2,20, 20 )  
-- doing something like  
myImage:setFrame(2)  

I tried it with no success
Is it possible ?

[import]uid: 9328 topic_id: 27724 reply_id: 327724[/import]

@Antheor, it looks like you are missing options table.

http://www.coronalabs.com/blog/2012/03/06/image-sheets-image-groups-and-sprites/

http://docs.coronalabs.com/api/library/graphics/newImageSheet.html

Naomi
[import]uid: 67217 topic_id: 27724 reply_id: 112431[/import]

Hi there,
You actually need to define your image as a sprite before you can swap frames. It’s simple enough to do; instead of declaring it as a “newImageRect” you make it a “newSprite”. Then you can swap frames at will. Refer to the links that Naomi provided for the sprite API details.

Brent Sorrentino [import]uid: 9747 topic_id: 27724 reply_id: 112437[/import]

Naomi, I did the options ( it’s my “sheetinfo”).

I’ll try to change the declaration. Thx for the tip. [import]uid: 9328 topic_id: 27724 reply_id: 112456[/import]

Ah, I missed that (or rather, I glanced at mySheet and myImage and thought something was definitely missing, including the option table & sequence data table.)

If you just want to use a frame from an imageSheet without using any other frame, what you want to do is:

display.newImageRect( [parent ,] sheet, frameIndex, width, height )

But if you want to change the frame (i.e., use setFrame function), I think you need to go with:

display.newSprite( [parent,] imageSheet, sequenceData )

Naomi [import]uid: 67217 topic_id: 27724 reply_id: 112527[/import]

OK, thx again for the feedback :wink: [import]uid: 9328 topic_id: 27724 reply_id: 112578[/import]