Simple Single Image Scrolling Example? (SOLVED)

Is there a sample anyone has of…

  1. Load image dynamically to screen (assuming using GUI/dynamic texture load)

  2. The image is larger than the screen

  3. Simple dragging input to move around image larger than the viewport.

I’ve seen some tiled examples, etc. but not one that is a single image.

1 Like

Would this work?


First off that’s wicked cool! And I love you used Defold for something utilitarian. I’ll check out the source. I basically just want to load say a 1000 x 1000 image into a box that is say 500 x 500 and not have it stretch/shrink to fit but instead be panable inside that defined window. Then surround it with gui, etc.


Is there really a difference?

I think you want to size the box node the same size as the image and then either cover it with other gui nodes or add a stencil cutout of 500x500.

1 Like

Thanks, I was thinking of using a stencil but hadn’t tried it yet - I’ll go in that direction.

1 Like

Hey, FWIW I’m working on this and was reviewing the API reference:

This line:
“Clipping mode defines how the node will clipping it’s children nodes”

should read

“Clipping mode defines how the node will clip its children nodes”

Thanks! Fixed:

its not it’s as well. It’s is a typo we all make but it is not indicative of possessiveness.

I’m making progress but stumbled on a different issue as I try to just get a hackable prototype going. I’m trying to load two images from disk and set each to a new texture and populate their corresponding gui.node box.

filename = "scroll-room-examp"
filename = "/main/bundled_resources/common/scene-backgrounds/"..filename..".png"
local data, error = sys.load_resource(filename)
if not data then
	print("error: "..error)
local png = image.load(data)
gui.new_texture("placeimage", png.width, png.height, "rgb", png.buffer)	
gui.set_texture(imagery, "placeimage")

filename = "women"
filename = "/main/bundled_resources/common/scene-objects/"..filename..".png"
local data2, error = sys.load_resource(filename)
if not data2 then
	print("error: "..error)
newpng = image.load(data2)
gui.new_texture("objecttoload", newpng.width, newpng.height, "rgb", newpng.buffer)	

gui.set_texture(object1, "objecttoload")

But on the last line it’s triggering
Texture ‘objecttoload’ is not specified in scene

I renamed some of the variables on the second block of loading code just to see if there was some issue there… I’m sure this isn’t the way to load multiple objects from disk to display in-game but again I’m just trying to get a quick and dirty version of this idea up and running first.

Going to look back at some older code that didn’t have this problem in meantime.

This call is likely failing for some reason. Check the return value (true/false). Do you see any errors in the console?

Note: In the next release (beta on Monday) we have improved gui.new_texture() so that you get more info about why it is failing (out of resources, data format error etc).

will flood it with various print(something) - etc. to see what else comes out.

So… I was tracking down other ideas and ended up here:
Loading image from file (SOLVED) (hahahahah)
and I flipped it from Rgb to Rgba (the opposite of the previous problem) and it worked. Is RGBA vs. RGB a transparency issue? This image has transparency.

1 Like

Ok, great! You found it. It does log “Invalid image buffer size” which is an indication that there was something wrong with the data. In the next version of Defold you’ll be able to catch this specific problem.

Cool! I think it’s basically a PNG transparency vs. no transparency issue.