2D Tile Engine

Hello guys,

Currently I’m making a 2d game with only python and Panda3d (I’m a beginner yes). I wanna know how you guys make such a tile engine.
I allready have some textures and know how to get them working in Panda3D, but I just need to know how I can put them in such a tile engine :smiley:. Or if somebody has a script that would be awesome.

Thanks anyway.

hi and welcome to panda3d,

what you’r asking for was asked several times with different variations already. look here, you might find something useful.

https://discourse.panda3d.org/viewtopic.php?t=7045
https://discourse.panda3d.org/viewtopic.php?t=6380
https://discourse.panda3d.org/viewtopic.php?t=4443
https://discourse.panda3d.org/viewtopic.php?t=2851

long story short. create the tile geometry (usualy a square), load the texture , assign it, reparent to render, repeat until your level is complete.
if your performance drops due to hundrets of individual geoms, use flatten strong to reduce the number of geoms.
aside from that there is no fancy magic

Lately i began to make a tilebased kind of engine.
In my case is 3d, but i suppose you could do more or less the same but attaching the nodes to render2d instead of the normal render.

check it here:

discourse.panda3d.org/viewtopic.php?t=7360

anyway, i think that if what you want to do is pure 2d and you dont have knowledge about shaders pygame maybe would be a better option (?)
c

Thanks for the replies, this is what I was looking for :smiley:.

I still have a problem with the positions, i have this code now:

import direct.directbase.DirectStart
from direct.showbase.DirectObject import DirectObject
from pandac.PandaModules import Point2,Point3,Vec3,Vec4
from direct.task.Task import Task
from math import sin, cos, pi
import cPickle, sys

import direct.directbase.DirectStart
from pandac.PandaModules import *
from direct.interval.IntervalGlobal import *
from direct.task.Task import Task
import random

def loadObject(tex = None, pos = Point2 (0,0), depth = 100, scale = 10,
transparency = True):
obj = loader.loadModel(“Models/plane”)
obj.reparentTo(camera)
obj.setPos(Point3(pos.getX(), depth, pos.getY()))
obj.setScale(scale)
obj.setBin(“unsorted”, 0)
obj.setDepthTest(False)
if tex:
tex = loader.loadTexture(“Textures/”+tex+".png")
obj.setTexture(tex, 1)

return obj

class mygame(DirectObject):
def init(self):

grass = loadObject("grass", scale = 5,transparency = False)
tiles = ["grass.grass,grass,grass"]
print tiles

q = mygame()

run()

Now he sticks all the tiles to one position right? How can I make it work that he moves each tile to the next postion?

Thank you

The topic is a few days old, but if I may:

I’m not entirely clear on what you’re asking. If you mean to ask why they are always appearing the same place, then it appears to me that the problem is probably that you don’t seem to be feeding a position argument to your “loadObject” function. However, if you mean to ask how you might go about generating new points to feed to said function, then it depends, I think, on how you intend to use the system.

For example, should tiles always be placed on a fixed grid, or could they be placed anywhere? How do you want to load your levels - a large 2D array, perhaps, or a stream of objects and coordinates?