I made what I thought would be a fairly simple program is supposed to create a physics ball and draw it. The error is when it goes to draw the ellipse
Heres my main
function setup()
game = Game()
end
function draw()
game:draw()
end
I create a game and run its draw
Here’s my game class
Game = class()
function Game:init()
ball = Ball()
end
function Game:draw()
ball:draw()
end
Then I create a ball in init and draw it in draw
Here’s my ball class
Ball = class()
function Ball:init()
self.d = 100
ball = physics.body(CIRCLE,self.d/2)
ball.x = 100
ball.y = 100
ball.gravityScale = 1
ball.restitution = 1
ball.friction = 1
print("Ball init has been ran")
end
function Ball:draw()
print(ball.y)
print(ball.x)
print(self.d)
pushStyle()
fill(229, 16, 36, 255)
ellipse(ball.x, ball.y, r)
popStyle()
end
And here’s where all the hard code for the ball is. The error is when it goes to draw the ellipse. In the draw for the ball it doesn’t know what ball.x and ball.y are. This code, outside of a class and just in mains setup and draw works fine so it really puzzles me why it wont work. Thanks in advance.