A nooby question....

Hey guys! I have just recently been making my way through the manual and slowly learning my way through panda, and I would like to start experimenting a bit, and what I would like to know is if it is possibly to make a 2D Game of some sort in panda. Something like a scrolling game, or a platform style. I know that this program is specifically for 3D, but something 2D seems almost like a step down…so really what im wondering is is it possible.

Thanks!

yeah you can make a 2d game no problem. You just have to reparent every thing to aspect2d. Also learn how to use texture cards and remember to have all of the textures in power of 2 and you will be set.

well awesome! At least I know its possible now, thats really encouraging:D Where would I be able to find information on aspect2d, and texture cards… Also, this means I would be able to use 2D sprites as well without them being 3D…How would I do that?

anybody have any help on aspect2d or texture cards…even if its just a link or something, that would be awesome! Thanks!

egg-texture-cards: www.panda3d.org/manual/index.php/Autom … _Animation
aspect2d: www.panda3d.org/manual/index.php/Scene … ipulations

great! Thanks allot!

perhaps I could bother someone to write out a quick example of what the line of code should look like that tells panda to render something in render2d… The manual gives a nice description of what render2d is, but it really doesn’t give any examples…:frowning: For me, examples are a big part of my learning style:D

Thanks for all your help guys!

how about:

yourTextureCard = loader.loadModel("/path/to/your/file")
yourTextureCard.reparentTo(render2d)

untested code and its 4 o clock in the night. but it should still work.

Awesome! Thanks allot…I tested it, heres my code:

#Loads
import direct.directbase.DirectStart
from pandac.PandaModules import *

from direct.task import Task
from direct.actor import Actor
from direct.interval.IntervalGlobal import *
import math


#To load a test model
yourTextureCard = loader.loadModel("/Panda3D-1.5.2/models/maps/envir-rock2")
yourTextureCard.reparentTo(render2d) 

run() 

and whenever I try and run it, I keep getting this error

cammando.py
DirectStart: Starting the game.
Warning: DirectNotify: category ‘Interval’ already exists
Known pipe types:
wglGraphicsPipe
(all display modules loaded.)
:util(warning): Adjusting global clock’s real time by 5.30794e-006 seconds.
:loader(error): Couldn’t load file /Panda3D-1.5.2/models/maps/envir-rock2.egg: d
oes not exist.
Traceback (most recent call last):
File “cammando.py”, line 13, in
yourTextureCard.reparentTo(render2d)
AttributeError: ‘NoneType’ object has no attribute ‘reparentTo’

I’m not sure quite what it means…although I was able to find that theres somthing wrong in line 13.

It looks like the loader didn’t work because it returned None instead of a nodepath. Check to make sure the path string is correct or try a different model.

This would be a correct path:

yourTextureCard = loader.loadModel("/c/Panda3D-1.5.2/models/maps/envir-rock2") 

Or, most likely, since there’s a model path, this would work as well:

yourTextureCard = loader.loadModel("maps/envir-rock2") 

Though, neither would work anyway, because envir-rock2.jpg is a texture, not a model. Loading it as model would be useless. Try loading a model instead.

Please see this page for more details on path names.

but the picture I want is a JPG, How would I convert that into an egg…?

Images cannot be converted into eggs. Egg is a format that contains description of 3D models, and images are textures that you use in these meshes.

The texture card is not sprite. It is square polygon, and your image is painted on this polygon. As texture you can use image of any format that is supported by Panda.

You can use something like this if it is hard for you to use command line:

import os

# Path to the folder where your image is in:
workingFolder="C:\\My_Panda_Projects\\My_project\\"
# Name of the file:
textures = ["reticle.png"]
# Name for output texture card:
outputFile = "reticle-texture-card.egg"
# Consult the manual about other options
#arguments = ["-fps 4"]
arguments = [""]
# The path to egg-texture-cards.exe:
programFolder="C:\\Panda3D-1.5.2\\bin\\egg-texture-cards.exe"



delimiter = " "
if len(textures) > 1:
    textures = delimiter.join(textures)
else:
    textures = textures[0]
if len(arguments) > 1:
    arguments = delimiter.join(arguments)
else:
    arguments = arguments[0]

commandArguments = ["-o", outputFile,
                    str(arguments),
                    str(textures)]

commandArguments=str(delimiter.join(commandArguments))

def makeCards():
    os.system(programFolder + " " + commandArguments)

makeCards()

Sorry Ryan, rather then giving real help they guys on the thread been just confusing you. Use this code:

import direct.directbase.DirectStart
from pandac.PandaModules import *
from random import uniform,random
 
def load2dSprite(name):
    """ 
        loads 2d sprite makes a texture card 
        with as the same size as textures 
    """  
    spriteTexture = loader.loadTexture(name)
    cm = CardMaker("blob maker")
    x = spriteTexture.getXSize()/2
    y = spriteTexture.getYSize()/2
    cm.setFrame(-x,x,-y,y)
    sprite = aspect2d.attachNewNode(cm.generate())
    sprite.setTexture(spriteTexture)
    sprite.setTransparency(True)
    return sprite
loader.load2dSprite = load2dSprite

def keepAspectWindowPixelSize():
    """ 
        keeps the aspect ratio at pixel size
        so that load 2d sprites would map pixel to pixel
    """  
    aspect2d.setScale(2./base.win.getXSize(), 1, -2./base.win.getYSize())
base.accept('aspectRatioChanged', keepAspectWindowPixelSize )        


# ---------- your game and crap

level = loader.load2dSprite('maps/grid.rgb')
for i in range(100):
    sprite = loader.load2dSprite('maps/envir-tree2.png')
    sprite.setX(random()*300-150)
    sprite.setZ(random()*300-150)
    sprite.setScale(.1)

run()

It does 3 things:
1 it show you how to create a texture card automatically when you load an image.

2 it shows the code needed to make aspect2d to have similar pixel sizes as the screen (and the texture loader)

3 it shows you how to use it in 3d world grid by creating a map and putting brushes around it. Note you can still use all the scale/node path features of panda3d.

Good luck, ask if you have any more questions!

Treeform, why did you disregard non-powers of 2 size images ?
Use PNMImageHeader to get the real size.

because if his image is not power of 2 its going to render slowly on my card (probably in software or some thing) . Yet panda will stretch/shrink it for you to fit but why would some one make a non power of 2 sprite in the first place. If i use this system i could see that i made an error with the non power of 2 sprite while in the other i don’t.

PS in really i was just too lazy and justifying my way of doing it this way.

Hey, thanks treeform! That helps allot! It Worked Perfectly! I’m going to fiddle around some more ans see what I can come up with.

import direct.directbase.DirectStart
from pandac.PandaModules import *
from random import uniform,random
 
def load2dSprite(name):
    """
        loads 2d sprite makes a texture card
        with as the same size as textures
    """ 
    spriteTexture = loader.loadTexture(name)
    cm = CardMaker("blob maker")
    x = spriteTexture.getXSize()/2
    y = spriteTexture.getYSize()/2
    cm.setFrame(-x,x,-y,y)
    sprite = aspect2d.attachNewNode(cm.generate())
    sprite.setTexture(spriteTexture)
    sprite.setTransparency(True)
    return sprite
loader.load2dSprite = load2dSprite

def keepAspectWindowPixelSize():
    """
        keeps the aspect ratio at pixel size
        so that load 2d sprites would map pixel to pixel
    """ 
    aspect2d.setScale(2./base.win.getXSize(), 1, -2./base.win.getYSize())
base.accept('aspectRatioChanged', keepAspectWindowPixelSize )       


# ---------- your game and crap

level = loader.load2dSprite('maps/grid.rgb') 
for i in range(100):
    sprite = loader.load2dSprite('maps/envir-tree2.png')
    sprite.setX(random()*300-150)
    sprite.setZ(random()*300-150)
    sprite.setScale(.1)

run() 

level = loader.load2dSprite(‘maps/grid.rgb’)
I take it that this loads my background image? Am I right

def load2dSprite(name):
And this loads my game character or sprite…

thanks again for answering all my nooby questions:D Ill get this sooner or later.