Welcome!
This is the community forum for my apps Pythonista and Editorial.
For individual support questions, you can also send an email. If you have a very short question or just want to say hello — I'm @olemoritz on Twitter.
Clear pixel art with FILTERING_NEAREST?
-
Recently I’ve been testing out my 64*64 pixel art with the pythonista scene module (which I’m more comfortable using).
I have been able to get clear images by individually setting the filtering mode of each imported image to FILTERING_NEAREST, which is a very tedious process.
Is there a way of setting the filtering mode of all the images in the whole scene to FILTERING_NEAREST, preferably in one line?
Here’s a short example of my current code:
import scene from scene import * x,y = get_screen_size() class MyScene(Scene): def setup(self): self.background_color = '#000000' self.pixel = Texture('GameAssets/lizard_profile.png') self.pixel.filtering_mode=FILTERING_NEAREST #imagine copying this for every image. very tedious. but it is the only method that i know which actually works. self.pixelNode = SpriteNode(self.pixel) self.pixelNode.position = (x/2,y/2) self.pixelNode.size = self.pixelNode.size*6 #makes the 64*64 pixel art more visible. self.add_child(self.pixelNode) def update(self): filtering_mode=FILTERING_NEAREST #this does not work. scene.filtering_mode=FILTERING_NEAREST #this also does not work. scene.run(MyScene(),orientation=LANDSCAPE,frame_interval=1, anti_alias=False, show_fps=True, multi_touch=True)
If there are no convenient methods for doing this, I’ll have to rescale my images at a higher resolution (although I’d prefer to stick with 64*64 PNGs due to the smaller file sizes).
-
@Vile Not sure that I correctly understand your question. If not, sorry and forget this post.
Else, Texture object can't be subclassed thus you can try via a function, like:class MyScene(Scene): def MyTexture(self,image): texture = Texture(image) texture.filtering_mode=FILTERING_NEAREST return texture def setup(self): self.background_color = '#000000' self.pixel = self.MyTexture('pzl:Blue6')
-
@cvp, heh, you were quicker. Here is my sample version of the traditional ”vector out boring setup into a factory function” pattern:
from scene import * class MyScene(Scene): def setup(self): self.background_color = 'black' self.pixel_node = self.make_pixels('spc:PlayerShip3Green') self.pixel_node.position = self.size/2 def make_pixels(self, file, parent=None): pixel = Texture(file) pixel.filtering_mode=FILTERING_NEAREST pixel_node = SpriteNode(pixel) pixel_node.size = pixel_node.size*6 parent = parent or self parent.add_child(pixel_node) return pixel_node run(MyScene())
-
@mikael, thanks for your help!
Although making a function is longer than one line, this should cut down my production time in the long run.
-
@cvp, I edited your code slightly because python was expecting a Node object:
import scene from scene import * x,y=get_screen_size() class MyScene(Scene): def MyTexture(self,image): texture = Texture(image) texture.filtering_mode=FILTERING_NEAREST return texture def setup(self): self.background_color = '#000000' self.pixel = self.MyTexture('pzl:Blue6') self.pixelNode = SpriteNode(self.pixel) self.pixelNode.position = (x/2,y/2) self.add_child(self.pixelNode) run(MyScene())
-