Jump to content

[TOPIC: topicViewTemplate]
[GLOBAL: userSmallPhoto]
Photo

Help me with the switch-widget please!
Started by jonas_elme Feb 17 2013 08:29 PM

7 replies to this topic
[TOPIC CONTROLS]
This topic has been archived. This means that you cannot reply to this topic.
[/TOPIC CONTROLS]
[modOptionsDropdown]
[/modOptionsDropdown]
[reputationFilter]
[TOPIC: post.html]
#1

jonas_elme

[GLOBAL: userInfoPane.html]
jonas_elme
  • Observer

  • 12 posts
  • Corona SDK

Hi !

I just want to know how to make the simplest switch by using my own pictures.

I would like it to work like this. (see below)

But is does´nt! So apperently there´s something wrong with this.

Can someon help me with how it should look like?

(Yes i require widgets etc, it´s just my switch code that makes it crash!)
Thank you so much!

[code=auto:0]
local swtBtn = widget.newSwitch
{

width=300,
height=150,
frameOn="bild1.png",
frameOff="bild2.png",
onPress=function1,
onRelease=function2,
}
[code=auto:0]

uid: 197493 topic_id: 36032 reply_id: 336032


[TOPIC: post.html]
#2

Danny

[GLOBAL: userInfoPane.html]
Danny
  • Corona Geek

  • 2,597 posts
  • Corona Staff

Hi.

As per the documentation: http://docs.coronalabs.com/api/library/widget/newSwitch.html

frameOn & frameOff are frames indexes from an imageSheet which you have created. They are not individual png image files.
uid: 84637 topic_id: 36032 reply_id: 143170


[TOPIC: post.html]
#3

jonas_elme

[GLOBAL: userInfoPane.html]
jonas_elme
  • Observer

  • 12 posts
  • Corona SDK

Thank you!

I solved it myself, but now i have another problem.

I want my spritesheet to start when i hit a button but i cant get it to work.

Any tips for this one :)?

[code=auto:0]

function knapp1 (event)
instance:play("hubbe.png")
end

button1 = widget.newButton{
default = "startknapp.png",
over = "menyknapp.png",
onRelease = knapp1,
emboss = true
}
button1.x=_W/2;button1.y=_H/2.2

local sheet2 = graphics.newImageSheet( "hubbe.png", { width=160, height=200, numFrames=6 } )
local instance = display.newSprite( sheet2, { name="hubbe.png", start=1, count=6, time=2000 } )
instance.x =500
instance.y = 500
uid: 197493 topic_id: 36032 reply_id: 143331


[TOPIC: post.html]
#4

Danny

[GLOBAL: userInfoPane.html]
Danny
  • Corona Geek

  • 2,597 posts
  • Corona Staff

Yes you have a scope issue there.

Your function cannot "see" instance because you have declared it below the function. There are several ways to get around this situation, the most common being creating a "forward reference".

See the below modified example of your code:

-- Create a "forward reference" to instance here
local instance

function knapp1 (event)
instance:play("hubbe.png")
end
 
button1 = widget.newButton{
        default = "startknapp.png",
        over = "menyknapp.png",
onRelease = knapp1,
emboss = true
}
button1.x=_W/2;button1.y=_H/2.2
 
 
 
local sheet2 = graphics.newImageSheet( "hubbe.png", { width=160, height=200, numFrames=6 } )

-- Create instance here 
instance = display.newSprite( sheet2, { name="hubbe.png", start=1, count=6, time=2000 } )
instance.x =500
instance.y = 500
uid: 84637 topic_id: 36032 reply_id: 143334


[TOPIC: post.html]
#5

jonas_elme

[GLOBAL: userInfoPane.html]
jonas_elme
  • Observer

  • 12 posts
  • Corona SDK

Hi !

I just want to know how to make the simplest switch by using my own pictures.

I would like it to work like this. (see below)

But is does´nt! So apperently there´s something wrong with this.

Can someon help me with how it should look like?

(Yes i require widgets etc, it´s just my switch code that makes it crash!)
Thank you so much!

[code=auto:0]
local swtBtn = widget.newSwitch
{

width=300,
height=150,
frameOn="bild1.png",
frameOff="bild2.png",
onPress=function1,
onRelease=function2,
}
[code=auto:0]

uid: 197493 topic_id: 36032 reply_id: 66032


[TOPIC: post.html]
#6

Danny

[GLOBAL: userInfoPane.html]
Danny
  • Corona Geek

  • 2,597 posts
  • Corona Staff

Hi.

As per the documentation: http://docs.coronalabs.com/api/library/widget/newSwitch.html

frameOn & frameOff are frames indexes from an imageSheet which you have created. They are not individual png image files.
uid: 84637 topic_id: 36032 reply_id: 143170


[TOPIC: post.html]
#7

jonas_elme

[GLOBAL: userInfoPane.html]
jonas_elme
  • Observer

  • 12 posts
  • Corona SDK

Thank you!

I solved it myself, but now i have another problem.

I want my spritesheet to start when i hit a button but i cant get it to work.

Any tips for this one :)?

[code=auto:0]

function knapp1 (event)
instance:play("hubbe.png")
end

button1 = widget.newButton{
default = "startknapp.png",
over = "menyknapp.png",
onRelease = knapp1,
emboss = true
}
button1.x=_W/2;button1.y=_H/2.2

local sheet2 = graphics.newImageSheet( "hubbe.png", { width=160, height=200, numFrames=6 } )
local instance = display.newSprite( sheet2, { name="hubbe.png", start=1, count=6, time=2000 } )
instance.x =500
instance.y = 500
uid: 197493 topic_id: 36032 reply_id: 143331


[TOPIC: post.html]
#8

Danny

[GLOBAL: userInfoPane.html]
Danny
  • Corona Geek

  • 2,597 posts
  • Corona Staff

Yes you have a scope issue there.

Your function cannot "see" instance because you have declared it below the function. There are several ways to get around this situation, the most common being creating a "forward reference".

See the below modified example of your code:

-- Create a "forward reference" to instance here
local instance

function knapp1 (event)
instance:play("hubbe.png")
end
 
button1 = widget.newButton{
        default = "startknapp.png",
        over = "menyknapp.png",
onRelease = knapp1,
emboss = true
}
button1.x=_W/2;button1.y=_H/2.2
 
 
 
local sheet2 = graphics.newImageSheet( "hubbe.png", { width=160, height=200, numFrames=6 } )

-- Create instance here 
instance = display.newSprite( sheet2, { name="hubbe.png", start=1, count=6, time=2000 } )
instance.x =500
instance.y = 500
uid: 84637 topic_id: 36032 reply_id: 143334



[topic_controls]
[/topic_controls]