This is kinda weird problem , I’m trying to create a parallax background for a 2D game,
so ofcourse I would need different layers of background to get the effect, and so I thought of creating a list which contains each of this layer using a for loop (i thought it would be efficient just to create a loop and add all the layers to be in one list) And yes it does load and render the image, but except for the first layer it loads, all the other background layers are of very low quality why so
When i load them each layer without using a for loop, it does give back crips images.
As you can see there is a clear difference in the image quality among them, eventhough they are the same image.
My code is a bit shaby but this is my game file
from direct.showbase.ShowBase import ShowBase
from panda3d.core import loadPrcFileData
from direct.task import Task
from panda3d.core import Texture,TransparencyAttrib
#PRC FILE DATA
prc_data = """
show-frame-rate-meter 1
win-size 1280 720
window-title Sky
"""
loadPrcFileData('',prc_data)
class MyApp(ShowBase):
def __init__(self):
ShowBase.__init__(self)
def background_layers(): #This function tries to load and render background layers with the help of ApplyTextoModel functio
self.layers = []
num = 2 # number of layers
#Loading backgrounds
for i in range(num):
layer = self.ApplyTextoModel('models/plane.egg',f'city/{6+i*-1}.png',True,True,[1280/5,720/5])
self.layers.append(layer)
#rendering backgrounds
for i in range(num):
obj = self.layers[i]
obj.reparentTo(self.render)
background_layers()
def ApplyTextoModel(self,obj_loc,tex_loc,true_size,transparency,obj_res):
obj = self.loader.loadModel(obj_loc)
obj.setScale(obj_res[0],1,obj_res[1])
tex = self.loader.loadTexture(tex_loc)
if transparency:
obj.setTransparency(TransparencyAttrib.MAlpha)
try:
if true_size:
tex.setWrapV(Texture.WM_clamp)
tex.setWrapU(Texture.WM_clamp)
obj.setTexture(tex)
print("Texturing Successfully applied",true_size)
else:
obj.setTexture(tex)
print("True_size not applied",)
except:
print("Texturing Failed")
return(obj)
app = MyApp()
app.run()
If anyone knows how to fix this please guide me through.
Thanks