My goal here is to create a slider widget using an image sheet (sprite sheet). Using a image sheet is key.
Before you continue reading, I would like to mention that I’ve visited the Slider Widget Documentation enough times that I’ve practically memorized it. Yet somehow, I still can’t get my slider widget to look half-decent, so here I am…
I believe I am doing everything correctly, but clearly I’m not since slider widget looks more like a plane crash than anything else…
If someone can point out what I’m doing wrong, and possible post the correct code, I would appreciate it immensely.
Thank you in advance.
::Below is my code::
config.lua
application = { content = { width = 320, height = 568, scale = "zoomEven", xAlign = "center", yAlign = "center", }, }
main.lua
local composer = require("composer") composer.gotoScene("slider")
slider.lua
local composer = require("composer") local widget = require("widget") local scene = composer.newScene() local viewGroup local w, h = display.contentWidth, display.contentHeight local sliderSheet = graphics.newImageSheet("slidersheet.png", { frames = { { -- Left x = 618, y = 1, width = 256, height = 128, }, { -- Center x = 1, y = 1, width = 256, height = 128, }, { -- Right x = 878, y = 1, width = 256, height = 128, }, { -- Fill x = 258, y = 1, width = 256, height = 128, }, { -- Handle x = 514, y = 1, width = 102, height = 102, }, }, sheetContentWidth = 470, sheetContentHeight = 314, }) function scene:create(event) viewGroup = self.view local background = display.newRect(w/2, h/2, w, h) local mySlider = widget.newSlider { left = 0, top = 240, value = 0, sheet = sliderSheet, leftFrame = 1, middleFrame = 2, rightFrame = 3, fillFrame = 4, frameWidth = 256, frameHeight = 128, handleFrame = 5, handleWidth = 40, handleHeight = 40, } mySlider.width = 300 mySlider.height = 50 end scene:addEventListener("create", scene) return scene