oakes / play-clj

A Clojure game library
The Unlicense
939 stars 73 forks source link

ui text-field will not focus #75

Closed floybix closed 9 years ago

floybix commented 9 years ago

Hi, I'm not sure where this problem comes from, it could be my misunderstanding but I am hoping you will be able to point me in the right direction.

This is in Nightmod. I have a game with multiple screens. One screen which is not initially rendered contains a text-field. However when I render that screen (I switch an atom to flag it to render) the text field will not respond to clicks or typing.

If I grab the border of the window and resize it, suddenly it will respond and the cursor starts blinking. Also, if I start the game with that ui screen visible, the text field will be responsive.

I've tried to get my head around the code, I thought it was related to (play-clj.core/update-stage! screen entities) but calling that from the repl didn't work -- specifically (#'play-clj.core/update-stage! (deref (:screen screen)) (deref (:entities screen)))

The code (Nightmod game) is at https://github.com/floybix/the-spider-riddles - sorry this is far from a minimal test case but again, hoping there is some obvious solution.

oakes commented 9 years ago

Hi, I'll look into this soon. By the way, there is an error that initially appears in your game because the update! call doesn't directly mutate the screen map; it just returns a new one. So, in the :on-show function for status-screen and spider-screen, you need to do this:

(let [screen (update! screen :camera (orthographic) :renderer (stage))]
  ; rest of code here
  )
floybix commented 9 years ago

The plot thickens... even within one screen (an overlay screen status-screen) I can reliably produce non-responsiveness in a text-button: if I change the position of a label entity (i.e. assoc :x) then suddenly the text-button is non-responsive. Until I manually resize the window.

I guess this is about how event listeners are instantiated, but I'm quite lost...

floybix commented 9 years ago

Just saw your comment, thanks. Might be worth doing that same (let) in the example in README.md.

BTW if you are running my game on latest commit you can see the text-button non-responsiveness once you pick up the sword and try to click on "Use".

Much and many appreciations.

oakes commented 9 years ago

Correct me if I'm wrong, but it looks like this problem is solved by your PR.

floybix commented 9 years ago

Yes that's right, thanks.

oakes commented 9 years ago

Hi, I just pushed a new version of play-clj. I updated the Nightmod repo to use it, and I noticed your game has an error now. In the create-entity-from-object-layer function, the getRectangle call is failing because it thinks it's a TextureMapObject instead of a RectangleMapObject. I haven't had time to look into it, but I wanted to alert you to see if it's something in your code or in play-clj. It uses a new version of libGDX so perhaps something changed.

floybix commented 9 years ago

I see, it is a change in libGDX, a good change that makes it simpler to create an entity from a map object layer.

On 19 March 2015 at 22:56, Zach Oakes notifications@github.com wrote:

Hi, I just pushed a new version of play-clj. I updated the Nightmod repo to use it, and I noticed your game has an error now. In the create-entity-from-object-layer function, the getRectangle call is failing because it thinks it's a TextureMapObject instead of a RectangleMapObject. I haven't had time to look into it, but I wanted to alert you to see if it's something in your code or in play-clj. It uses a new version of libGDX so perhaps something changed.

— Reply to this email directly or view it on GitHub https://github.com/oakes/play-clj/issues/75#issuecomment-83615541.

Felix Andrews / 安福立 http://www.neurofractal.org/felix/