Multiple Jumping won't work

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
depakkumar
Prole
Posts: 2
Joined: Sat Oct 07, 2017 12:52 pm
Contact:

Multiple Jumping won't work

Post by depakkumar »

Hi all,
I'm new to this forum & also new to this language & game engine, i'm learning a course on udemy, In that course where I have to avoid multiple jumps(i.e the player should not jump when he is in air or not in contact with other objects, I got a error which Is shown in the image, I don't know whether It is a silly error, so please see it. And also could you please explain the logic in this jumping section, The tutor created a last 2 functions for this in main.lua & I still can't understand It & he is a good tutor by the way.

Main.lua

Code: Select all

function love.load(arg)

   --creating physics--
   myWorld=love.physics.newWorld(0, 500, sleep)
   myWorld:setCallBacks(beginContact, endContact, preSolve, postSolve)

   --importing sprites--
  sprites= {}
  sprites.coin_sheet= love.graphics.newImage('sprites/coin_sheet.png')
  sprites.player_jump=love.graphics.newImage('sprites/player_jump.png')
  sprites.player_stand=love.graphics.newImage('sprites/player_stand.png')
  require('player')
  --creating function for platforms
  platforms = {}
  spawnPlatform(50,400, 300, 30)
end

function love.update(dt)
  --calling the physics(note the colon not equal between myworld & update)--
  myWorld:update(dt)
  playerUpdate(dt)
end

function love.draw()
love.graphics.draw(sprites.player_stand, player.body:getX(), player.body:getY(), nil, nil, nil, sprites.player_stand:getWidth()/2, sprites.player_stand:getHeight()/2)

  for i,p in ipairs(platforms) do
    love.graphics.rectangle("fill", p.body:getX(), p.body:getY(), p.width, p.height)
  end

end

    function love.keypressed(key, scancode, isrepeat)
     if key=="w" or key=="up" and player.grounded==true  then
       player.body:applyLinearImpulse(0, -2500)--for making player jump

     end
    end

function spawnPlatform(x, y , width, height)
local platform = {}
platform.body= love.physics.newBody(myWorld, x, y, "static")
platform.shape= love.physics.newRectangleShape(width/2, height/2, width, height)-- width/2, height/2 moves the offset to upper left hand corner of this shape thereby matching with platform
platform.fixture= love.physics.newFixture(platform.body, platform.shape)
platform.width=width
platform.height=height
table.insert(platforms, platform)
end

function beginContact(a,b, coll)
 player.grounded=true
end

function endContact(a, b, coll)
player.grounded=false
end
player.lua

Code: Select all

player={}
--creating player physics
player.body=love.physics.newBody(myWorld, 100, 100, "dynamic")
player.shape=love.physics.newRectangleShape(66, 92)
--A fixture acts as a connection between body & shape--
player.fixture=love.physics.newFixture(player.body, player.shape, density)
player.speed=100
player.grounded=false

function playerUpdate(dt)
  if love.keyboard.isDown("left") or love.keyboard.isDown("a") then
    player.body:setX(player.body:getX() - player.speed * dt)
  end
  if love.keyboard.isDown("right") or love.keyboard.isDown("d") then
    player.body:setX(player.body:getX() + player.speed * dt)
  end
end
Attachments
This is the error image
This is the error image
Capture.PNG (23.53 KiB) Viewed 2399 times
User avatar
bartbes
Sex machine
Posts: 4946
Joined: Fri Aug 29, 2008 10:35 am
Location: The Netherlands
Contact:

Re: Multiple Jumping won't work

Post by bartbes »

The error is fairly simple to explain. The function you're trying to call is World:setCallbacks, note that it has a lower case b.

As for the jumping, applying an impulse is much like applying a force over a short period of time. In this case you apply an upward impulse, kind of like you do in real life when you push down on the ground to jump (and the ground pushes back).
depakkumar
Prole
Posts: 2
Joined: Sat Oct 07, 2017 12:52 pm
Contact:

Re: Multiple Jumping won't work

Post by depakkumar »

yeah Thanks bro!!!!!
Post Reply

Who is online

Users browsing this forum: Ahrefs [Bot], Google [Bot] and 4 guests