Quick Links: Download Gideros Studio | Gideros Documentation | Gideros Development Center | Gideros community chat
big bitmap as background. Performance? - Gideros Forum

big bitmap as background. Performance?

Hope you are all doing well :smile:
My question: how do you deal with big sprites as background?
For example I have a 5000 * 768 texture that I feed into a bitmap as a background for my game. It is quite big so I split it up into 6.
When I run my game it seems that it stutters at every image cut?!
How would you deal with this please?

I have read somewhere in the forum that I should hide (setvisible) my sprites until they are actually displayed. Any other tips? :)
my growING GIDEROS github repositories: https://github.com/mokalux?tab=repositories

Comments

  • MoKaLuxMoKaLux Member
    edited February 15
    What about cutting it into tiles and then create a tilemap? Tiles are not drawn if outside the screen, is this the way to go?

    I am going to try this :) (thank you antix for showing me how to use tilemaps <3 )

    Likes: SinisterSoft

    my growING GIDEROS github repositories: https://github.com/mokalux?tab=repositories
    +1 -1 (+1 / -0 ) Share on Facebook
  • rrraptorrrraptor Member
    edited February 16
    Hm...no problem for me with 4k texture. Works fine on my phone aswell.

    Test:
    OBJ_NUM @ 10000 -- total amount of objects
    local minX, minY, maxX, maxY = application:getLogicalBounds()
     
    local USE_BG = true
    local W = (maxX - minX) * 2 --4572
    local H = (maxY - minY) * 2 --3328
    local MX = W / 2
    local MY = H / 2
    local MID_DIST = math.length(MX, MY)
     
    local Obj = Core.class(Sprite)
    local offset = 20
    function Obj:init()
    	self.dir = math.random(4) * (offset + math.random(90 - offset * 2)) * offset
     
    	self.w = math.random(10, 64)
    	self.h = math.random(10, 64)
    	self.speed = math.random(100, 500)
    	self.vr = math.random(10,50)
    	self.rotationDir = math.random() < 0.5 and 1 or -1
    	self.model = Pixel.new(math.random(0xffffff), 1, self.w, self.h)
    	self:addChild(self.model)
     
    	--self:setPosition(MX, MY)
    end
    --
    function Obj:update(dt)
    	local x, y = self:getPosition()
     
    	self.dir += self.vr * self.rotationDir * dt
     
    	local theta = ^<self.dir
    	local cosa = math.cos(theta)
    	local sina = math.sin(theta)
    	x += cosa * self.speed * dt
    	y += sina * self.speed * dt
     
    	if x < 0 then x = W end
    	if y < 0 then y = H end
    	if x > W then x = 0 end
    	if y > H then y = 0 end
     
    	local alpha = math.distance(x, y, MX, MY) / MID_DIST
    	self:setAlpha(alpha)
    	self:setRotation(self.dir)
    	self:setPosition(x, y)
    end
    --
     
    local scene = Sprite.new()
    local ind = 1
    local mx, my = 0, 0
    local objs = {}
    local timer = 0
    scene:setScale(0.5)
     
    if (USE_BG) then 
    	local tex = Texture.new("4k_texture.jpg", true)
    	W = tex:getWidth()
    	H = tex:getHeight()
    	MX = W / 2
    	MY = H / 2
    	MID_DIST = math.length(MX, MY)
     
    	local img = Bitmap.new(tex)
    	scene:addChild(img)
    	ind = 2
    end
     
    stage:addChild(scene)
     
    local tf = TextField.new(nil, "Fps: 00")
    tf:setPosition(40, 40)
    tf:setScale(2)
    stage:addChild(tf)
     
    local function createObjects()
    	for i = 1, OBJ_NUM do 
    		objs[i] = Obj.new()
    		scene:addChildAt(objs[i], ind)
    	end
    end
     
    stage:addEventListener(Event.MOUSE_WHEEL, function(e)
    	local s = scene:getScale()
    	if (e.wheel < 0) then
    		s -= 0.1
    	else
    		s += 0.1
    	end
    	scene:setScale(s)
    end)
     
    stage:addEventListener("mouseDown", function(e)
    	mx, my = e.x, e.y
    end)
     
    stage:addEventListener("mouseMove", function(e)
    	local x, y = scene:getPosition()
    	x = x + e.x - mx
    	y = y + e.y - my
    	scene:setPosition(x, y)
    	mx, my = e.x, e.y
    end)
     
    stage:addEventListener("enterFrame", function(e)
    	local dt = e.deltaTime
    	timer += dt
    	if (timer >= 1) then 
    		timer = 0
    		tf:setText(("Fps: %02d"):format(1 / dt))
    	end	
     
    	for i = 1, #objs do 
    		objs[i]:update(dt)
    	end
    end)
     
    Core.asyncCall(createObjects)

    Likes: MoKaLux

    +1 -1 (+1 / -0 ) Share on Facebook
Sign In or Register to comment.