Two things

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.
User avatar
TurtleP
Party member
Posts: 147
Joined: Thu Mar 22, 2012 9:20 pm
Contact:

Two things

Post by TurtleP »

Hello All,

I have been trying to make a new image appear, but LOVE won't see it exists, which it does when compressed into the .love.
Second, I am trying to do tile scrolling as made in the tile-scrolling tutorial on the Wiki. It's not working. Can someone help me fix this?

Code: Select all

function love.load()
    player = {
        grid_x = 400,
        grid_y = 320,
        act_x = 200,
        act_y = 200,
        speed = 10
    }
    map = {
        { 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1 },
        { 1, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1 },
        { 1, 0, 1, 1, 0, 0, 0, 0, 1, 0, 0, 1, 0, 1 },
        { 1, 1, 1, 1, 0, 0, 0, 0, 1, 0, 0, 1, 0, 1 },
        { 1, 1, 0, 1, 0, 1, 1, 1, 1, 0, 0, 0, 0, 1 },
        { 1, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1 },
        { 1, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1 },
        { 1, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1 },
        { 1, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1 },
        { 1, 0, 0, 1, 0, 0, 0, 0, 1, 1, 1, 1, 0, 1 },
        { 1, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1 },
        { 1, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1 },
        { 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1 }
    }
	
	music = love.audio.newSource("pallet.wav")
	love.audio.play(music)
   map_w = 20
   map_h = 20
   map_x = 0
   map_y = 0
   tile_w = 40
   tile_h = 40
   map_offset_x = 30
   map_offset_y = 30
   map_display_w = 14
   map_display_h = 10
end

function love.update(dt)
    player.act_y = player.act_y - ((player.act_y - player.grid_y) * player.speed * dt)
    player.act_x = player.act_x - ((player.act_x - player.grid_x) * player.speed * dt)
end

function love.draw()
	draw_map()
    love.graphics.rectangle("fill", player.act_x, player.act_y, 40, 40)
    
end

function love.keypressed(key)
    if key == "up" then
        if testMap(0, -1) then
            player.grid_y = player.grid_y - 40
        end
    elseif key == "down" then
        if testMap(0, 1) then
            player.grid_y = player.grid_y + 40
        end
    elseif key == "left" then
        if testMap(-1, 0) then
            player.grid_x = player.grid_x - 40
        end
    elseif key == "right" then
        if testMap(1, 0) then
            player.grid_x = player.grid_x + 40
        end
    end
	
	if key == 'up' then
      map_y = map_y-1
      if map_y < 0 then map_y = 0; end
   end
   if key == 'down' then
      map_y = map_y+1
      if map_y > map_h-map_display_h then map_y = map_h-map_display_h; end
   end
   
   if key == 'left' then
      map_x = math.max(map_x-1, 0)
   end
   if key == 'right' then
      map_x = math.min(map_x+1, map_w-map_display_w)
   end
end

function testMap(x, y)
    if map[(player.grid_y / 40) + y][(player.grid_x / 40) + x] == 1 then
        return false
    end
    return true
end

function draw_map()

	for y=1, map_display_h do
        for x=1, map_display_w do
            if map[y][x] == 1 then
                love.graphics.rectangle("line"[map[y+map_y][x+map_x]],(x*tile_w)+map_offset_x, (y*tile_h)+map_offset_y)
            end
        end
    end
	
end
User avatar
tentus
Inner party member
Posts: 1060
Joined: Sun Oct 31, 2010 7:56 pm
Location: Appalachia
Contact:

Re: Two things

Post by tentus »

Code: Select all

love.graphics.rectangle("line"[map[y+map_y][x+map_x]],(x*tile_w)+map_offset_x, (y*tile_h)+map_offset_y)
This is not how love.graphics.rectangle is supposed to work. You've halfway combined two different functions. I think you meant to use love.graphics.draw().

If you did mean to use love.graphics.draw(), you need to define the image first, in love.load.
Kurosuke needs beta testers
User avatar
TurtleP
Party member
Posts: 147
Joined: Thu Mar 22, 2012 9:20 pm
Contact:

Re: Two things

Post by TurtleP »

tentus wrote:

Code: Select all

love.graphics.rectangle("line"[map[y+map_y][x+map_x]],(x*tile_w)+map_offset_x, (y*tile_h)+map_offset_y)
This is not how rectangle is supposed to work. You've halfway combined two different functions. I think you meant to use love.graphics.draw().
Thanks, but also:

I did this,

PlayerR = love.graphics.newImage("PlayerD.png")

When I made the .love (I was trying to draw this as well) it said it did not exist.
Dallox
Prole
Posts: 16
Joined: Sun Mar 11, 2012 7:16 pm
Location: Netherlands

Re: Two things

Post by Dallox »

TurtleP wrote:
tentus wrote:

Code: Select all

love.graphics.rectangle("line"[map[y+map_y][x+map_x]],(x*tile_w)+map_offset_x, (y*tile_h)+map_offset_y)
This is not how rectangle is supposed to work. You've halfway combined two different functions. I think you meant to use love.graphics.draw().
Thanks, but also:

I did this,

PlayerR = love.graphics.newImage("PlayerD.png")

When I made the .love (I was trying to draw this as well) it said it did not exist.
It might help if you upload the love file.
User avatar
tentus
Inner party member
Posts: 1060
Joined: Sun Oct 31, 2010 7:56 pm
Location: Appalachia
Contact:

Re: Two things

Post by tentus »

Could you post your full, current code? I can't help you if you give us an abridged version: your initial post does not contain the line of code you mentioned.

Something to consider: PlayerD.png does not equal playerd.png (caps matter!)
Kurosuke needs beta testers
User avatar
TurtleP
Party member
Posts: 147
Joined: Thu Mar 22, 2012 9:20 pm
Contact:

Re: Two things

Post by TurtleP »

tentus wrote:Could you post your full, current code? I can't help you if you give us an abridged version: your initial post does not contain the line of code you mentioned.

Something to consider: PlayerD.png does not equal playerd.png (caps matter!)
I know, I typed it quite exact. It wasn't in my code because I removed it prior to making this topic. This is with those lines inside the code:

It tells me when I try to run it:
"Could not open file PlayerD.png. Does not exist.

Callback: Line 37 in function 'load'

Would it matter that for some reason, the .png is capitalized in the .love?

Code: Select all

function love.load()
    player = {
        grid_x = 400,
        grid_y = 320,
        act_x = 200,
        act_y = 200,
        speed = 10
    }
    map = {
        { 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1 },
        { 1, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1 },
        { 1, 0, 1, 1, 0, 0, 0, 0, 1, 0, 0, 1, 0, 1 },
        { 1, 1, 1, 1, 0, 0, 0, 0, 1, 0, 0, 1, 0, 1 },
        { 1, 1, 0, 1, 0, 1, 1, 1, 1, 0, 0, 0, 0, 1 },
        { 1, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1 },
        { 1, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1 },
        { 1, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1 },
        { 1, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1 },
        { 1, 0, 0, 1, 0, 0, 0, 0, 1, 1, 1, 1, 0, 1 },
        { 1, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1 },
        { 1, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1 },
        { 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1 }
    }
	
	music = love.audio.newSource("pallet.wav")
	love.audio.play(music)
   map_w = 20
   map_h = 20
   map_x = 0
   map_y = 0
   tile_w = 40
   tile_h = 40
   map_offset_x = 30
   map_offset_y = 30
   map_display_w = 14
   map_display_h = 10
   PlayerD = love.graphics.newImage("PlayerD.png")
   Barrier = love.graphics.newImage("Barrier.png")
end

function love.update(dt)
    player.act_y = player.act_y - ((player.act_y - player.grid_y) * player.speed * dt)
    player.act_x = player.act_x - ((player.act_x - player.grid_x) * player.speed * dt)
end

function love.draw()
	draw_map()
    love.graphics.draw(PlayerD, player.act_x, player.act_y, 40, 40)
    
end

function love.keypressed(key)
    if key == "up" then
        if testMap(0, -1) then
            player.grid_y = player.grid_y - 40
        end
    elseif key == "down" then
        if testMap(0, 1) then
            player.grid_y = player.grid_y + 40
        end
    elseif key == "left" then
        if testMap(-1, 0) then
            player.grid_x = player.grid_x - 40
        end
    elseif key == "right" then
        if testMap(1, 0) then
            player.grid_x = player.grid_x + 40
        end
    end
	
	if key == 'up' then
      map_y = map_y-1
      if map_y < 0 then map_y = 0; end
   end
   if key == 'down' then
      map_y = map_y+1
      if map_y > map_h-map_display_h then map_y = map_h-map_display_h; end
   end
   
   if key == 'left' then
      map_x = math.max(map_x-1, 0)
   end
   if key == 'right' then
      map_x = math.min(map_x+1, map_w-map_display_w)
   end
end

function testMap(x, y)
    if map[(player.grid_y / 40) + y][(player.grid_x / 40) + x] == 1 then
        return false
    end
    return true
end

function draw_map()

	for y=1, map_display_h do
        for x=1, map_display_w do
            if map[y][x] == 1 then
                love.graphics.draw(Barrier[map[y+map_y][x+map_x]],(x*tile_w)+map_offset_x, (y*tile_h)+map_offset_y)
            end
        end
    end
	
end
User avatar
TurtleP
Party member
Posts: 147
Joined: Thu Mar 22, 2012 9:20 pm
Contact:

Re: Two things

Post by TurtleP »

TurtleP wrote:
tentus wrote:Could you post your full, current code? I can't help you if you give us an abridged version: your initial post does not contain the line of code you mentioned.

Something to consider: PlayerD.png does not equal playerd.png (caps matter!)
I know, I typed it quite exact. It wasn't in my code because I removed it prior to making this topic. This is with those lines inside the code:

It tells me when I try to run it:
"Could not open file PlayerD.png. Does not exist.

Callback: Line 37 in function 'load'

Would it matter that for some reason, the .png is capitalized in the .love?

Code: Select all

function love.load()
    player = {
        grid_x = 400,
        grid_y = 320,
        act_x = 200,
        act_y = 200,
        speed = 10
    }
    map = {
        { 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1 },
        { 1, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1 },
        { 1, 0, 1, 1, 0, 0, 0, 0, 1, 0, 0, 1, 0, 1 },
        { 1, 1, 1, 1, 0, 0, 0, 0, 1, 0, 0, 1, 0, 1 },
        { 1, 1, 0, 1, 0, 1, 1, 1, 1, 0, 0, 0, 0, 1 },
        { 1, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1 },
        { 1, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1 },
        { 1, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1 },
        { 1, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1 },
        { 1, 0, 0, 1, 0, 0, 0, 0, 1, 1, 1, 1, 0, 1 },
        { 1, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1 },
        { 1, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1 },
        { 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1 }
    }
	
	music = love.audio.newSource("pallet.wav")
	love.audio.play(music)
   map_w = 20
   map_h = 20
   map_x = 0
   map_y = 0
   tile_w = 40
   tile_h = 40
   map_offset_x = 30
   map_offset_y = 30
   map_display_w = 14
   map_display_h = 10
   PlayerD = love.graphics.newImage("PlayerD.png")
   Barrier = love.graphics.newImage("Barrier.png")
end

function love.update(dt)
    player.act_y = player.act_y - ((player.act_y - player.grid_y) * player.speed * dt)
    player.act_x = player.act_x - ((player.act_x - player.grid_x) * player.speed * dt)
end

function love.draw()
	draw_map()
    love.graphics.draw(PlayerD, player.act_x, player.act_y, 40, 40)
    
end

function love.keypressed(key)
    if key == "up" then
        if testMap(0, -1) then
            player.grid_y = player.grid_y - 40
        end
    elseif key == "down" then
        if testMap(0, 1) then
            player.grid_y = player.grid_y + 40
        end
    elseif key == "left" then
        if testMap(-1, 0) then
            player.grid_x = player.grid_x - 40
        end
    elseif key == "right" then
        if testMap(1, 0) then
            player.grid_x = player.grid_x + 40
        end
    end
	
	if key == 'up' then
      map_y = map_y-1
      if map_y < 0 then map_y = 0; end
   end
   if key == 'down' then
      map_y = map_y+1
      if map_y > map_h-map_display_h then map_y = map_h-map_display_h; end
   end
   
   if key == 'left' then
      map_x = math.max(map_x-1, 0)
   end
   if key == 'right' then
      map_x = math.min(map_x+1, map_w-map_display_w)
   end
end

function testMap(x, y)
    if map[(player.grid_y / 40) + y][(player.grid_x / 40) + x] == 1 then
        return false
    end
    return true
end

function draw_map()

	for y=1, map_display_h do
        for x=1, map_display_w do
            if map[y][x] == 1 then
                love.graphics.draw(Barrier[map[y+map_y][x+map_x]],(x*tile_w)+map_offset_x, (y*tile_h)+map_offset_y)
            end
        end
    end
	
end
Sorry for double post. It seems it does matter. However, drawing a barrier makes it tell me it expected userdata. This is done at function draw_map(). I am trying to follow the tiled map scrolling tutorial.
coffee
Party member
Posts: 1206
Joined: Wed Nov 02, 2011 9:07 pm

Re: Two things

Post by coffee »

TurtleP wrote:
TurtleP wrote:
tentus wrote:Could you post your full, current code? I can't help you if you give us an abridged version: your initial post does not contain the line of code you mentioned.

Something to consider: PlayerD.png does not equal playerd.png (caps matter!)
I know, I typed it quite exact. It wasn't in my code because I removed it prior to making this topic. This is with those lines inside the code:

It tells me when I try to run it:
"Could not open file PlayerD.png. Does not exist.
You must have an exactly named "PlayerD.png" in same directory than your main.love. Also try to instead use lowercase just for debugging for now. Can you post your .Love file (zip the files inside directory)?
User avatar
TurtleP
Party member
Posts: 147
Joined: Thu Mar 22, 2012 9:20 pm
Contact:

Re: Two things

Post by TurtleP »

coffee wrote:
You must have a exactly named "PlayerD.png" in same directory than your main.love. Also try to instead use lowercase just for debugging for now. Can you post your .Love file (zip the files inside directory)?
Yes, would you like to see my Source? Drawing a barrier seems to be a situation for me, I am not sure why though. Included are the images I am going to use.
It wouldn't let me add the .love, here's mediafire link:

http://www.mediafire.com/?vtu692pfhomsvxb
coffee
Party member
Posts: 1206
Joined: Wed Nov 02, 2011 9:07 pm

Re: Two things

Post by coffee »

TurtleP wrote:
coffee wrote:
You must have a exactly named "PlayerD.png" in same directory than your main.love. Also try to instead use lowercase just for debugging for now. Can you post your .Love file (zip the files inside directory)?
Yes, would you like to see my Source? Drawing a barrier seems to be a situation for me, I am not sure why though. Included are the images I am going to use.
It wouldn't let me add the .love, here's mediafire link:

http://www.mediafire.com/?vtu692pfhomsvxb
You can't attach because your wav is to big. try convert all songs or evens sounds to .ogg. LOVE play it better and take less space.
no PlayerD.png error after all. you discovered that is PlayerD.PNG right?
error on draw. it should be
love.graphics.draw(Barrier,map[y+map_y][x+map_x], x*40,y*40)
but result is horrible lol. You are scaling 40x!
Post Reply

Who is online

Users browsing this forum: No registered users and 46 guests