Hi, i don't understand why my bg_speed doesn't work.
When i press KeyUP bg_speed var is incremented, so background animation should be accelerate.
need help.
#beginner
import "CoreLibs/sprites"
import "CoreLibs/animation"-- performance shortcut
local gfx = playdate.graphics
local car_speed = 4
local bg_speed = 50-- background sprite
local function CreateBackgroundSprite()
local background = gfx.sprite.new() background.imagetable = gfx.imagetable.new("images/outrun") background:setBounds(0, 0, 400, 240) background.animation = gfx.animation.loop.new(bg_speed, background.imagetable, true) function background:update() self:setImage(self.animation:image()) end background:add() background:setZIndex(0)
end
local function CreatePLayer()
carSprite = gfx.image.new("images/car")
carSprite = gfx.sprite.new(carSprite)
carSprite:moveTo(160, 200)
carSprite:add()
endCreateBackgroundSprite()
CreatePLayer()function playdate.update()
gfx.setBackgroundColor(gfx.kColorBlack) if playdate.buttonIsPressed(playdate.kButtonUp) then bg_speed = bg_speed - 1 -- background speed fast print(bg_speed) end if playdate.buttonIsPressed(playdate.kButtonDown) then bg_speed = bg_speed + 1 -- background speed slow end if playdate.buttonIsPressed(playdate.kButtonRight) then carSprite:moveBy(car_speed,0) end if playdate.buttonIsPressed(playdate.kButtonLeft) then carSprite:moveBy(-car_speed,0) end gfx.clear() gfx.sprite.update()
end
thank you