Advertisement
Mithran

VX Draw Text Test

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