Moving and Start-Origin Problems after using AnAl

Questions about the LÖVE API, installing LÖVE and other support related questions go here.
Forum rules
Before you make a thread asking for help, read this.
Post Reply
User avatar
Doodles
Prole
Posts: 2
Joined: Tue Jul 28, 2015 1:19 am

Moving and Start-Origin Problems after using AnAl

Post by Doodles »

Hi everybody :)

I'm new here and new to this language.
After reading tons of lines I come to a problem, reading can't fix...

After making an AnAl animation, my moving function doesn't work anymore.
The animation still works.
The start origin of my "little hero" doesn't work too...

I've made an screenshot and saved it on my webspace so you can better see the problem: http://trade-off.de/love2d/index.html
Last but not least - sry for my poor englisch :?

Here comes the code:

Code: Select all

--enemy.lua


enemy = {}


function enemy.load()
   enemy.x = 0
   enemy.y = 100
   enemy.width = 0
   enemy.height = 0

   local img  = love.graphics.newImage("enemy/animation/right/right1.png")
   anim1 = newAnimation(img, 40, 50, 0.2, 0)

   local img  = love.graphics.newImage("enemy/animation/left/left1.png")
   anim2 = newAnimation(img, 40, 50, 0.2, 0)

   local img  = love.graphics.newImage("enemy/animation/down/down1.png")
   anim3 = newAnimation(img, 40, 50, 0.2, 0)

   local img  = love.graphics.newImage("enemy/animation/top/top1.png")
   anim4 = newAnimation(img, 40, 50, 0.2, 0)

   idleright = love.graphics.newImage("enemy/right.png")

   sound = love.audio.newSource("sounds/walk.wav")
end


function enemy.draw()
  if not love.keyboard.isDown('d','a','s','w')
  then
  love.graphics.draw(idleright, 40, 50)
  end

   if love.keyboard.isDown('d')
   then
   anim1:draw(40, 50) 
   end

   if love.keyboard.isDown('a')
   then
   anim2:draw(40, 50)  
   end

   if love.keyboard.isDown('s')
   then
   anim3:draw(40, 50) 
   end

   if love.keyboard.isDown('w')
   then
   anim4:draw(40, 50) 
   end
end


function enemy.sounds(dt)
   if love.keyboard.isDown('d','a','w','s') then
      sound:play() 
   end
end


function love.keypressed(k)
   if k == 'escape' then
      love.event.quit()
   end
end


function enemy.move(dt)
   if love.keyboard.isDown('d') then
      enemy.x = enemy.x + 1 
   end

   if love.keyboard.isDown('a') then
      enemy.x = enemy.x - 1   
   end

   if love.keyboard.isDown('w') then
      enemy.y = enemy.y - 1    
   end

   if love.keyboard.isDown('s') then
      enemy.y = enemy.y + 1    
   end
end


function enemy.boundary()
   if enemy.x < 0 then
      enemy.x = 0
   end

   if enemy.x > 800 - enemy.width then
      enemy.x = 800 - enemy.width
   end

   if enemy.y < 100 then
      enemy.y = 100 
   end

   if enemy.y > 600 - enemy.height then
      enemy.y = 600 - enemy.height
   end
end


function UPDATE_ENEMY(dt)
   anim1:update(dt)  
   anim2:update(dt)  
   anim3:update(dt)  
   anim4:update(dt) 
   enemy.move(dt)
   enemy.boundary()
   enemy.sounds(dt)
end


function DRAW_ENEMY()
   enemy.draw()
end
Well, what possible harm could one insane, mutant tentacle do?
User avatar
DaedalusYoung
Party member
Posts: 407
Joined: Sun Jul 14, 2013 8:04 pm

Re: Moving and Start-Origin Problems after using AnAl

Post by DaedalusYoung »

Because you're hardcoding the x and y values:

Code: Select all

love.graphics.draw(idleright, 40, 50)
should be something like:

Code: Select all

love.graphics.draw(idleright, enemy.x, enemy.y)
Btw, you might want to use dt in your move function too:

Code: Select all

function enemy.move(dt)
   if love.keyboard.isDown('d') then
      enemy.x = enemy.x + (10 * dt) -- will make the character move 10 pixels per second
   end
-- ....
end
User avatar
Doodles
Prole
Posts: 2
Joined: Tue Jul 28, 2015 1:19 am

Re: Moving and Start-Origin Problems after using AnAl

Post by Doodles »

Nice, now it works :) Thanks!
Well, what possible harm could one insane, mutant tentacle do?
Post Reply

Who is online

Users browsing this forum: Ahrefs [Bot], Bing [Bot] and 41 guests