Hi,
I am having a problem with switching a texture of a sprite.
Google shows that I must use “gui.play_flipbook()” when using atlases.
But I don’t understand what to do…
Thanks!
Jesse
Hi,
I am having a problem with switching a texture of a sprite.
Google shows that I must use “gui.play_flipbook()” when using atlases.
But I don’t understand what to do…
Thanks!
Jesse
gui.set_texture() is not what you want in this case most likely if the texture is already set on the node and you only want to change the animation.
gui.play_flipbook() is correct for changing the animation as long as that animation is defined on the atlas texture it should work.
Can you post a code sample of what’s not working for you exactly?
node = gui.get_node("SpeakerON")
if (DelayAllUserInput == 0) then
if gui.pick_node(node, action.x, action.y) then
if (ScreenFadeStatus == 0) then
gui.set_scale( node, vmath.vector3(0.85, 0.85, 1) )
msg.post("level:/Audio#MenuClick", "play_sound", {delay = 0, gain = EffectsVolume})
if (MusicVolume == 0 and EffectsVolume == 0) then
MusicVolume = 1
EffectsVolume = 1
gui.set_texture(node, "SpeakerON")
else
MusicVolume = 0
EffectsVolume = 0
gui.set_texture(node, "SpeakerOFF")
end
sound.set_group_gain("music", MusicVolume)
sound.set_group_gain("effects", EffectsVolume)
PM.PlayMusic(CurrentMusicPlaying)
DelayAllUserInput = 20
NextScreen = 2
ScreenFadeStatus = 1
ScreenFadeAlpha = 0
end
end
end
AS Pkeod said gui.play_flipbook()
, I used this for a button pressed effect, when the button is pressed the image changes to give the effect the button has been pressed. In your atlas your button looks like this:
Images, no animations. And in the code I change them with:
if gui.pick_node(self.node_btn_play, action.x, action.y) then
if action_id == input_click then
if action.pressed then
gui.play_flipbook(self.node_btn_play, hash("btn_play_down"))
elseif action.released then
gui.play_flipbook(self.node_btn_play, hash("btn_play_up"))
end
end
end
Hope is what you were looking for.
Hi,
Code posted above.
When user clicks on speaker icon I want the sprite to change.
(SpeakerON when audio is on, and SpeakerOFF when audio is off)
Both sprites above are in “TitleImages.atlas”.
Any ideas?
Thanks!
Jesse
In your previous post you wrote:
gui.set_texture(node, "SpeakerON")
Where SpeakerON
should now actually be the name of your atlas like:
gui.set_texture(node, "TitleImages")
To select the image/animation from that atlas, you’ll need to add gui.play_flipbook()
as well. Like so (SpeakerON
is the name of the image):
gui.play_flipbook(node, "SpeakerON")
You could try this in your script:
if (MusicVolume == 0 and EffectsVolume == 0) then
MusicVolume = 1
EffectsVolume = 1
gui.set_texture(node, "TitleImages")
gui.play_flipbook(node, "SpeakerON")
else
MusicVolume = 0
EffectsVolume = 0
gui.set_texture(node, "TitleImages")
gui.play_flipbook(node, "SpeakerOFF")
end
ERROR:SCRIPT: /data/gui_script/Screen-2-Title-GUI-Script.gui_script:288: Texture ‘TitleImages’ is not specified in scene
stack traceback:
[C]: in function ‘set_texture’
/data/gui_script/Screen-2-Title-GUI-Script.gui_script:288: in function </data/gui_script/Screen-2-Title-GUI-Script.gui_script:60>
Hi,
Got it working.
Did not need: “gui.set_texture(node, “TitleImages”)”
Thanks!
Jesse