Add tileset loading
This commit is contained in:
+8
-1
@@ -7,6 +7,11 @@ default_font = Font.new "assets/fonts/charybdis.ttf", 24, pixel_art: true
|
||||
bg_image1 = Image.load "assets/images/menu_bg.png", pixel_art: true
|
||||
bg_image2 = Image.load "assets/images/game_over_dead_bg.png", pixel_art: true
|
||||
|
||||
tile_set = Image.load_set "assets/images/walls.png", 20, 20, padding: {x: 0, y: 20}, offset: {x: 0, y: 0}, pixel_art: true
|
||||
# tile_set is an array of images, so we can create an animation from it directly or use the images separately
|
||||
pp tile_set, "Tile set size: #{tile_set.size}"
|
||||
tile_animation = Animation.new tile_set, fps: 10
|
||||
|
||||
bg_animation = Animation.new [bg_image1, bg_image2], fps: 5
|
||||
|
||||
bg_image1_a = Animation.from(bg_image1)
|
||||
@@ -18,7 +23,7 @@ text = ElementText.new :btn_text, default_font, 0xFFFF00, {name: "Me"}, position
|
||||
|
||||
rect = ElementRect.new 100, 25, 0xFF0000, position: {x: 50, y: 50}, z: 0, rotation: 60, scale: { x: 1, y: 1 }, alpha: 0.8, click_mode: :block
|
||||
|
||||
image_element = ElementImage.new bg_animation, position: {x: 0, y: 0}, z: -1, click_mode: :block, alpha: 1
|
||||
image_element = ElementImage.new tile_animation, position: {x: 0, y: 0}, scale: { x: 20, y: 20 }, z: -1, click_mode: :block, alpha: 1
|
||||
|
||||
image1 = Image.new 50, 50, pixel_art: true
|
||||
|
||||
@@ -68,6 +73,8 @@ App.update do |delta_time|
|
||||
green_pixel = [0xFF, 0, 255, 0] # ARGB
|
||||
c_p = ((c_c / 10) % 2) == 1 ? red_pixel : green_pixel
|
||||
raw_bytes = (c_p * (50 * 50)).pack('C*')
|
||||
# this is not the most efficient way to create a raw byte array, but it works for demonstration purposes
|
||||
# you can use ` commands to get image data from an external source or generate it procedurally
|
||||
bg_image1.update(0, 0, 50, 50, raw_bytes)
|
||||
image1.update(0, 0, 50, 50, raw_bytes)
|
||||
|
||||
|
||||
Reference in New Issue
Block a user