Mithran

VXA Draw Test Text

Mar 13th, 2012
254
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.68 KB | None | 0 0
  1.  
  2. class Scene_DrawTextTest < Scene_Base
  3. ON = true
  4. TEST_TEXT = "The green area is the rect given by Bitmap#text_size." # +
  5. " And this is just an extra optional line that can be added to the above to demonstrate the error."
  6. # the green area is the rect given by Bitmap#text_size for the above string,
  7. # and the text is drawn to this rect
  8. # by definition, the text should be of approximately the same size as the rect
  9. # and should not shift if alignment is changed, but neither is true
  10.  
  11. # if you make the above string really long (as in, for horizonally scrolling text)
  12. # the draw text will collapse over itself (uncomment the plus to see)
  13. ALIGN = 0 # text_size issue is really ovbious when aligned left
  14. # but try center with longer text, to show text drawing over itself for no reason
  15. # to make matters worse, it doesnt even properly center when this happens
  16.  
  17. def start
  18. @sprite = Sprite_Base.new
  19. rect = Cache.empty_bitmap.text_size(TEST_TEXT)
  20. @sprite.bitmap = Bitmap.new(rect.width, rect.height)
  21. @sprite.bitmap.fill_rect(rect, Color.new(0, 128, 0))
  22. @sprite.bitmap.draw_text(rect, TEST_TEXT, ALIGN)
  23. center_sprite(@sprite)
  24. end
  25.  
  26. def update
  27. super
  28. @sprite.update
  29. SceneManager.exit if Input.trigger?(:C)
  30. end
  31.  
  32. def center_sprite(sprite)
  33. sprite.ox = sprite.bitmap.width / 2
  34. sprite.oy = sprite.bitmap.height / 2
  35. sprite.x = Graphics.width / 2
  36. sprite.y = Graphics.height / 2
  37. end
  38.  
  39. def terminate
  40. end
  41.  
  42. end
  43.  
  44. Font.default_name = "Verdana" # for comparison to VX
  45.  
  46. module SceneManager
  47. if Scene_DrawTextTest::ON
  48. def self.first_scene_class
  49. Scene_DrawTextTest
  50. end
  51. end
  52. end
Advertisement
Add Comment
Please, Sign In to add comment