0

I'm trying to render! a simple label on the on-render screen function, but it doesn't work. All I get is a blank screen.

It took me some time but I finally found that this happens when I return something else but the label. For example, this works:

(defscreen main-screen
  :on-show
  (fn [screen entities]
    (update! screen :renderer (stage))
    [])

  :on-render
  (fn [screen _]
    (clear!)
    (render! screen [(label "Hello, world!" (color :white))])))

This doesn't (all that's changed is the last line on on-render):

(defscreen main-screen
  :on-show
  (fn [screen entities]
    (update! screen :renderer (stage))
    [])

  :on-render
  (fn [screen _]
    (clear!)
    (render! screen [(label "Hello, world!" (color :white))])
    ["I just wanna pass my own data here, ugh.."]))

For testing, I replaced the label with texture and it did work.

What's causing this? it seems so arbitrary (the label I evaluate to in the first example gets completely ignored anyway! so why do I have to pass it? I don't get what's going on).

P.S. creating the label on every frame is intentional in this case, and I know I could just set it from one I make in on-show, but I tried to be a bit more dynamic. I also tried to put a Thread/sleep after render! to make sure I have a visible time-window between rendering & clearing.

I'm a complete beginner I'd like to know why the above doesn't work in addition to how can I fix it?

MasterMastic
  • 20,711
  • 12
  • 68
  • 90

1 Answers1

0

checkout the play-clj's defscreen-doc , in particular:

All functions take a screen map and entities vector as arguments, and return the entities list at the end with any desired changes. If a function returns nil, the entities list is not changed.

You neither return nil nor the (optionally changed) entities, but a vector with a string.

I expect that is the reason for the non-functioning code - haven't tested it though.

What is your intention with your "own data"?

birdspider
  • 3,034
  • 1
  • 16
  • 25
  • The entities I'm trying to have is a vector with one element which is a map of my game's state. I wanted to make a label with text from the state and `render!` it. This is how I've done it for my `clear!` color and my textures' drawing, and everything is rendered except that label. – MasterMastic Feb 19 '16 at 14:42