Reputation: 43
I am unable to open up a individual sprite within my atlas that I have compiled using kivy pillow. I keep getting 'Error loading texture' within the python interpreter. I am new to kivy so my biggest inclination to what is wrong is my file structure or how im referencing via string. There is very little documentation on how to structure the atlas files within the folder that contains main.py and main.kv and how that relates to your atlas string within the kv file.
I have tried creating a new folder within the folder that contains main.py and main.kv and I named it textures.
The data structure looks like this
C:\Users\User\Desktop\Main\textures\myatlas-0.png, myatlas.atlas
Main.py
from kivy.app import App
from kivy.uix.gridlayout import GridLayout
from kivy.properties import StringProperty, ObjectProperty
from kivy.uix.image import Image
from kivy.uix.widget import Widget
class Sprite(Widget):
pass
class MainApp(App):
def build(self):
self.load_kv('sprite.kv')
return Sprite()
if __name__ == "__main__":
app = MainApp()
app.run()
sprite.kv
<sprite.kv>
GridLayout:
cols:1
rows:1
size: root.width * .8, root.height * .125
center: root.width/2, root.height /1.1
Image:
id: note1
source: 'atlas://textures/myatlas-0/myatlas/N000'
size_hint: .5, 1
When executed blank white box appears in kivy app and 'Error loading texture' within the python interpreter
Upvotes: 0
Views: 735
Reputation: 344
Another important aspect what I found for non KV lang users (like me) is that you do not need to use the :class:
~kivy.atlas.Atlas
to load your atlas. The atlas://
prefix specifies that.
This is specified and in the documentation, but I was tempted to use the classical "method" call.
Example for Non KV lang users:
class YOUR_CLASS:
# atlas://path_to_your_atlas/atlas_name/id
background = StringProperty("atlas://data/img/default/background")
The bellow example will raise and TypeError
:
from kivy.atlas import Atlas
ATLAS:Atlas = Atlas("data/img/default.atlas")
class YOUR_CLASS:
background = StringProperty(ATLAS["background"])
Output |
---|
File "D:\Programs\Python3\lib\site-packages\kivy\resources.py", line 66, in resource_find |
if filename[:8] == 'atlas://': |
TypeError: 'kivy.graphics.texture.TextureRegion' object is not subscriptable |
Upvotes: 0
Reputation: 43
So I thought that you had to include the atlas with the page number and also specify the atlas name again before the referenced sprite. So this was a easy fix that I feel dumb about. But here is the correct source string for anyone with a little difficulty understanding the format.
GridLayout:
cols:1
rows:1
size: root.width * .8, root.height * .125
center: root.width/2, root.height /1.1
Image:
id: note1
source: 'atlas://textures/myatlas/N000'
Upvotes: 1