I guess I don't get the logic?
Code: Select all
if x < width then
x = x + 1
elseif x > width then
x = x - 1
How can I tell the program to change the direction of the rectangle when it reaches the most outer parts of the screen?
Thanks in advance
Code: Select all
if x < width then
x = x + 1
elseif x > width then
x = x - 1
Code: Select all
if x >= window_width - rectangle_width then
direction = "left"
elseif x <= 0 then
direction = "right"
end
if direction == "left" then
x = x - 1
elseif direction == "right" then
x = x + 1
end
Code: Select all
local pos = 0
local dir = "right"
function love.update(dt)
if dir == "right" then
pos = pos + 1
if pos >= love.graphics.getWidth() then
dir = "left"
end
elseif dir == "left" then
pos = pos - 1
if pos <= 0 then
dir = "right"
end
end
end
Code: Select all
local pos = 0
local velocity = 1
function love.update(dt)
pos = pos + velocity
if pos >= love.graphics.getWidth() or pos <= 0 then
velocity = -velocity
end
end
Code: Select all
local pos = 0
local count = 0
function love.update(dt)
count = count + dt
pos = math.sin(count) * (love.graphics.getWidth() / 2) + love.graphics.getWidth() / 2
end
Users browsing this forum: Google [Bot] and 5 guests