Sprite not always showing up (SOLVED)

I apologies in advanced if this is a duplicate question but I can’t seem to find a solution. I recently started using with defold and I’m trying to move a object around on the screen. About 50% of the time my objects move perfectly but the other 50% the object doesn’t show up on the screen. My debug statements show the object moving but they aren’t being displayed. The following is the script that I’m using for the game object. I’m creating the object via a factory (not sure if that matters).


function init(self)
	msg.post(".", "acquire_input_focus")
	print("tile.init()")
	self.timer = 1
	self.dest = vmath.vector3(400,400,0);
end

function update(self, dt)
	self.timer = self.timer - dt
	
	local p = go.get_position();
	 
	if dist(p.x,p.y,self.dest.x,self.dest.y) > 1 then
		local dx = (self.dest.x - p.x) * 0.15
		local dy = (self.dest.y - p.y) * 0.15
		
		p.x = p.x + dx
		p.y = p.y + dy
		
		if dist(p.x,p.y,self.dest.x,self.dest.y) < 1 then
		 	print("Moved to" , p.x , "x" , p.y  , " " , dx , " " , dy )
		end
		
		go.set_position( p );
	end
end


function dist(x1,y1,x2,y2) 
	return math.sqrt( math.pow( x1 - x2 , 2 ) + math.pow( (y1 - y2) , 2 )) 
end



function glide_to(self,dest) 
	self.dest = dest
end

function on_input(self, action_id, action)
	if action_id == nil then
		return true
	end
	
	if action_id == hash("click") and action.pressed then
    glide_to(self, vmath.vector3( action.x, action.y , 0) )
    
	end
end

The default render script uses a z-depth range of -1 to 1. I’m guessing that your sprite gets a z-value outside of this range?

Yes. That was it. My background had an z-value higher than the object. I’m just not sure why it ever was viewable. Thanks for the help.

1 Like