Page 1 of 1

Click counter

Posted: Thu May 22, 2014 10:41 am
by edwardander
Hi all,

i am just training on love. i decided to make a little program which is kind a showcase of flux tweening library. in scenario it must change the tweening ease at every click. but unfortunately, i could not change the index of the "easemods" by every single clicking. here is my code, where do i make the mistake?

Code: Select all

flux = require "flux"

function love.load()
player={x = 100, y = 100}     --> start point of the player
easemodes={"linear", "quadin", "quadout", "quadinout", "cubicin",     --> ease modes of the flux lib
  "cubicout", "cubicinout", "quartin", "quartout", "quartinout", 
  "quintin", "quintout", "quintinout", "expoin", "expoout", 
  "expoinout", "sinein", "sineout", "sineinout", "circin", 
  "circout", "circinout", "backin", "backout", "backinout", 
  "elasticin", "elasticout", "elasticinout"}
n=1     --> ease modes indexer. this should be iterated by clicking

end 

function love.update(dt)
	flux.update(dt)
  flux.to(player, 2, {x=love.mouse.getX(),y=love.mouse.getY()}):ease(easemodes[n])      --> the square follows the mouse cursor here. alse ease mode is selected
  if love.mouse.isDown("l") then      --> my wrong code which cant change "n" by clicking. my question about here mostly
    if not love.mouse.isDown("l") then
      n=n+1
    end
  end
  
 
end

  
function love.draw()
  love.graphics.print(easemodes[n],20,20)     --> shows which mode we are at
	love.graphics.setColor(255, 0, 0, 255)	
	love.graphics.rectangle("fill", player.x, player.y, 10, 10)
end


Re: Click counter

Posted: Thu May 22, 2014 10:59 am
by bartbes
edwardander wrote:

Code: Select all

  if love.mouse.isDown("l") then
    if not love.mouse.isDown("l") then
How would that ever work?

You probably just want to do something like this:

Code: Select all

function love.mousepressed(x, y, button)
    if button == "l" then
        n = n%#easemodes + 1
    end
end

Re: Click counter

Posted: Thu May 22, 2014 11:10 am
by edwardander
you know, after one moment you try really silly thing. but i can swear that i tried "love.mousepressed" function too. i think i need a coffee

thank you.