• Announcements

    • khawk

      Download the Game Design and Indie Game Marketing Freebook   07/19/17

      GameDev.net and CRC Press have teamed up to bring a free ebook of content curated from top titles published by CRC Press. The freebook, Practices of Game Design & Indie Game Marketing, includes chapters from The Art of Game Design: A Book of Lenses, A Practical Guide to Indie Game Marketing, and An Architectural Approach to Level Design. The GameDev.net FreeBook is relevant to game designers, developers, and those interested in learning more about the challenges in game development. We know game development can be a tough discipline and business, so we picked several chapters from CRC Press titles that we thought would be of interest to you, the GameDev.net audience, in your journey to design, develop, and market your next game. The free ebook is available through CRC Press by clicking here. The Curated Books The Art of Game Design: A Book of Lenses, Second Edition, by Jesse Schell Presents 100+ sets of questions, or different lenses, for viewing a game’s design, encompassing diverse fields such as psychology, architecture, music, film, software engineering, theme park design, mathematics, anthropology, and more. Written by one of the world's top game designers, this book describes the deepest and most fundamental principles of game design, demonstrating how tactics used in board, card, and athletic games also work in video games. It provides practical instruction on creating world-class games that will be played again and again. View it here. A Practical Guide to Indie Game Marketing, by Joel Dreskin Marketing is an essential but too frequently overlooked or minimized component of the release plan for indie games. A Practical Guide to Indie Game Marketing provides you with the tools needed to build visibility and sell your indie games. With special focus on those developers with small budgets and limited staff and resources, this book is packed with tangible recommendations and techniques that you can put to use immediately. As a seasoned professional of the indie game arena, author Joel Dreskin gives you insight into practical, real-world experiences of marketing numerous successful games and also provides stories of the failures. View it here. An Architectural Approach to Level Design This is one of the first books to integrate architectural and spatial design theory with the field of level design. The book presents architectural techniques and theories for level designers to use in their own work. It connects architecture and level design in different ways that address the practical elements of how designers construct space and the experiential elements of how and why humans interact with this space. Throughout the text, readers learn skills for spatial layout, evoking emotion through gamespaces, and creating better levels through architectural theory. View it here. Learn more and download the ebook by clicking here. Did you know? GameDev.net and CRC Press also recently teamed up to bring GDNet+ Members up to a 20% discount on all CRC Press books. Learn more about this and other benefits here.

Archived

This topic is now archived and is closed to further replies.

CodyVa

[java] Thread error(or lack of error), not doing restarting.

4 posts in this topic

I don''t know what i''m doing wrong!!! The only thing i can think of is when stop is called..somehow it''s called twice? which makes the thread not start the next time start() is called. The Problem is when i put my mouse in the window it starts running the thread okay. when i take out the mouse it stops the thread as it supposed to... but when i put the mouse back in again it doenst'' restart the thread? any suggestions? (any coding tips will be helpfull to) Here''s the relevant code i think. Public boolean mouseEnter(Event evt, int x, int y) { try { m_tthread.start(); //the thread is member of the main class } //as in, m-tthread = new Thread(this); catch (IllegalThreadStateException itse) { System.out.println(itse.toString());//don''t know if this } //works it never //showed up return true; //so it returns and no other calls are made right //even if it didn''t handle it correctly Public boolean mouseExit(Event evt, int x, int y) { if (m_tthread.isAlive()) { m_tthread.stop(); } return true; } Public void run() { while (true) { //TimeIn is just an object member in the main class. TimeIn = Long.toString(System.currentTimeMillis()); try { repaint(); Thread.sleep(250); } catch (InterruptedException ie) { m_tthread.stop(); } } }
0

Share this post


Link to post
Share on other sites
My suggestion would be to put some diagnostic print statements into your mouse handler methods. It could be that one or both of them is being called more often or at different times than you expect.
0

Share this post


Link to post
Share on other sites
Thread.stop() is deprecated, don''t use it. Instead of
while(true) {
...
}
in your run method do a
while(t_running) {
...
}

then instead of Thread.stop() you just set the boolean t_running = false. When you want to start the thread running again set t_running=true then call Thread.run();
0

Share this post


Link to post
Share on other sites
my class has "implements runnable" in it...
and the thread is
m_tthread = new Thread(this);
right???
where do i get t_running from?


The thread stops when the loop ends right?


so me setting a flag doens''t actually start the thread..it just allows the loop to happen right?

0

Share this post


Link to post
Share on other sites
Well, if I understand what you're asking properly, the problem is this: You can't start a thread that's already been stopped.

Hmm... I'm not explaining well. Once a thread has been run with its start() method, it can't be started again. You have two options: Either create a new thread each time you want to run it, or set some sort of pause() and unpause() methods in your class.

The second is probably preferable, as far as system resources go. It shouldn't be too much trouble to rig up something with wait(), notify(), and some flag. Maybe something like this:
    
private boolean paused = false;

run() {

//start your while loop here, then follow immediately
//with this block:


if (paused) {
synchronized (this) {
try { wait () } catch (InterruptedException e) {}
}//synchronized

}//if


//the rest of the while loop


}//run()

private synchronized void pause() {
paused = true;
}//pause()

private synchronized void unpause() {
paused = false;
notify();
}//unpause



I think that would do the job you want, without the hassle of creating a new thread every time you want to restart the animation.

(Edited: Oops, forgot to synchronize the wait() call...)


Edited by - c_wraith on September 19, 2000 8:52:40 PM
0

Share this post


Link to post
Share on other sites