Sprite in SFML style in Qt6, OpenGL ES 2.0, C++, Python, JavaScript for Android, Desktop, and WebAssembly
-
Hello,
This is my example that I will explain in the current topic. SFML-style means that working with a sprite is like in SFML. There are methods of the Sprite class with the same names like in SFML:
void setPosition(float x, float y); void setSize(float w, float h); void setTextureRect(const QString &spriteName);
The example parses a JSON file that was created in FreeTexturePacker.
Source code on GitHub:
- OpenGL ES 2.0, Qt6, C++
- OpenGL ES 2.0, PySide6, Python
- OpenGL ES 2.0, PyQt6, Python
- WebGL 1.0, JavaScript
Executables created by Qt C++:
- WebAssembly: https://65d032748f92293df6abc084--sweet-pavlova-c68026.netlify.app/
- EXE for Windows 10, 64-bit: sprite-in-sfml-style-opengles2-qt6-cpp-win10x64-exe.zip
- APK for Android 7-14: sprite-in-sfml-style-opengles2-qt6-cpp-android-7-14.apk
-
-
-
-
Hi,
While the demonstration is nice, I wouldn't use assets from that company. They are pretty trigger sensitive when it relates to their material.
-
@SGaist I don't know, maybe they don't pay attention if someone makes demos for training and not for selling. I think none of them will find this topic. I’ll try to leave these assets for now, but if someone from their company writes, I’ll replace them with other assets.
-
What is the difference between JSON parsing on PySide6 and PyQt6. On PyQt6 you need to call the toDouble() method, but on PySide6 you don't:
PyQt6:
gravity = root["gravity"].toDouble()
PySide6:
gravity = root["gravity"]
import sys from PyQt6.QtCore import QByteArray, QJsonDocument from PyQt6.QtWidgets import QApplication, QWidget class Window(QWidget): def __init__(self): super().__init__() content = "{ \"gravity\": -9.8 }" doc = QJsonDocument.fromJson(QByteArray(content.encode())) root = doc.object() gravity = root["gravity"].toDouble() # PyQt6 # gravity = root["gravity"] # PySide6 print("gravity =", gravity) print(type(gravity)) if __name__ == "__main__": app = QApplication(sys.argv) w = Window() w.show() sys.exit(app.exec())
-
@8Observer8 Good question, I currently don't know. You would need to compare the bindings generated by each variant to see what is done differently.