Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8919277
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T05:58:44+00:00 2026-06-15T05:58:44+00:00

Alright I’ve tried to ask this before but I’m not really getting anywhere yet.

  • 0

Alright I’ve tried to ask this before but I’m not really getting anywhere yet. I’m hoping i can explain what i want to do well enough. i will past all the code I have so far below.

  • Im trying to create a 2D game just as practice to get to know pygame and python better.
  • The game will be basically like the NES Zelda game (first one)
  • Right now I want to recreate a one of the topdown screens. Simple sprites of 16×16 pixels on a grid.
  • Now with the great help of you guys I have already gotten a clue about how to create the grid in a nice compact def with two ‘for’ statements (above).

    def drawMapArray(maparray):
    for x in range(0, xTile):
        for y in range(0, yTile):
            current_tile = tile_dict[maparray[x, y]]
            screen.blit(current_tile, (x*spritesize, y*spritesize))
    
  • Now what i want to do is from another file, take a map to map out tiles on the grid from a png file. so if my screen was 8 by 4 tiles:

     1 0 2 2 2 3 2 3
     3 0 0 0 0 1 0 0 
     4 4 4 4 4 1 1 1
     1 1 1 3 3 3 4 4
    
     1 = thing1.png
     2 = thing2.png
     3 = thing3.png
     4 = thing4.png
    
  • So then somehow I could import that into the maparray so each tile had the right .png file showing up on the grid. How would i go about getting this to happen? Here is my code below.

    import numpy
    import pygame
    import sys
    from pygame.locals import *
    
    pygame.init()
    
    fpsClock = pygame.time.Clock()
    
    #print help(numpy)
    
    resmulti=3
    spritesize=16*resmulti
    resolution=(256*resmulti,224*resmulti)
    screen = pygame.display.set_mode((resolution[0], resolution[1]))
    pygame.display.set_caption("testing.")
    
    xTile = 2
    yTile = 2
    
    gameRunning = True
    groundArray = numpy.ones((xTile,yTile))
    ###################################
    ######### Image Manipulation ######
    ###################################
    def pngLoad(imgloc, size, flipx, flipy):
        img = pygame.image.load(imgloc).convert_alpha()
        if size > 1:
            #pygame.transform.scale(Surface, (width, height), DestSurface = None): return Surface
            img = pygame.transform.scale(img, (img.get_width()*size, img.get_height()*size))
        if flipx == 1:
            #pygame.transform.flip(Surface, xbool, ybool)
            img = pygame.transform.flip(img, True, False)
        if flipy == 1:
            img = pygame.transform.flip(img, False, True)
    
        return img
    
    ###################################
    ######### All Image Tiles #########
    ###################################
    tile_dict = {3 : pngLoad("link1.png", resmulti,0,0),
                 2 : pngLoad("shrub_01.png", resmulti,0,0),
                 1 : pngLoad("tanback.png", resmulti,0,0)
                }
    
    def drawMapArray(maparray):
        for x in range(0, xTile):
            for y in range(0, yTile):
                #Determines tile type.
                current_tile = tile_dict[maparray[x, y]]
                screen.blit(current_tile, (x*spritesize, y*spritesize))
    
    
    while gameRunning:
        drawMapArray(groundArray)
    
        for event in pygame.event.get():
            if event.type == pygame.QUIT:
                gameRunning = False
                break
    
        #Updates display and then sets FPS to 30 FPS.
        pygame.display.update()
        fpsClock.tick(30)
    
    pygame.quit()
    
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-15T05:58:45+00:00Added an answer on June 15, 2026 at 5:58 am

    This example that use a spritesheet for tiles, and numpy for a 2d array of tiles. https://stackoverflow.com/a/12665286/341744

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Alright, this is driving me nuts because my regex is working on Rubular, but
Alright so I have no idea how to even begin doing this But basically
Alright, I'm extremely new to programming so odds are this is a really easy
Alright. This may be difficult but I have been struggling for quite a bit
Alright I've been debugging the whole day but can't figure out what the problem
Alright, hoping someone can help. I've got a page used to search for employees.
Alright, so I'm about 90% sure that this isn't possible, but I thought I'd
Alright, I found out in this question that polling sockets does not scale, so
Alright, I am so close to finishing this I can taste it. Over the
Alright, I'm trying to figure out why I can't understand how to do this

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.