Author Topic: Properly Fitting Objects on Screen, by Screen Size!  (Read 2356 times)

0 Members and 1 Guest are viewing this topic.

Offline XVicarious

  • LV6 Super Member (Next: 500)
  • ******
  • Posts: 485
  • Rating: +45/-28
  • I F**king Love Twisty Puzzles
    • View Profile
    • XVicarious
Properly Fitting Objects on Screen, by Screen Size!
« on: August 01, 2013, 04:32:02 pm »
So my game is nearing completion (finally).   One of my last problems is making the level selection screen fit the proper amount of level "buttons"  per row on the screen depending on the screen's resolution.  I didn't notice this (well at least the extent of the problem) until I got my new 2013 Nexus 7, whose screen size is much larger than the previous generation's (720p vs 1080p).

Basically I'm having trouble dynamically fitting objects on the screen based on the screen's resolution.

The current code I'm using as of now to fit items on the screen:

Code: [Select]
elif gameState == "levelSelect":
            if doOnce:
                buttons = pygame.sprite.Group()
                buttList = []
                buttText = []
                buttRect = []
                numbers = 0
                for lv in android.assets.list():
                    if lv.endswith(".level"):
                        if (numbers > -1) and (numbers < 9):
                            h = 64
                            buttList.append(LevelButton((numbers+1)*128-64,h,str(numbers + 1)))
                        elif (numbers > 8) and (numbers < 17):
                            h = 192
                            buttList.append(LevelButton((numbers-8)*128-64,h,str(numbers + 1)))
                        buttRect[numbers].center = buttList[numbers]
                        numbers += 1
                numbers = 0
                for button in buttText:
                    screen.blit(button, buttRect[numbers])
                    numbers += 1
                doOnce = False

I'd like to point out I have the screen's native resolution stored in mynative[0][0] and mynative[0][1]

Its like I just hit a writer's sort of block while doing this.

Offline leafy

  • CoT Emeritus
  • LV10 31337 u53r (Next: 2000)
  • *
  • Posts: 1554
  • Rating: +475/-97
  • Seizon senryakuuuu!
    • View Profile
Re: Properly Fitting Objects on Screen, by Screen Size!
« Reply #1 on: August 01, 2013, 06:14:50 pm »
It's not the screen size that's larger, it's the resolution, and thus the DPI. I'm not too sure about games, but since the screen size doesn't change, you should be using the same layout. All you need to do is create XHDPI/HDPI resources, and the Android SDK should take care of the rest. (That applies to normal apps, not too sure about games. Try looking your problem up on Google.)

EDIT: Just noticed that you're not necessarily talking about Android, wups.
In-progress: Graviter (...)

Offline Sorunome

  • Fox Fox Fox Fox Fox Fox Fox!
  • Support Staff
  • LV13 Extreme Addict (Next: 9001)
  • *************
  • Posts: 7920
  • Rating: +374/-13
  • Derpy Hooves
    • View Profile
    • My website! (You might lose the game)
Re: Properly Fitting Objects on Screen, by Screen Size!
« Reply #2 on: August 02, 2013, 04:42:50 am »
when i used pygame i wrote me two functions: get_x and get_y. They both calculated x and y positions for a certain resolutions scaled to fit the screen.

Code: [Select]
def get_x(pxl):
    return (((x*100)/640)*pxl)/100
def get_y(pxl):
    return (((y*100)/480)*pxl)/100
this is for a 640x480 screen.

Also, check out my website
If OmnomIRC is screwed up, blame me!
Click here to give me an internet!