Results 1 to 4 of 4
  1. #1
    Join Date
    Aug 2012
    Posts
    6

    Question Need some help with VTM5: Independent Sprite Speeds (SOLVED)

    Hi all,

    I have been following the VTMs for Evil Monkeys from three through to five, however I am stuck on the Independent Sprite Speeds video. The game no longer shows any monkeys, and fireballs seem to start one tile away and stop about two further tiles away.

    I believe the issue is related to the timers. I am using wxWidgets 2.9.4 and in this version the wxTimer code as shown in the VTMs has been deprecated. So I have tried to replace the code with the new wxTimer and also with wxStopWatch. It has worked until this VTM.

    Things I have tried so far:
    * Watching the VTMs at least twice and making sure all code works properly before moving on to the next VTM
    * The Thread Of Information
    * The wxWidgets documentation.
    * Google
    * Experimenting with wxTimer and wxStopWatch

    Can someone please suggest what I can do to fix this?
    Last edited by tashycat; 11-02-2012 at 08:58 AM.

  2. #2
    Join Date
    Mar 2011
    Posts
    195
    Hard to say without seeing some code.

  3. #3
    Join Date
    Jun 2003
    Location
    Trier, Germany
    Posts
    1,350
    since you already suspect that the timer is the guilty component, that's where you should start. the usual way to tackle this kind of problem is to do some testing. that is, you run the timer-related code and check if the outcome is what you expected. pay special attention to corner cases (e.g. parameter values that cause an if-clause to use a different code path) since this is where stuff usually breaks.

    you may test either manually using a debugger and console output, or by writing a program that does the testing for you. the latter has the huge advantage that you can rerun the test at any time to ensure the tested component is still working as expected. since testing is an integral part of real-world software development, there are a lot of tools that help you with this (i found google.test to be especially beginner-friendly).

    once you are done with the testing you have either found and fixed a bug in the timer code or not. in either case, once all tests pass, you know that the timer code is working correctly and hence, if the erroneous behavior is still there, it must be caused by something else. in that case you can either continue writing tests for components or use the debugger to track down this specific error manually.

    mind you that this kind of bug-hunting is a software-developer's bread-and-butter. code almost never works as expected at first and it is vital to develop techniques that allow you to hunt down errors quickly. so this is in fact an excellent training exercise for you. if you still feel lost and need some advice on debugging techniques, feel free to come back and ask.

  4. #4
    Join Date
    Aug 2012
    Posts
    6

    Lightbulb

    Thanks for your tips ComicSansMS. I did manage to figure out a solution, however it was not due to testing issues but because I didn't fully understand how wxTimer and wxStopWatch worked with each other (the wxWidgets documentation gives little detail about this). Basically in earlier version of wxWidgets there was one global timer. Now wxWidgets requires one timer to be initialised and then one or more stopwatches to be used, allowing greater flexibility in the use of timers.

    Anyhow here's my solution for those experiencing the same problem.

    In AppFrame.h I left the wxTimer object and added a wxStopWatch object:

    Code:
    	wxTimer *m_timer;
    	wxStopWatch *m_stopwatch;
    In the AppFrame constructor I replaced the code shown in the VTM and initialised m_timer and m_stopwatch;

    Code:
    	// Deprecated code
    	//m_timer = new wxTimer(this, ID_TIMER);
    	//srand(wxGetElapsedTime(false));
    	//wxStartTimer();
    
    	// New wxTimer code
    	m_timer = new wxTimer(this, ID_TIMER);
    	srand(m_timer->GetInterval()); // hope this works, seems to!
    	m_timer->Start();
    
    	// wxStopWatch code
    	m_stopwatch = new wxStopWatch();
    	m_stopwatch->Start(UPDATE_TIME);
    The destructor contains code to delete the objects:

    Code:
    	m_timer->Stop();
    	delete m_timer;
    
    	m_stopwatch->Pause();
    	delete m_stopwatch;
    m_timer->Stop() calls replaced with a call to the equivalent stopwatch method:

    Code:
            //m_timer->Stop();
            m_stopwatch->Pause();
    m_timer->Start(UPDATE_TIME) calls replaced with a call to the equivalent stopwatch method:

    Code:
            //m_timer->Start(UPDATE_TIME);
            m_stopwatch->Start(UPDATE_TIME);
    The call to level->update() in the AppFrame::updateGame method passes the return value from m_stopwatch->Time();:

    Code:
            //level->update(m_timer->GetInterval());
            level->update(m_stopwatch->Time());
    Running this solution shows the game to work exactly as seen at the end of VTM5 - Independent Sprite Speeds. The evil monkeys chase the player with increasing speed in each new level, and the fireballs shoot exactly as expected (either into a wall or an evil monkey).

    Hope this helps anyone having the same issue :-)

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •