Git Product home page Git Product logo

Comments (1)

SteveBarnegren avatar SteveBarnegren commented on May 27, 2024

Hi Alan

Sorry for the delay in getting back to you!

I'm sure that you've probably either solved this by now or moved on to a different solution, but I'll answer the question anyway!

If I'm honest, I'm not sure exactly what the issue is with the code that you had at this point. I can give you some general advice on this type of issue though.

In a game, you often have some sort of state that you want to 'reset' back to how it was when you started. The thing that can catch you out is that something isn't exactly as it was in the beginning after the reset. Like you were experiencing here, you then have to try and track down which of the things you wanted to reset that is out of place, which can be a pain.

One trick to avoiding that problem is to put everything that needs to be reset under a single object that you can deallocate a reallocate. For instance, rather than having three variables that you need to reset back to their original positions, have one object that holds the three variables and then just create a brand new instance of that object. This way you know that everything is exactly how it was when you originally started.

One solution to this particular problem is to just reallocate the view controller, as this is the parent of the all of the properties that you need to reset. You might need to then put it in a parent view controller so that you have a persistent view on screen when you recreate it. That might not give you the right experience that you're looking for, but hopefully gives you the idea about how you might solve such an issue. If you want to get around that then you might be able to refactor the example implementation so that all of the state is kept under a child object that you can recreate within the view controller.

There are of course other approaches to solving these sorts of problems, but hopefully that at least points you in the right direction!

from swiftchess.

Related Issues (17)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.