minimap OnscreenImage

Im trying to create a minimap by simple placing an image on screen and some moving dots. But i having problems placing the image.

when i do this

self.root = OnscreenImage(image = mapimage, parent = base.a2dBottomRight)

it only shows 1/4 of the image (the top left), i thought base.a2dBottomRight was suposed to place the botton right of the image with the botton right of the screen.

is there any way to scale the image when i change the resolution os the screen?


  1. The problem is probably that your image is being parented correctly to the bottom corner of the screen, but the (0,0) point for the image is at the center of it. That would mean the center of the image is placed at the bottom right corner, causing you to only see 1/4 of it. Try moving the image up and left by half it’s size.

  2. There is. You can use the following code to get the width and height of the default window, in pixels, at any time.

props =
winX = props.getXSize()
winY = props.getYSize()

From there you just have set the scale of the mini map accordingly.

Since you’re parenting the image to base.aspect2d it should already be resizing to take up the same amount of the window when you change the window size, so I’m guessing you want to change that bevior? You might be better parenting it to render2d then.

thx for the reply

  1. You mean i should move with pos (eg: pos = (-1,0,1))? So i would have to do that for every image with diferent size or there is other way?

2)i cant realy see the diference betwen them, ive read on the manual but i cant see :slight_smile:

Using pos that way would work, yes. The alternative would be setting things up so that the (0,0) point for your image is in the appropriate corner. OnScreenImage can take an egg, instead of an image file, so you could do this with egg-texture-cards. You would just set the left, right, bottom, and top with the -g and -p flags when using egg-texture-cards. For example, if your image was 512 x 512 and you wanted in to .1 screen units square, you would do

egg-texture-cards -g -.1,0,0,.1 -p 512,512 -o myEgg.egg myImage.png

Then you would load that egg with loader.loadModel and supply it to the OnScreenImage. Or maybe you can give an egg filename to OnScreenImage, I don’t know.

The difference is that aspect2d compensates for the aspect ratio of a non-square window, and render2d doesn’t. So when parenting things to render2d, you need to scale them manually to adjust for the ratio of the window. Otherwise they may be distorted.


I’ve done it. Im using this code to keep the image the size I want

def setSizeInPixels(self, nodePath, numPixels, task):
        '''Sets the minimap in pixels'''
        props =
        height = float(props.getYSize())
        width = float(props.getXSize())
        hScale = (1/height)
        wScale = (1/width)
        pixelNode = NodePath("Pixel Node")
        nodePath.setScale(pixelNode, numPixels)
        alignTo(self.root, base.a2dTopRight,UR,O)
        return task.cont

alingTo can be found here [url]DirectGUI or nodepath alignment]