hi,
i made class that creates tiles in circle around camera (for grass and etc.)
it does some math and uses only camera.getX() and camera.getY().
it works perfect but when i set camera to pos x>0 y>0 my tiles center appears on coordinates 0,0 and then travels to coordinates x y (looks quite cool when lots of grass moves toward you
)
so i think that setpos not makes camera in that position but moves it there? is this right? and how should i fix this?
setPos() on the camera, or on any other NodePath, immediately sets the camera to that new position. There is no delay.
If you are seeing such a delay, it might be due to something else within your program that’s implementing it. For instance, maybe you copied code from someone else that moves the camera gradually to a new position and you didn’t realize it.
David
hmm, you r right
there’s something somewhere wrong in the code, maybe there would be a valounteer to dig up that problem
this is a code for the tiles
class Tile:
def __init__(self, x, y, size, content):
tmpsize = size/2
c = sqrt(2*tmpsize*tmpsize)
self.x = x
self.y = y
self.content = content
self.bottomLeftX = x - c
self.bottomLeftY = x - c
def __del__(self):
if self.content:
self.content.removeNode()
def distance(self, x, y):
return sqrt((self.x-x)*(self.x-x)+(self.y-y)*(self.y-y))
def getArea(self):
return (self.bottomLeftX,self.bottomLeftY)
class Tiles:
def __init__(self, contentF, tilesize = 10, distance = 100 ):
self.tilesize = tilesize
self.distance = distance
self.contentF = contentF
self.curentTileX = 0
self.curentTileY = 0
self.tiles = {}
def update(self, posX, posY):
#TODO: reiktu padaryt kad uzdetu paramsa kur paslinko
# ir tada is top[ puses pridetu
# o is kitus nuimtu
end = self.tilesize/2
recalc = False
if (posX + end)<self.curentTileX:
self.curentTileX = self.curentTileX - self.tilesize
recalc = True
if (posX - end)>self.curentTileX:
self.curentTileX = self.curentTileX + self.tilesize
recalc = True
if (posY + end)<self.curentTileY:
self.curentTileY = self.curentTileY - self.tilesize
recalc = True
if (posY - end)>self.curentTileY:
self.curentTileY = self.curentTileY + self.tilesize
recalc = True
if not recalc:
return
posX = self.curentTileX
posY = self.curentTileY
for x in range(posX-self.distance, posX+self.distance, self.tilesize):
for y in range(posY-self.distance, posY+self.distance, self.tilesize):
if not self.tileExists(x, y):
self.add(x, y)
self.remove(posX, posY)
def add(self, x, y):
self.tiles['%s' %str((x,y))] = Tile(x, y, self.tilesize, self.contentF(x,y))
def tileExists(self, x, y):
if str((x,y)) in self.tiles:
return True
return False
def remove(self, posX, posY):
for tile in self.tiles.keys():
if self.tiles[tile].distance(posX, posY)>self.distance:
del self.tiles[tile]
and this is ho i use it:
class Grass:
def __init__(self, terrain, camera):
...
self.camera = camera
self.tiles = Tiles(self.plant2)
...
def update(self):
self.tiles.update(self.camera.getX(), self.camera.getY())
and then jus use grass.update() in mainloop
here is full source http://www.mindes.info/tmp/panda3d/ketvirtas.zip
hey, ran your code and looks good, kinda reminded me of the original DeltaForce 1 shooter (without the shoothing). so I enjoyed it
Couldn’t understand exactly what it’s not working so I can give it a look…
ok thanks.
give me few more months and it will look like crysis
I am watching this topic, so as soon as you post your update I’ll be downloading and checking it out.
Good luck and plenty of inspiration