I am making a basic little game in Java and I want to have it so that I can use Hashmaps for binding keys..
e.g.- it would be like HashMap
and then I would do:
hashmap.add(Keys.up, VK_UP);
but this is where I get to my problem, How do i access the hashmap and choose which keys are pressed when the KeyListener returns a pressed key?
Sorry if this question seems baffling but I’m really confused too..
You insert key and value to the hashmap using
map.put(key,value)and retrieves a value based on a key usingmap.get(key)You need to make sure that the class of the keys overrides both
hashCode()andequals()[For library classes – it already is]