Giter VIP home page Giter VIP logo

tex-pack's Introduction

tex-pack

This is a small extension that allows you to combine multiple images into texture pages at runtime through a bin packing algorithm. image

Example (pre-2.3)

tpage = tex_page_create(1024, 1024);
one = tex_page_add(tpage, "one.png", 1, 64, 64);
two = tex_page_add(tpage, "two.png", 2, 64, 64);
tex_page_finalize(tpage);

// ... later, to draw:
tex_sprite_draw(one, 0, x, y);
tex_sprite_draw_ext(two, 1, x, y, 2, 2, current_time / 3, c_white, 1);

Example (2.3)

tpage = new TexPage(1024, 1024);
one = tpage.add("one.png", 1, 64, 64);
two = tpage.add("two.png", 2, 64, 64);
tpage.finalize();

// ... later, to draw:
one.draw(0, x, y);
two.drawExt(1, x, y, 2, 2, current_time / 3, c_white, 1);

API

See doc22.html and doc23.html in export directory.

Compiling Haxe->GML

  • Install Haxe
  • Install sfhx via
    haxelib git sfhx https://github.com/YellowAfterlife/sfhx
  • Install sfgml via
    haxelib git sfgml https://github.com/YellowAfterlife/sfgml
  • Do haxe binpack.hxml to compile all versions.

This will update all 3 GameMaker projects.

Approach

Since packing happens at runtime, the approach used is one of the simplest possible - the algorithm finds the first child-less rectangular node in the tree that can fit an image, marks it as a container for it, and divides it into three - now-image-sized node itself, and two children filling the remaining space:

+-------+    +---+---+
|       |    | E |   |
|   E   | -> +---+ B +
|       |    | A |   |
+-------+    +-------+

Split direction depends on remaining width/height after subtracting image size.

I do not know the algorithm name off-hand as this is loosely based on an example I made for someone in 2012.

Authors, license

Vadim "YellowAfterlife" Dyachenko

MIT license

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.