font positioning is better.

This commit is contained in:
=
2014-09-08 18:39:45 -07:00
parent adec643666
commit dbae4fd0f7
7 changed files with 431 additions and 122 deletions

View File

@@ -6,8 +6,24 @@
[clojure.pprint]
[advent.pathfind])
(:import [com.badlogic.gdx.graphics Pixmap Pixmap$Filter Texture Texture$TextureFilter]
[com.badlogic.gdx.graphics.g2d TextureRegion]))
[com.badlogic.gdx.graphics.g2d TextureRegion]
[com.badlogic.gdx.scenes.scene2d.utils Align]))
(defn ensure-on-screen [talk]
(let [margin-width (* 0.05 (game :width))
minimum-x margin-width
maximum-x (- (game :width)
margin-width)
label-width (label! talk :get-width)
label-right (+ (:x talk) label-width)
]
(cond (> label-right maximum-x)
(assoc talk :x (- maximum-x label-width))
(< (:x talk) minimum-x)
(assoc talk :x minimum-x)
:else
talk
)))
(defscreen talking-screen
:on-show
(fn [screen entities]
@@ -20,12 +36,16 @@
:on-talk
(fn [{:keys [create-talk target-id text x y]} [entities]]
(let [font (bitmap-font "mainfont.fnt" )
(let [font (bitmap-font "ego/font.fnt" )
tr (bitmap-font! font :get-region)
width (/ (game :width) 1.5)
tx (.getTexture tr)
_ (texture! tx :set-filter Texture$TextureFilter/Linear Texture$TextureFilter/Linear)
talk (assoc (label text (style :label font (color :white)) ) :x (* 4 x) :y (* 4 y))]
(label! talk :set-font-scale 1)
talk (assoc (label text (style :label font (color :white))) :x (- (* 4 x) (/ width 2)) :y (* 4 y))
talk (ensure-on-screen talk)]
(label! talk :set-wrap true)
(label! talk :set-width width)
(label! talk :set-alignment Align/center)
(assoc entities target-id talk)))
:stop-talk

View File

@@ -98,7 +98,7 @@
house (texture "house.png")
overdirt (texture "overdirt.png")
music (sound "town-music.mp3")
_ (sound! music :loop)
;; _ (sound! music :loop)
]
{
:cursor {:id "cursor" :cursor-index 0 }
@@ -117,8 +117,7 @@
:interactions [{:mouse-in? (zone/box 258 100 281 160)
:click-fn (fn [screen entities [x y]]
(assoc-in entities [:ego :actions] [(actions/stop :ego)
(actions/talk :ego (str "The last time I went through that door, \n"
"Fangald turned me into a frog."))]))}]
(actions/talk :ego (str "The last time I went through that door, Fangald turned me into a frog."))]))}]
:scale-fn (scaler-fn-with-baseline 110 0.10 1.00)
:layers [(assoc background :x 0 :y 0 :baseline 0)
(assoc house :x 0 :y 0 :baseline 122)