Advertisement
Guest User

Untitled

a guest
Jun 9th, 2017
76
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. (ns dinjin.core
  2.   (:import [com.badlogic.gdx Game Gdx Graphics Screen]
  3.            [com.badlogic.gdx.graphics Color GL20 Texture]
  4.            [com.badlogic.gdx.graphics.g2d BitmapFont SpriteBatch]
  5.            [com.badlogic.gdx.scenes.scene2d Stage]
  6.            [com.badlogic.gdx.scenes.scene2d.ui Label Label$LabelStyle]))
  7.  
  8. (gen-class
  9.   :name dinjin.core.Game
  10.   :extends com.badlogic.gdx.Game)
  11.  
  12. (def texture-state (atom {:sprite nil :texture nil}))
  13.  
  14. (defn render
  15.   ""
  16.   [delta]
  17.   (.glClearColor (Gdx/gl) 0 0 0 0)
  18.   (.glClear (Gdx/gl) GL20/GL_COLOR_BUFFER_BIT)
  19.  
  20.   ;; This works, but instantiates every loop
  21.   ;; (doto (SpriteBatch.)
  22.   ;;   (.begin)
  23.   ;;   (.draw (Texture. "clojure.png") 50.5 50.5)
  24.   ;;   (.end))
  25.  
  26.   ;; Throws: No matching method found: draw for class com.badlogic.gdx.graphics.g2d.SpriteBatch
  27.   (doto (:sprite @texture-state)
  28.     (.begin)
  29.     (.draw (:texture @texture-state) 50.5 50.5)
  30.     (.end)))
  31.  
  32. (defn main-screen
  33.   []
  34.   (proxy [Screen] []
  35.     (show [])
  36.     (render [delta]
  37.       ;; Call render loop
  38.       (render delta))
  39.     (dispose[])
  40.     (hide [])
  41.     (pause [])
  42.     (resize [w h])
  43.     (resume [])))
  44.  
  45. (defn -create [^Game this]
  46.   ;; Create SpriteBatch and Texture
  47.   (let [sprite (SpriteBatch.)
  48.         texture (Texture. "clojure.png")]
  49.     (swap! texture-state #(assoc % :sprite sprite :texture texture))
  50.     (.setScreen this (main-screen))))
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement