Solution:
Instead of checking if the ball is below 0. I added a margin. 7 seemed to be the sweet spot.
Definitely not the best solution, but a solution nonetheless.
New to love2d
Making a pong game to get the feel for it. However cannot get my score updated even though I think I am doing everything right.
The initial score (0 0) gets on the screen but after a goal happens the score is not updated on the screen. I have also tried with removing dt in arguments in the scoreUpdate function.
Score = {}
function Score:load()
self.x = love.graphics.getWidth() / 2 - 100
self.y = love.graphics.getHeight() - love.graphics.getHeight() + 50
self.xPlayerScore = love.graphics.getWidth() / 2
self.yPlayerScore = love.graphics.getHeight() - love.graphics.getHeight() + 50
self.playerScore = 0
self.xAiScore = love.graphics.getWidth() / 2 + 40
self.yAiScore = love.graphics.getHeight() - love.graphics.getHeight() + 50
self.aiScore = 0
end
function Score:update(dt)
self:scoreUpdate(dt)
end
function Score:scoreUpdate(dt)
if Ball.x < 0 then
self.aiScore = self.aiScore + 1 * dt
end
if Ball.x + Ball.width > love.graphics.getWidth() then
self.playerScore = self.playerScore + 1 * dt
end
end
function Score:draw()
love.graphics.print("SCORE:", self.x, self.y)
love.graphics.print(tostring(self.playerScore), self.xPlayerScore, self.yPlayerScore)
love.graphics.print(tostring(self.aiScore), self.xAiScore, self.yAiScore)
end
Text doesn't get updated [SOLVED]
Forum rules
Before you make a thread asking for help, read this.
Before you make a thread asking for help, read this.
Text doesn't get updated [SOLVED]
- Attachments
-
- score.lua
- score file
- (1.04 KiB) Downloaded 141 times
- zorg
- Party member
- Posts: 3465
- Joined: Thu Dec 13, 2012 2:55 pm
- Location: Absurdistan, Hungary
- Contact:
Re: Text doesn't get updated [SOLVED]
Considering you didn't share more code, i'm going to assume the problem lies elsewhere that affects only the left side, otherwise you'd have said that that margin was required on the other side as well... probably something with checking the ball's position, and changing it if it goes below 0, which makes sense... but that also should change if it goes above the window width, who knows.
A more elegant solution could be Ball.x + Ball.width < 0 and Ball.x > love.graphics.getWidth(), if you want to allow the ball actually going out of bounds.
A more elegant solution could be Ball.x + Ball.width < 0 and Ball.x > love.graphics.getWidth(), if you want to allow the ball actually going out of bounds.
Me and my stuff True Neutral Aspirant. Why, yes, i do indeed enjoy sarcastically correcting others when they make the most blatant of spelling mistakes. No bullying or trolling the innocent tho.
Re: Text doesn't get updated [SOLVED]
I did have to add a margin to the right side too, forgot to add. I'll try your solution later today and update my original post for anyone who's facing the same issue
Who is online
Users browsing this forum: Ahrefs [Bot], Google [Bot] and 2 guests