|
Hi, I've been playing about with Spritekit recently and have come across a somewhat novel issue. I've created a scene with three sprites, and can move them about happily. I then save, reset and reload, and that's where the funkiness starts - there is nothing amiss with the saving and loading functions, and everything else appears to be working well. I hope the following screenshots and explanation outline well enough what I'm talking about. 1) I generate three objects and their position is set at 0.0... 2) I move them to the following positions... 3) I then save and reload, there is an almost imperceptible shifting of the sprites... 4) I then move the top sprite back to the middle of the screen... 5) I then save and reload...and it jumps down to the bottom of the screen..! If I save and load without moving any of the sprites they stay in the same position. Here is the code that I'm using:
I am confident with the rest of the code, I just can't track down what I am getting wrong with my positioning. There is no scaling going on beyond the resizeFill. Whenever I move a sprite and save/reload it's almost like there's a move along the same vector, if that makes sense, and then it stays where it is. If anyone could shed any light, I'd be grateful. Many thanks, Jes |
|
You mentioned the positions are off when you save and reload. Show the code you use to save and reload. Set a breakpoint inside your save function, step through the code, and check the position of the sprites. Are the positions what you expect? If you open the file, are the sprite positions what you expect? I see the following line of code in your
You're converting to the parent's coordinate space when someone moves. Do you convert to the parent's coordinate space when saving and reloading? |
|
Thanks for the response. The save and load functions work exactly as expected, it's just that occaisionally it looks like the touchesEnded method doesn't fire correctly, or at least that how it appears. I've got things mostly working now apart from that occasional glitch, so I'll just pursue that avenue. |
TAKE YOUR SKILLS TO THE NEXT LEVEL If you like Hacking with Swift, you'll love Hacking with Swift+ – it's my premium service where you can learn advanced Swift and SwiftUI, functional programming, algorithms, and more. Plus it comes with stacks of benefits, including monthly live streams, downloadable projects, a 20% discount on all books, and free gifts!
Sponsor Hacking with Swift and reach the world's largest Swift community!
You need to create an account or log in to reply.
All interactions here are governed by our code of conduct.
Link copied to your pasteboard.