Changing skins

Discuss using and improving Lua and the Lua Player specific to the PSP.

Moderators: Shine, Insert_witty_name

Post Reply
2Xtremes2004
Posts: 53
Joined: Wed Aug 31, 2005 1:43 am

Changing skins

Post by 2Xtremes2004 »

Ok, I set up a menu in my app so that I could change the background. My menu is set up pretty close to the menu in Shine's Snake game. My question is, is there a way to make it change all the graphics in the app, and not just the background, without having to make a option for each seperate object? Also, I remember seeing something about the reason mp3 were not going to be supported was because of having to buy the rights or something. If thats the case how do other homebrew makers get away with it, for example, I have XBMC on my xbox and it supports mp3.
I want my money back!?
LuMo
Posts: 410
Joined: Sun Aug 21, 2005 2:45 am
Location: Austria
Contact:

Post by LuMo »

put all images into arrays
make a skin an entry
skin1 = array[1]
skin2 = array[2]
skin3 = array[3]
...
should work

greets
lumo
"Good artists copy, great artists steal."
Pablo Picasso
go2lumo.com
MikeHaggar
Posts: 116
Joined: Mon Jul 18, 2005 2:20 am

Re: Changing skins

Post by MikeHaggar »

Using XBMC as an example for guys who cares about rights, isn't exactly good ;)

And .ogg is probably a better format to use anyway...
2Xtremes2004
Posts: 53
Joined: Wed Aug 31, 2005 1:43 am

Post by 2Xtremes2004 »

I was not applying that they care about rights, I don't know if they do or not, either way I was just using them as an example. Anyways.. I have never heared of .ogg, is there any kind of .mp3 to .ogg converter. Will Lua support .ogg in the future?
Last edited by 2Xtremes2004 on Sun Oct 23, 2005 2:36 am, edited 1 time in total.
I want my money back!?
2Xtremes2004
Posts: 53
Joined: Wed Aug 31, 2005 1:43 am

Post by 2Xtremes2004 »

I have never used an array, so I am a bit clueless about them. Could you point me towards an example please. Maybe, it is something like this:

Code: Select all

-- Default options
options = { theme = "Skin#1", music = "Song#1" }

-- Possible options for system config menu
possibleOptions = {
	theme = {
		displayName = "Themes",
		values = {"Skin#1, Skin#2"} },
	music = {
		displayName = "Background Music",
		values = {"Song#1", "Song#2", "Song#3"} }

-- Skin Arrays
Skin#1 = {
background = Image.load("Skins/Background.png"),
hold = Image.load("Data/Hold.png"),
battl = Image.load("Data/Battery Low.png"),
batth = Image.load("Data/Battery Half.png"),
battf = Image.load("Data/Battery Full.png"),
usba = Image.load("Data/USBON.png"),
baudio = Image.load("Data/Audio.png"),
bimage = Image.load("Data/Image.png"),
pointer = Image.load("Data/Pointer.png"),
lshoulder = Image.load("Data/LON.png"),
rshoulder = Image.load("Data/RON.png")
}
I want my money back!?
LuMo
Posts: 410
Joined: Sun Aug 21, 2005 2:45 am
Location: Austria
Contact:

Post by LuMo »

array = table in lua

Code: Select all

-- Skin Arrays
Skins# = {
{
background = Image.load("Skins/Background.png"),
hold = Image.load("Data/Hold.png"),
battl = Image.load("Data/Battery Low.png"),
batth = Image.load("Data/Battery Half.png"),
battf = Image.load("Data/Battery Full.png"),
usba = Image.load("Data/USBON.png"),
baudio = Image.load("Data/Audio.png"),
bimage = Image.load("Data/Image.png"),
pointer = Image.load("Data/Pointer.png"),
lshoulder = Image.load("Data/LON.png"),
rshoulder = Image.load("Data/RON.png")
}
{
background = Image.load("Skins/Background2.png"),
hold = Image.load("Data/Hold2.png"),
battl = Image.load("Data/Battery Low2.png"),
batth = Image.load("Data/Battery Half2.png"),
battf = Image.load("Data/Battery Full2.png"),
usba = Image.load("Data/USBON2.png"),
baudio = Image.load("Data/Audio2.png"),
bimage = Image.load("Data/Image2.png"),
pointer = Image.load("Data/Pointer2.png"),
lshoulder = Image.load("Data/LON2.png"),
rshoulder = Image.load("Data/RON2.png")
}
} 

this codeholds 2skins
"Good artists copy, great artists steal."
Pablo Picasso
go2lumo.com
2Xtremes2004
Posts: 53
Joined: Wed Aug 31, 2005 1:43 am

Post by 2Xtremes2004 »

Ok, I got it put into my script, but it shows an error every time its suppose to blit an image. Do I need to go back through and edit my script to load from the array?

This is how it was set up:

Code: Select all

screen:blit(0, 0, background, 0, 0, background:width(), background:height(), false)
Do I change it to something like this?

Code: Select all

screen:blit(0, 0, Skin{background}, 0, 0, Skin{background}:width(), Skin{background}:height(), false)
...or something else. Sorry for being such a noob, but I'm slowly learning :-P Thx for all the help so far.
I want my money back!?
haust
Posts: 25
Joined: Sat Oct 01, 2005 12:37 am
Location: France

Post by haust »

Sorry but why the # symbol in Skins# ?? For fun or for some lua feature ??
flattspott
Posts: 22
Joined: Mon Aug 22, 2005 4:06 am

Post by flattspott »

I think you need a variable to track which skin is active

Since tables start with an index of 1, one is the starting point of the variable.

activeSkin = 1
to change the skin just increase the activeSkin variable




screen:blit(0, 0, Skin[activeSkin].background, 0, 0, Skin[activeSkin].background:width(), Skin[activeSkin].background:height(), false)
2Xtremes2004
Posts: 53
Joined: Wed Aug 31, 2005 1:43 am

Post by 2Xtremes2004 »

When I tried it like this:

Code: Select all

Skin = { 
{ 
background = Image.load("Skins/Background.png"), 
hold = Image.load("Data/Hold.png"), 
battl = Image.load("Data/Battery Low.png"), 
batth = Image.load("Data/Battery Half.png"), 
battf = Image.load("Data/Battery Full.png"), 
usba = Image.load("Data/USBON.png"), 
baudio = Image.load("Data/Audio.png"), 
bimage = Image.load("Data/Image.png"), 
pointer = Image.load("Data/Pointer.png"), 
lshoulder = Image.load("Data/LON.png"), 
rshoulder = Image.load("Data/RON.png") 
} 
{ 
background = Image.load("Skins/Background2.png"), 
hold = Image.load("Data/Hold2.png"), 
battl = Image.load("Data/Battery Low2.png"), 
batth = Image.load("Data/Battery Half2.png"), 
battf = Image.load("Data/Battery Full2.png"), 
usba = Image.load("Data/USBON2.png"), 
baudio = Image.load("Data/Audio2.png"), 
bimage = Image.load("Data/Image2.png"), 
pointer = Image.load("Data/Pointer2.png"), 
lshoulder = Image.load("Data/LON2.png"), 
rshoulder = Image.load("Data/RON2.png") 
} 
}
It gives me the following error:

Code: Select all

error: System/SYSTEM.LUA:70 '}' expected (to close '{' at line51)
near '{'
Error: No script file found.
Press start to restart
Any ideas, anyone?
I want my money back!?
ShUr1k3n
Posts: 42
Joined: Sun Oct 16, 2005 9:04 pm

Post by ShUr1k3n »

U must put a "," between "options" like this:

Code: Select all

Skin = {
{
background = Image.load("Skins/Background.png"),
hold = Image.load("Data/Hold.png"),
battl = Image.load("Data/Battery Low.png"),
batth = Image.load("Data/Battery Half.png"),
battf = Image.load("Data/Battery Full.png"),
usba = Image.load("Data/USBON.png"),
baudio = Image.load("Data/Audio.png"),
bimage = Image.load("Data/Image.png"),
pointer = Image.load("Data/Pointer.png"),
lshoulder = Image.load("Data/LON.png"),
rshoulder = Image.load("Data/RON.png")
&#125;,  < --------- HERE........
&#123;
background = Image.load&#40;"Skins/Background2.png"&#41;,
hold = Image.load&#40;"Data/Hold2.png"&#41;,
battl = Image.load&#40;"Data/Battery Low2.png"&#41;,
batth = Image.load&#40;"Data/Battery Half2.png"&#41;,
battf = Image.load&#40;"Data/Battery Full2.png"&#41;,
usba = Image.load&#40;"Data/USBON2.png"&#41;,
baudio = Image.load&#40;"Data/Audio2.png"&#41;,
bimage = Image.load&#40;"Data/Image2.png"&#41;,
pointer = Image.load&#40;"Data/Pointer2.png"&#41;,
lshoulder = Image.load&#40;"Data/LON2.png"&#41;,
rshoulder = Image.load&#40;"Data/RON2.png"&#41;
&#125;
&#125; 
Regards,

ShUr1k3n
LuMo
Posts: 410
Joined: Sun Aug 21, 2005 2:45 am
Location: Austria
Contact:

Post by LuMo »

oops forgot that little puppy ','
greets
"Good artists copy, great artists steal."
Pablo Picasso
go2lumo.com
2Xtremes2004
Posts: 53
Joined: Wed Aug 31, 2005 1:43 am

Post by 2Xtremes2004 »

So, this should work right?

Code: Select all

-- Default options
options = &#123; theme = "Skin1", music = "Song#1" &#125;
activeSkin = 1

-- Possible options for system config menu
possibleOptions = &#123;
   theme = &#123;
      displayName = "Themes",
      values = &#123;"Skin1, Skin2"&#125; &#125;,
   music = &#123;
      displayName = "Background Music",
      values = &#123;"Song#1", "Song#2", "Song#3"&#125; &#125;

Skin1 = Skin&#91;1&#93;
Skin2 = Skin&#91;2&#93;

Skin = &#123;
&#123;
background = Image.load&#40;"Skins/Background.png"&#41;,
hold = Image.load&#40;"Data/Hold.png"&#41;,
battl = Image.load&#40;"Data/Battery Low.png"&#41;,
batth = Image.load&#40;"Data/Battery Half.png"&#41;,
battf = Image.load&#40;"Data/Battery Full.png"&#41;,
usba = Image.load&#40;"Data/USBON.png"&#41;,
baudio = Image.load&#40;"Data/Audio.png"&#41;,
bimage = Image.load&#40;"Data/Image.png"&#41;,
pointer = Image.load&#40;"Data/Pointer.png"&#41;,
lshoulder = Image.load&#40;"Data/LON.png"&#41;,
rshoulder = Image.load&#40;"Data/RON.png"&#41;
&#125;,
&#123;
background = Image.load&#40;"Skins/Background2.png"&#41;,
hold = Image.load&#40;"Data/Hold2.png"&#41;,
battl = Image.load&#40;"Data/Battery Low2.png"&#41;,
batth = Image.load&#40;"Data/Battery Half2.png"&#41;,
battf = Image.load&#40;"Data/Battery Full2.png"&#41;,
usba = Image.load&#40;"Data/USBON2.png"&#41;,
baudio = Image.load&#40;"Data/Audio2.png"&#41;,
bimage = Image.load&#40;"Data/Image2.png"&#41;,
pointer = Image.load&#40;"Data/Pointer2.png"&#41;,
lshoulder = Image.load&#40;"Data/LON2.png"&#41;,
rshoulder = Image.load&#40;"Data/RON2.png"&#41;
&#125;
&#125;

screen&#58;blit&#40;0, 0, Skin&#91;activeSkin&#93;.background, 0, 0, Skin&#91;activeSkin&#93;.background&#58;width&#40;&#41;, Skin&#91;activeSkin&#93;.background&#58;height&#40;&#41;, false&#41;
Ok, I updated my script with the above code and now it gives me this error:

Code: Select all

error&#58; System/SYSTEM.LUA&#58;48&#58; attempt to index global 'Skin' &#40;a nil value&#41;
Error&#58; No script file found.
Press start to restart
Last edited by 2Xtremes2004 on Wed Oct 26, 2005 5:43 am, edited 1 time in total.
I want my money back!?
LuMo
Posts: 410
Joined: Sun Aug 21, 2005 2:45 am
Location: Austria
Contact:

Post by LuMo »

you can remove the following lines:

Code: Select all

Skin1 = Skin&#91;1&#93;
Skin2 = Skin&#91;2&#93; 
greets
"Good artists copy, great artists steal."
Pablo Picasso
go2lumo.com
2Xtremes2004
Posts: 53
Joined: Wed Aug 31, 2005 1:43 am

Post by 2Xtremes2004 »

Ok, I removed the two lines like you suggested and it will load the first skin fine, but it will not load Skin2.
I want my money back!?
LuMo
Posts: 410
Joined: Sun Aug 21, 2005 2:45 am
Location: Austria
Contact:

Post by LuMo »

could you upload the bunch of files in a zip?
then i have a look on it...
maybe you come to our irc room?

greets
lumo
"Good artists copy, great artists steal."
Pablo Picasso
go2lumo.com
2Xtremes2004
Posts: 53
Joined: Wed Aug 31, 2005 1:43 am

Post by 2Xtremes2004 »

I Finaly got it!!!! ;-P Turns out, all I needed was this:

Code: Select all

   selectedLevel = &#40;options&#91;"level"&#93;&#41;
   if skinSelected ~= selectedLevel then
      if selectedLevel == "Skin#1" then
         activeSkin = 1
         skinSelected = "Skin#1"
      elseif selectedLevel == "Skin#2" then
         activeSkin = 2
         skinSelected = "Skin#2"
      end
   end
Thx for the help LuMo, ShUr1k3n, and flattspott!
I want my money back!?
LuMo
Posts: 410
Joined: Sun Aug 21, 2005 2:45 am
Location: Austria
Contact:

Post by LuMo »

hehe thought that was straigt forward (that you have to change the value somehow ;) )
"Good artists copy, great artists steal."
Pablo Picasso
go2lumo.com
Post Reply