How to make a small sprite (game object), a self-stretching background for the game?

Hello everyone. After a long break, I’m working with Defold again. I’ve been trying to figure out how to do this for 4 days. Can someone help me ?

  1. How to make a small sprite (game object), a self-stretching background for the game?

  2. How to make different stretching behavior for different sprites? (Gameobject)

  3. How to launch a “laser” sprite into another spinning sprite “circle”, and stick to the collision, and continue spinning as a child.

  4. How to raise “go” over “gui”? “gui” images cover all “go” images

These are probably very simple questions, but I couldn’t find a simple and understandable answer =)

1) My choice.

– Catching the screen change response

function window_callback(self, event, data)
	if event == window.WINDOW_EVENT_RESIZED then
		print("Window resized: ", data.width, data.height)
		if data.width < 720 then
			data.width = 720
		end
		if data.height < 1280 then
			data.height = 1280
		end
		go.set("/background#sprite", hash("size"), vmath.vector3(data.width, data.height, 0))
	end
end

– Listening to size changes

function init(self)
	window.set_listener(window_callback)
end

2) Very simple.

function init(self)
    go.set("/circle#sprite", hash("size"), vmath.vector3(320, 320, 0))
end

The size has changed but you receive an error.
ERROR:SCRIPT: main/main.script:8: could not perform unsupported operation on 'size’
stack traceback:

1 Like

I’ve stumbled upon same issue with background and done it this way:

  1. My game is set to “use_fixed_fit_projection”
  2. Change background Sprite “Size Mode” to “Manual”.
  3. Subscribe same as above to window.set_listener(window_callback)
  4. In window_callback
local w, h = data.width, data.height

if w < DISPLAY_WIDTH then
	w = DISPLAY_WIDTH
	h = h * DISPLAY_WIDTH / data.width
end
if h < DISPLAY_HEIGHT then
	h = DISPLAY_HEIGHT
	w = w * DISPLAY_HEIGHT / data.height
end

go.set("/background#sprite", "size", vmath.vector3(w, h, 1))

where

local DISPLAY_WIDTH = sys.get_config_int("display.width")
local DISPLAY_HEIGHT = sys.get_config_int("display.height")
1 Like