2d games

From what I have been able to gather, Panda3d in considerably faster than Pyglet and obviously faster than PyGame (considering it is basically an SDL wrapper). I want to create a 2d game that has a lot of effects that I don’t think Pyglet can handle. It seems like Panda3d is the way to go.

However, I’m a little nervous to use Panda3d for a 2d game. I’ve been looking into Panda3d for almost a week now. I searched Google for “Panda3d 2d” and it seems as though all the hits are of people wanting to use Panda3d for 2d games and it seems they have had little or no success.

I’m familiar with OpenGL to an extent, so I think I should be good to go if I just set up a 2d-ortho camera. It just seems like there would really be a lot more to it than that.

I looked into the Asteroids example and it covers a lot of the basics, but I would like something more in depth. Can you offer any insight on Panda3d and 2d games?

Thank you.

Panda can do it relatively easily; there are simply some convienience functions missing.

For example, to get coordinates in pixel coords, you could use this template. It is the base for my 2d hud stuff, all it does is allow you to use node.setPos(x,0,y) in pixel coordinates from the upper left hand of the screen and control the order in which they are drawn. Collisions would be harder as you would have to code them yourself; but there are ways around that. Also, images all have to be power of two for alot of computers which is slightly annoying.


#node everything is parented to, pixel coords from upper left corner (x,0,y)
pixelNode = NodePath(PandaNode('pixel node'))
pixelNode.reparentTo(render2d)
pixelNode.setPos(-1,0,1)	#the upper left corner
pixelNode.setScale(2.0/base.win.getProperties().getXSize(),1,-2.0/base.win.getProperties().getYSize())	

def SetDrawOrder(node,depth):
	#a lower depth will cause the node to be drawn earlier.
	node.setBin('fixed',depth)

def SetSize(node,width,height):
        #sets the scale in pixels
	node.setScale(width,1,-height)	#has to be negative or else the image will be upside down...

def createBox(texture):
      #creates a sprite which is positioned by the upper left hand corner.  Change the size by using setSize and reparent to pixel node to get a sprite that you can position and scale in pixels.

	#creates a 0-1,0-1 sprite on screen...
	vdata = GeomVertexData('', GeomVertexFormat.getV3t2(), Geom.UHStatic)
	vertex = GeomVertexWriter(vdata, 'vertex')
	uv = GeomVertexWriter(vdata, 'texcoord')
	prim = GeomTriangles(Geom.UHStatic)

	vertex.addData3f(0, 0, 1)
	vertex.addData3f(0, 0, 0)
	vertex.addData3f(1, 0, 0)
	vertex.addData3f(1, 0, 1)
	uv.addData2f(0,0)
	uv.addData2f(0,1)
	uv.addData2f(1,1)
	uv.addData2f(1,0)

	prim.addVertices(3,2,0)
	prim.addVertices(1,0,2)
	prim.closePrimitive()

	geom = Geom(vdata)
	geom.addPrimitive(prim)
	nodepath = NodePath(GeomNode('gnode'))
	nodepath.node().addGeom(geom)
	nodepath.setTransparency(1)
	nodepath.setTexture(loader.loadTexture(texture))

	return nodepath

Short answer: it is possible but you will most likely be fighting the system at one point or another; it is work-aroundable and you can implement whatever you want, but may take longer to get working than pygame or others.

You should check the “asteroids” sample out. It’s also 2d. But the plane seems to be using a mesh, I’m not sure. Anyway its an egg file.

Panda3D → Panda2D ? :wink:
looks like a nice idea, but i bet it won’t be as easy as pygame or other 2d packages.

@Makkura:

I’ve seen several excellent 2-d games produced using Panda3D. I wouldn’t be able to say whether it’s easier to use than a typical 2-d game engine, but it’s different. Certain things will be easier, and certain other things will be harder.

To write a 2-d game in Panda3D, it’s probably best if you get away from thinking in terms of pixels, and think instead in terms of objects and screen units. Panda is designed to take you away from pixels, and into a space more abstract than that. This makes operations like zooming and rotating perfectly natural and automatic.

On the other hand, most 2-d game engines historically deal with pixel-based rendering. If you want to write a game where you think with pixels instead of abstract units, you can still use Panda to do this, but it’s not what Panda is good at. You can, for instance, set an appropriate scale on render2d to scale the -1…1 range to 0…800 or whatever you window size is. You can also invert the vertical axis this way so that the (0, 0) corner is at the upper left. You’ll have to spend more time thinking about the proper alignment of your pixels to the screen, though, than you would in a normal 2-d engine.

David