Open DesLandysh opened 2 months ago
You missed a small detail: context.convert_event(event)
actually returns a new event with the .position
attribute updated to tile coordinates:
tile_event = context.convert_event(event)
event.position.x # pixel X
tile_event.position.x # tile X
You missed a small detail:
context.convert_event(event)
actually returns a new event with the.position
attribute updated to tile coordinates:tile_event = context.convert_event(event) event.position.x # pixel X tile_event.position.x # tile X
As I figure out this must be place in EventHandler
class, isn't it? There weren't any mentions in tutorial till part 7 included (i'm on it). Methinks, we do not assign conversion in tutorial because we can use event.tile
, so since 15.0 context.convert_event(event)
returns event with tile coords instead of pixel coords by default. And we need divide by tile size or use event = context.convert_event(event)
(however, I foresee some issues in future with this assignation)
Because the tutorial still relies on event.tile.x
. context.convert_event
did not return a new event when the tutorial was written, it only updated the event in-place which is now deprecated by the latest versions of Python-tcod.
You only need to divide by the tileset size when you render consoles without a tcod context.
On this day,
event.tile.x
andevent.tile.y
is deprecated (they works fine, but...)If
tcod.console.Console
instead oldtcod.Console
, andtcod.event.KeySym.ANYKEY
instead of oldtcod.event.K_ANYKEY
is understandable intuitively (that's tiny Part 1-6 issues I've met), this issue requires some brains and logic actions, and I take a brave to open an issue.Issue code, _inputhandlers.py:
IDE (PyCharm, in my case) suggests the
event.position.x
andevent.position.y
respectively, however, it gets the pixel position instead of the tile position needed to proper functionality of this function.Solution (hardcoded version):
Number
10
I took from dejavu10x10_gs_tc.png font. I decided that every letter is the tile, so 10x10 is the tile size in pixels.Further, a learner should create a const.py file (methinks) to keep all constants, so it can be named as
tile_size
orTILE_SIZE
, or something else to replace ... // 10
by...// tile_size
.