Bitmaps and Sprites. - Printable Version +- Save-Point (https://www.save-point.org) +-- Forum: Games Development (https://www.save-point.org/forum-4.html) +--- Forum: Tutorials (https://www.save-point.org/forum-19.html) +--- Thread: Bitmaps and Sprites. (/thread-3387.html) |
Bitmaps and Sprites. - deValdr - 04-21-2011 Bitmaps and Sprites Learn how to make your game more visually appealing and exciting with scripted Sprites. Creating a Sprite Sprite is a class built into RGSS. It displays a bitmap on the screen. This is how you create a sprite that is displayed on the screen: Code: @sprite = Sprite.new Code: @sprite = Sprite.new Position of the sprite The position of the sprite is handled using x and y as well as a z variable. The z variables determines where in the queue of visual elements it will be drawn. Far behind or in front. We set position this way: Code: @sprite.x = 50 Some additional properties for the Sprite class are: Code: @sprite.angle = 360 Color Color is important in bitmaps. Every pixel in a bitmap is made up of four different values. Red, Green, Blue and alpha. The alpha channel is opacity. The rest is obvious. RGSS has a built in Color class. You create a new Color object like this. Code: @black = Color.new(0, 0, 0, 255) Setting pixels In order to draw a pixel on a bitmap you use the .set_pixel method of the Bitmap object. Code: @sprite.bitmap.set_pixel(x, y, color) Drawing rectangles Sometimes we would rather want to draw a rectangle spanning over many pixels than just single pixels. It can be done very easily: Code: @sprite.bitmap.fill_rect(x, y, width, height, color) Using loops to create dynamic effects You can read about for loops in my other tutorial. They can be very handy if you want to create gradients for example: Code: for i in 1..100 More may be coming soon. :) Hope it helped. I appreciate replies if you liked it. :) |