love2d

attempt to index local 'def' (a nil value)

杀马特。学长 韩版系。学妹 提交于 2021-02-10 19:59:25
问题 I'm working on a game. At a certain point, I would like to create special GameObject. The special GameObject is called Projectile and is the same as GameObject but has a dx and dy as well as some other functions that only a projectile will have. I am trying to make Projectile extend the GameObject class, but I run into issues when I try to create an instance of Projectile. I've tried different ways of declaring Projectile and shuffling declaration order but can't seem to figure out why I'm

Local variables in global scope Lua

妖精的绣舞 提交于 2021-01-28 20:24:06
问题 So let's say I have a lua file, and at the top, I define a variable outside of any function, but I call it local local x = 1 Is there any difference between that local x, and a global x? 回答1: Yes, as it is local to the chunk that it is created in. Lua handles a chunk as the body of an anonymous function with a variable number of arguments (see §3.4.11). As such, chunks can define local variables, receive arguments, and return values. Moreover, such anonymous function is compiled as in the

Getting multiple values from a function without creating a variables in LUA

百般思念 提交于 2020-07-30 03:17:04
问题 Is there any way to get several values from a function without creating variables for it? local major, minor, revision, codename = love.getVersion() -- Get current LÖVE version as a string. So instead of making four different variables (or array) we'll use something that will just return a value you need. get( love.getVersion(), 0 ) -- Will return the first value (major). I read somewhere that I can use square brackets and tried love.getVersion()[1] but it says "Attempt to index a number

Trying to add horizontal movement to my game in love2d

我与影子孤独终老i 提交于 2020-07-23 06:38:05
问题 I have tried to add horizontal movement into my game in love, but I haven't found a way yet. This is my code. PADDLE_SPEED = 200 player1 = Paddle(10, 30, 5, 20) player1 = Paddle(10, 30, 5, 20) player2 = Paddle(VIRTUAL_WIDTH - 15, VIRTUAL_HEIGHT - 30, 5, 20) player3 = Paddle(30, 10, 20, 5) player4 = Paddle(VIRTUAL_WIDTH - 30, VIRTUAL_HEIGHT - 15, 20, 5) ball = Ball(VIRTUAL_WIDTH / 2 - 2, VIRTUAL_HEIGHT / 2 - 2, 4, 4) if love.keyboard.isDown('w') then player1.dy = -PADDLE_SPEED elseif love

Trying to add horizontal movement to my game in love2d

旧巷老猫 提交于 2020-07-23 06:36:36
问题 I have tried to add horizontal movement into my game in love, but I haven't found a way yet. This is my code. PADDLE_SPEED = 200 player1 = Paddle(10, 30, 5, 20) player1 = Paddle(10, 30, 5, 20) player2 = Paddle(VIRTUAL_WIDTH - 15, VIRTUAL_HEIGHT - 30, 5, 20) player3 = Paddle(30, 10, 20, 5) player4 = Paddle(VIRTUAL_WIDTH - 30, VIRTUAL_HEIGHT - 15, 20, 5) ball = Ball(VIRTUAL_WIDTH / 2 - 2, VIRTUAL_HEIGHT / 2 - 2, 4, 4) if love.keyboard.isDown('w') then player1.dy = -PADDLE_SPEED elseif love

Trying to add horizontal movement to my game in love2d

≡放荡痞女 提交于 2020-07-23 06:35:58
问题 I have tried to add horizontal movement into my game in love, but I haven't found a way yet. This is my code. PADDLE_SPEED = 200 player1 = Paddle(10, 30, 5, 20) player1 = Paddle(10, 30, 5, 20) player2 = Paddle(VIRTUAL_WIDTH - 15, VIRTUAL_HEIGHT - 30, 5, 20) player3 = Paddle(30, 10, 20, 5) player4 = Paddle(VIRTUAL_WIDTH - 30, VIRTUAL_HEIGHT - 15, 20, 5) ball = Ball(VIRTUAL_WIDTH / 2 - 2, VIRTUAL_HEIGHT / 2 - 2, 4, 4) if love.keyboard.isDown('w') then player1.dy = -PADDLE_SPEED elseif love

How do I create a save game feature in love2d?

这一生的挚爱 提交于 2020-07-15 05:52:41
问题 I am new to game development but I need to know if it is possible to create a save game feature in love2d with lua. 回答1: Sure. You can use a variety of libraries available. My current recommendation is Ser Binser ( Ser has been deprecated ). This process is called "table serialization." Then, you can do something like this to effectively create a "save." local ser = require 'Path.to.ser' local save function love.load() if love.filesystem.exists( 'Save.lua' ) then save = love.filesystem.load(

How to calculate coordinates of the gunpoint

送分小仙女□ 提交于 2020-01-17 06:43:33
问题 Good whatever time of day! I have some sprite: A point has coordinates Actor.x; Actor.y . AB length = 96 BC length = 86 AC length = 42 All calculations are approximate, I made it with help the ruler in Photoshop. Sprite always towards mouse, angle (in radians) stores in Actor.direction variable. I draw sprite with scale 0.3 . All bullets toward mouse (that is Bullet.direction == Actor.direction ). I need to create bullets in the B point. How I can calculate coordinates of the B point with any

Getting mouse position and playing sound with Lua in Love2D

断了今生、忘了曾经 提交于 2020-01-05 03:47:06
问题 I'm writing a little game for visual deficient people, but I'm having a hard time getting the mouse position. Let me explain : I need to know where in the table the mouse cursor is, without having a click, and then I want to play a sound. That sound would be different for every position. Any thoughts? Thanks, in advance! e.g., when the mouse is on the 1st box would be played the audio "a1", when it's on the 2nd box, "a2", and so on. I tried with: mouse_x, mouse_y = get_Position() if mouse_x

Getting mouse position and playing sound with Lua in Love2D

ε祈祈猫儿з 提交于 2020-01-05 03:47:05
问题 I'm writing a little game for visual deficient people, but I'm having a hard time getting the mouse position. Let me explain : I need to know where in the table the mouse cursor is, without having a click, and then I want to play a sound. That sound would be different for every position. Any thoughts? Thanks, in advance! e.g., when the mouse is on the 1st box would be played the audio "a1", when it's on the 2nd box, "a2", and so on. I tried with: mouse_x, mouse_y = get_Position() if mouse_x