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.
-
Pigzo
- Prole
- Posts: 17
- Joined: Mon Apr 09, 2012 8:49 pm
Post
by Pigzo » Mon Apr 09, 2012 8:55 pm
Hey Guys i have a Problem with Love 0.8.0 I Programmed a New Game(N00b Like xD) and i made a player.lua .. i'll post the complete code..
main.lua
Code: Select all
require 'player'
function love.load()
mediumFont = love.graphics.newFont(20)
bg_color()
end
function love.update(dt)
if love.keyboard.isDown("right") then
player_x = player_x + (speed * dt)
elseif love.keyboard.isDown("left") then
player_x = player_x - (speed * dt)
end
if love.keyboard.isDown("up") then
player_y = player_y - (speed * dt)
elseif love.keyboard.isDown("down") then
player_y = player_y + (speed * dt)
end
end
function love.draw()
love.draw(player_mob, player_x, player_y)
love.graphics.setFont(mediumFont)
setColor("black")
love.graphics.print("Start Game", 5, 5)
resetColor()
end
function bg_color()
love.graphics.setBackgroundColor(187, 255, 129)
end
function setColor(color)
if color == "black" then
love.graphics.setColor(0, 0, 0)
end
end
function resetColor()
love.graphics.setColor(255, 255, 255)
end
player.lua
Code: Select all
function player()
player_mob = love.graphics.newImage("Data/mob/player.png")
player_x = 200
player_y = 200
speed = 400
end
Everytime i Started this i became this warning from Love
Error
main.lua:23: stack overflowed
Traceback
main.lua:23: in function 'draw'
-
bartbes
- Sex machine
- Posts: 4946
- Joined: Fri Aug 29, 2008 10:35 am
- Location: The Netherlands
-
Contact:
Post
by bartbes » Mon Apr 09, 2012 9:08 pm
You call love.draw in love.draw, and you should be calling love.graphics.draw.
-
Adamantos
- Prole
- Posts: 27
- Joined: Sun May 16, 2010 10:47 pm
Post
by Adamantos » Mon Apr 09, 2012 9:09 pm
Hey,
You are causing a recursion in
love.draw(), i.e. love.draw is calling itself over and over again... until there is no memory left. You are looking for the love.graphics.draw(...) funtion.
Code: Select all
function love.draw()
love.graphics.draw(player_mob, player_x, player_y)
...
end
-
Pigzo
- Prole
- Posts: 17
- Joined: Mon Apr 09, 2012 8:49 pm
Post
by Pigzo » Mon Apr 09, 2012 9:12 pm
Well Now i Became this Error ...
Error
main.lua:23: Incorrect parameter type: expected userdata.
Traceback
[C]: in function 'draw'
main.lua:23: in function 'draw'
[C]: in function 'xpcall'
-
Robin
- The Omniscient
- Posts: 6506
- Joined: Fri Feb 20, 2009 4:29 pm
- Location: The Netherlands
-
Contact:
Post
by Robin » Mon Apr 09, 2012 9:32 pm
You never call the function player(). Just call it in love.load() or something.
-
Pigzo
- Prole
- Posts: 17
- Joined: Mon Apr 09, 2012 8:49 pm
Post
by Pigzo » Mon Apr 09, 2012 9:43 pm
Works Perfectly Thank!
I Up You Karma
Users browsing this forum: Bing [Bot] and 6 guests