lundi 2 mars 2015

How to "link" a frame of an image sheet to a button on a segmented control? In lua

I am creating a practice widget for a class and I am trying to connect three frames in an image sheet to three different buttons on a segmented control.


Here is the code I have for the image sheet



-- Create the image sheet and options
local options = {
width = 240,
height = 80,
numFrames = 3
}

-- Create the hearts image
local heartSheet = graphics.newImageSheet( "heartcontainersfinalz.png", options )

local sequenceData = {
{ x=0, y=0, width=60, height=20 },
{ x=40, y=0, width=60, height=20 },
{ x=60, y=0, width=60, height=20 }
}
hearts = display.newImage( heartSheet, sequenceData )
hearts.x, hearts.y = 160, 350


and the code for the segmented control



-- Create the segmented control widget
local segmentedControl = widget2.newSegmentedControl
{
left = 50,
top = 100,
segmentWidth = 75,
segments = { "One", "Two", "Three" },
defaultSegment = 1,
onPress = onSegmentPress
}


So far I have the first frame of the image sheet displayed and above it I have the segmented control. So as I said I need the first button on the segmented control to display the first frame of the image sheet, second button to display the second frame, etc... Thanks in advance.


Aucun commentaire:

Enregistrer un commentaire