Loading an image from a subdirectory in a gem

104 views Asked by At

I used bundler to create a new gem, and I'm playing with rubygame. So far, it's going OK, except I can't get images on the Surface because I can't figure out what the path is to my images directory. I know it's sad, but I'm sorta used to Rails loading my images for me.

The full path to the image is: /usr/local/src/jewel_thief/lib/jewel_thief/images/player.png.

and I'm trying to use it in:

/usr/local/src/jewel_thief/lib/jewel_thief/player.rb (view source)

What am I doing wrong?

2

There are 2 answers

2
Salil On

Change

@image = Surface.load 'jewel_thief/images/player.png'

To

@image = Surface.load '/jewel_thief/images/player.png'

I think following also work

@image = Surface.load '/jewel_thief/lib/jewel_thief/images/player.png'
0
James Dunn On

The path ended up being this:

@image = Surface.load 'lib/jewel_thief/images/player.png'

Finally, after being stumped for hours. Thanks for the help though! Really.