How to properly multi thread an RPG
Posted
by
Nagrom_17
on Game Development
See other posts from Game Development
or by Nagrom_17
Published on 2010-11-16T14:08:29Z
Indexed on
2012/11/14
23:22 UTC
Read the original article
Hit count: 262
I am working on an RPG type game in Java and I would like to know a few things relating to threading,
What is the best way to implement a "wait for this then do this" without hanging the whole thread? Like waiting for a player to move to a location then pick up an item? or to wait one second then attack?
Currently I am spawning new threads every time I need to wait for something, but that doesn't feel like the best solution.
Any help is appreciated.
EDIT: Clarification and an example of how I currently do things.
User clicks on an item The function walkToAndPickUp(item) is called which is basically this:
Make a new thread so we don't freeze the thread handling input while the player moves.
Tell player to move to the item
While the player is not at the item(The player moves through an update() function called in a different thread, I don't know how else to do it without freezing threads)
Repeat until the player is at the item
If the player is at the item then call delete item from map and add to inventory.
© Game Development or respective owner