Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How do I use/cast OpaquePointer to Sprite? #50

Closed
iain-reid opened this issue May 2, 2024 · 3 comments
Closed

How do I use/cast OpaquePointer to Sprite? #50

iain-reid opened this issue May 2, 2024 · 3 comments

Comments

@iain-reid
Copy link

I'm pretty excited about this library - and the instructions worked perfectly!

However I'm running into an issue (that may be my misunderstanding of how to use PlaydateKit!)

When I use setUpdateFunction on a sprite - the closure defaults to passing me a variable called sprite (which makes perfect sense - I probably want access to that sprite to do something with it) - but the type is OpaquePointer...

Is there a way to cast this into a PlaydateKit Sprite? What is the best way to use this?

@finnvoor
Copy link
Owner

finnvoor commented May 2, 2024

Hi! Currently this isn't really possible, but I have a PR #32 that fixes this.

Instead of setting an update function on a sprite, you will be able to subclass Sprite and override the update function:

class MyGameObject: Sprite {
    override func update() {
        // update code
    }
}

I was waiting on some fixes to embedded swift, and currently the draw function can't be overridden/set due to a bug in the swift compiler, but it looks like the issues blocking the update function were fixed so I'll try to merge this PR later today.

@iain-reid
Copy link
Author

Looks like a good solution. Thanks for the quick response - and great work!

@finnvoor
Copy link
Owner

finnvoor commented May 2, 2024

done! example usage here:
https://github.com/finnvoor/PlaydateKitTemplate/blob/17a810ba7c7cb66edf0ee7bb409c508bb52377bb/Sources/PlaydateKitTemplate/Game.swift#L29-L43

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants