Skip to content

How to properly load and display PNG images in Heaps.io for web target? #1332

Description

@Lyten02

Hi! I'm developing a game using Haxe/Heaps.io targeting web. Having trouble loading images dynamically.

Current setup:

  • File exists at res/avatars/1.png
  • Build config has -D resourcesPath=.../res
  • File gets copied to bin/web/debug/res/avatars/1.png during build

Loading code:
// Option 1 - throws haxe_ValueException
var tile = hxd.Res.load("avatars/1.png").toTile();
var bitmap = new h2d.Bitmap(tile, parent);

// Option 2 - also doesn't work
var tile = hxd.Res.loader.load("avatars/1.png").toTile();

Console error:
Uncaught haxe_ValueException

What works:

  • Static resources via hxd.Res.game.phone.toTile() (file at res/game/phone.png)
  • HTML/CSS approach for displaying images

Questions:

  1. What's the correct way to load images dynamically by path in Heaps for web?
  2. Do resources need to be registered somewhere before use?
  3. What's the difference between hxd.Res.load() and hxd.Res.loader.load()?

Any help appreciated!

Image

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions