简体   繁体   English

在我的kivy应用程序中加载纹理图集时出错

[英]Error while loading texture atlas in my kivy application

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. 我在python解释器中不断收到“错误加载纹理”。 I am new to kivy so my biggest inclination to what is wrong is my file structure or how im referencing via string. 我是kivy的新手,所以我最大的偏向是我的文件结构或如何通过字符串引用。 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. 很少有文档介绍如何在包含main.py和main.kv的文件夹中构造地图集文件,以及如何与kv文件中的地图集字符串相关联。

I have tried creating a new folder within the folder that contains main.py and main.kv and I named it textures. 我尝试在包含main.py和main.kv的文件夹中创建一个新文件夹,并将其命名为Textures。

The data structure looks like this 数据结构如下所示

C:\\Users\\User\\Desktop\\Main\\textures\\myatlas-0.png, myatlas.atlas C:\\ Users \\ User \\ Desktop \\ Main \\ textures \\ myatlas-0.png,myatlas.atlas

Main.py 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

<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 执行时,空白的白框出现在kivy应用程序中,并且python解释器中出现“错误加载纹理”

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'

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM