Hi everyone
My Android game is in certification phase on the Samsung app store, and I got feedback, that my Level Selecting Screen isn’t responsive to the different display resolutions. So I’m struggling how to make that.
Atm my Screen consists of three arrays, which are overlaid: One that handles the number of columns and levels in a column, one for the level image (solved or unsolved level) and one with a button which displays, how good you were in the solved levels. I thought of following methods to solve the problem:
- Actually it would be easy to replace the hardcoded numbers for the column placement and size, but the textures would get cropped or distorted afaik (I had a lot of trouble with this at first).
-
- This in turn could be fixed by using drawTexture instead of Label, but if I’m not mistaken you have to set the position for drawTexture and this would mess with my placement in the columns/Areas. And I would still need Buttons but those could be made “empty” over two arrays of drawTextures.
-
- Or I could place them manually in the editor, but if so, I think there would be problems with the overlay and the changing textures for the “How-good-you-were-images”.
So I couldn’t come to a satisfying solution by myself. Do you have any tips for me, how I could/should solve this problem? This is my first real game and I never coded before, so please excuse me if I ask stuff that is some kind of obvious or if my code looks like a complete mess. Also my comments are in german because I had to make notes for myself to understand what i actually coded ^^"
#pragma strict
// levels
public var levelSceneIndexStart:int = 1; // Welches ist das erste Level im Index, dass ein Spiellevel ist?
private var levelSceneIndexEnd:int; // Welches ist das letzte Level im Index, dass ein Spiellevel ist?
public var levelSelectImgArray:Texture2D[]; // Array mit Texturen für aktive Levels
public var levelSelectGrayImgArray:Texture2D[]; // Array mit Texturen für inaktive Levels
public var highscoreImgArray: Texture2D[];
public var backButtonImg:Texture2D; // Textur für Back zum Hauptmenü Button
public var deleteButtonImg: Texture2D;
private var numberColumns: int= 5;
private var numberLevelsInColumn: int= 10;
var myGUISkin: GUISkin;
function Start () {
levelSceneIndexEnd = levelSceneIndexStart+levelSelectImgArray.Length-1;
}
function Update () {
}
function loadLevel(index:int){
Application.LoadLevel(index); // Level wird nach mitgegebener Indexnummer geladen
}
function showLevelButton(i:int){
if(getHighestSolvedLevelAsLevelNr()>=i i<levelSelectImgArray.Length){ //falls die mitgegebene Indexnummer <= das grösste gelöste Level +1 (+1 weil das nächste Level auch gespielt werden darf) in PlayerSettings
GUILayout.Label(levelSelectImgArray[i]);
}else if(i<levelSelectImgArray.Length) {
GUILayout.Label(levelSelectGrayImgArray[i]); // falls die mitgegebene Indexnummer >= das grösste gelöste Level in PlayerSettings: Nur Bild kein Button
}
}
function showScoreButton(i:int) {
if(getHighestSolvedLevelAsLevelNr()>=i i<levelSelectImgArray.Length){
if (GUILayout.Button(highscoreImgArray[getLevelScoreFromPrefs(i+levelSceneIndexStart)])){ // ... wird ein Button erstellt mit Bild aus dem Array
audio.Play();
loadLevel(i+levelSceneIndexStart); // Level wird geladen: Indexnummer des ersten Spiellevels + Nummer des Buttons im Array
}
}
}
function OnGUI(){
GUI.skin= myGUISkin;
// var guiHeight = levelSelectImgArray.Length*100/4+100; // Alle Buttons mit 40 Höhe + 10 Lücke durch zwei (also in der Mitte der Spalte)
//–––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––
for(var i=0; i<numberColumns;i++) {
GUILayout.BeginArea( Rect((40+i*130),120,120,Screen.height-120));
for(var j=0;j<numberLevelsInColumn;j++) {
var levelNummerLevel: int = (i*numberLevelsInColumn+j);
showLevelButton(levelNummerLevel);
}
GUILayout.EndArea();
}
for(var k=0; k<numberColumns;k++) {
GUILayout.BeginArea( Rect((40+k*130),120,120,Screen.height-120));
for(var l=0;l<numberLevelsInColumn;l++) {
var levelNummerScore: int = (k*anumberLevelsInColumn+l);
showScoreButton(levelNummerScore);
}
GUILayout.EndArea();
}
//–––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––
// highest level
// GUI.Label(Rect(10, 10, 200, 40), "highest level in prefs:"+getHighestSolvedLevelAsLevelNr()); // Welches ist das höchste gelöste Level (debug)
if (GUI.Button(Rect(10, 10, 100, 100), backButtonImg)){ // Button für zurück ins Hauptmenü, 10 nach Levelbuttons
audio.Play();
Application.LoadLevel("startScreen"); // Hauptmenü laden
//gamelogicScript.SetStatus("game","", j);
}
if (GUI.Button(Rect(10, Screen.height-110, 100, 100), deleteButtonImg)) {
audio.Play();
PlayerPrefs.DeleteAll();
}
if (GUI.Button(Rect(Screen.width-110, Screen.height-110, 100, 100), " ")) {
audio.Play();
PlayerPrefs.SetInt("HighestSolvedLevel", levelSceneIndexEnd);
}
}
function getHighestSolvedLevelAsLevelNr():int{
return PlayerPrefs.GetInt("HighestSolvedLevel"); // Returnt den Index des höchsten gelösten Levels und subtrahiert den Index des ersten Levels
}
function getLevelScoreFromPrefs(index:int):int{
return PlayerPrefs.GetInt("Score"+index); // Returnt die Highscore für die jeweilige Indexnummer
}