Advertisement
Guest User

SM5 Sprite Example

a guest
Feb 9th, 2014
116
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 0.98 KB | None | 0 0
  1. -- by default, Sprites do not have a height or width or even an image
  2.  
  3. Def.Sprite{
  4.     OnCommand=function(self)
  5.        
  6.         --declare our variables
  7.         local song, path, width, height;
  8.        
  9.         -- get the current song as a song object
  10.         song = GAMESTATE:GetCurrentSong();
  11.  
  12.         -- if there is a song (if the variable is not nil) then...
  13.         if song then
  14.            
  15.             -- then get that song's banner path
  16.             -- if the banner path is empty, path will be an empty string like (but not nil)
  17.             path = song:GetBannerPath();
  18.  
  19.             -- path shouldn't be nil, but check just in case
  20.             if path then
  21.                
  22.                 -- in this context, self is the Sprite object we are in
  23.                 -- we haven't loaded any image yet
  24.                 -- so use the Load() method and give it the path from above
  25.                 self:Load(path);
  26.                
  27.                
  28.                 -- now that we've loaded the image, it should have height and width
  29.                 width = self:GetWidth();
  30.                 height = self:GetHeight();
  31.                
  32.                 -- do stuff with height and width now
  33.                
  34.             end
  35.         end    
  36.     end
  37. };
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement