I'm not even sure if this is an SDK bug, but I have encountered a crazy weird bug when moving sprites every frame. I didn't have a device so I sent a build in the dev discord for testing, and they found an issue that the simulator doesn't even show. When moving sprites every frame (to an already floored position) The objects flicker, especially noticable on 50% opacity parts. I have attached a build and some relevant source code parts. This also isn't a device issue, since I got the exact same responce from 2 people.
table.insert(fishies, Fish(-26, -14, 0))
sprite_rock = Obj(64, 0, -50, image_rock)
sprite_seaweed1 = Obj(-5, 0, 26, image_seaweed1)
sprite_seaweed2 = Obj(-14, 0, -26, image_seaweed2)
gfx.sprite.setBackgroundDrawingCallback(
function( x, y, width, height )
image_bg:draw(0, 0)
end
)
function pd.update()
dt = playdate.getElapsedTime()
playdate.resetElapsedTime()
gfx.sprite.update()
-- cam rotation
cam_yaw = cam_yaw%360
if pd.isCrankDocked() then
cam_yaw += 0.125
else
cam_yaw += math.floor(pd.getCrankChange()/2)
end
end
function rotate_around_center(x, y, center_x, center_y, angle)
local translated_x = x - center_x
local translated_y = y - center_y
local rad = math.rad(angle)
local cos_angle = math.cos(rad)
local sin_angle = math.sin(rad)
local rotated_x = translated_x * cos_angle - translated_y * sin_angle
local rotated_y = translated_x * sin_angle + translated_y * cos_angle
local final_x = rotated_x + center_x
local final_y = rotated_y*cam_pitch_multiplier + center_y
return final_x, final_y
end
function Obj:update()
Obj.super.update(self)
local screen_center_x, screen_center_y = 200, 170
local new_x, new_y = rotate_around_center(self.cur_x+200, self.cur_y-self.cur_z+120, screen_center_x, screen_center_y, cam_yaw)
self:moveTo(math.floor(new_x), math.floor(new_y))
self:setZIndex(math.floor(new_y))
end
function Fish:update()
Fish.super.update(self)
local screen_center_x, screen_center_y = 200, 170
local new_x, new_y = rotate_around_center(self.cur_x, self.cur_y-self.cur_z, 0, 0, cam_yaw)
self:moveTo(math.floor(new_x + screen_center_x), math.floor(new_y + screen_center_y))
self:setZIndex(math.floor(new_y+screen_center_y))
-- following targets
if self.wait_time > 0 then
self.wait_time -= dt
else
self.cur_x, self.cur_y, self.cur_z = move_towards(self.cur_x, self.cur_y, self.cur_z, self.target_x, self.target_y, self.target_z, self.speed)
if distance_between(self.cur_x, self.cur_y, self.target_x, self.target_y) < 2 then
self:new_target()
self.wait_time = math.random(10, 50) / 10
end
end
end
current build:
fishbowl.pdx.zip (61.8 KB)
Sadly I'm not allowed to upload videos, and a gif couldn't show my issue.