I'd love some help

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
8t
Prole
Posts: 8
Joined: Sat Sep 25, 2010 6:30 pm

I'd love some help

Post by 8t »

So I have some issues with the draw function. I'm trying to make a sprite based character walk in NSEW directions, but I keep getting errors. I'm able to move a singular sprite and animate a sprite, but I can't animate a moving sprite and have it change facing or stop animating.

So what's the deal? I'm a newb here, and I know if I can get passed this hurdle of getting my characters to walk I can base the rest of my game off of that code, so can someone give me a hand here? Can someone share some generic code so I can get my graphics working right?
User avatar
Robin
The Omniscient
Posts: 6506
Joined: Fri Feb 20, 2009 4:29 pm
Location: The Netherlands
Contact:

Re: I'd love some help

Post by Robin »

Well, I'd love to do that, but some generic code rarely does the trick. ;) Perhaps if you shared your code with us, preferably in .love form, we could explain how we would solve this, given your existing code.
Help us help you: attach a .love.
8t
Prole
Posts: 8
Joined: Sat Sep 25, 2010 6:30 pm

Re: I'd love some help

Post by 8t »

This is what I got. I think with some review I have an idea of what my problem is, but I've only been reading books and tutorials and I still need some hands-on help with this.

And thanks for the love.
Attachments
main.lua
(7.59 KiB) Downloaded 287 times
User avatar
Robin
The Omniscient
Posts: 6506
Joined: Fri Feb 20, 2009 4:29 pm
Location: The Netherlands
Contact:

Re: I'd love some help

Post by Robin »

All right. You do know you can just put the animation code in a file called animations.lua and in your main.lua insert a line on top saying:

Code: Select all

require "animations"
?

For your actual problem, I think the best course of action here is to drop this game for a while, because it looks like it will be quite complicated, and just spend some time getting familiar with LÖVE, for example trying out the Tutorials, and making simple tests or games. Then you'll have an idea where to begin, because at this stage, I can't help you with this particular game without writing it for you. :)
Help us help you: attach a .love.
User avatar
zac352
Party member
Posts: 496
Joined: Sat Aug 28, 2010 8:13 pm
Location: In your head.
Contact:

Re: I'd love some help

Post by zac352 »

You're trying to accomplish cardinal directions?

Code: Select all

directions={
["N"]=0,
["E"]=math.pi/2,
["S"]=math.pi,
["W"]=math.pi*1.5
}
Edit:

Code: Select all

--Usage:
love.graphics.draw(myImg, x, y, directions[myDir], sx, sy, ox, oy)
Hello, I am not dead.
User avatar
Adamantos
Prole
Posts: 27
Joined: Sun May 16, 2010 10:47 pm

Re: I'd love some help

Post by Adamantos »

Hi "8t",

here is a little example on how you can handle animations very elemantary without the AnAL-library.
The code is hacked together "quick and dirty", but I hope, that you can learn how to draw
an animated image properly :)

Code: Select all

player = {
	position  = {100,100},
	velocity  = {0,0},
  direction = 0,
  speed     = 40,
  phase     = 0
}


function love.load()
  imgPlayer = love.graphics.newImage( "player.png" )
end
  


function love.update(dt)
  -- check for controls
  playerStop()
	if love.keyboard.isDown("up") then    playerSetDirection("N") end
	if love.keyboard.isDown("down") then  playerSetDirection("S") end
  if love.keyboard.isDown("left") then  playerSetDirection("W") end
  if love.keyboard.isDown("right") then playerSetDirection("E") end
  
  playerUpdate(dt)
end



function love.draw()
	playerDraw()
end






function playerDraw()
  love.graphics.setColor(255,255,255,255)
  love.graphics.drawq(
    imgPlayer,
    love.graphics.newQuad(math.floor(player.phase)*32,player.direction*32 , 32,32,256,128),
    player.position[1],
    player.position[2]
  )	
end



function playerSetDirection(dir) 
	if(dir=="E") then player.velocity  = { 1, 0} player.direction=0 end
	if(dir=="S") then player.velocity  = { 0, 1} player.direction=1 end
	if(dir=="W") then player.velocity  = {-1, 0} player.direction=2 end
	if(dir=="N") then player.velocity  = { 0,-1} player.direction=3 end
end



function playerStop()
	player.velocity = {0,0}
end


function playerUpdate(dt)
	-- stop animation
	if (player.velocity[1] == 0 and player.velocity[2] == 0 ) then 
		player.phase = 0
		return 
	end
	
	-- move
  player.position[1] = player.position[1] + player.velocity[1] * player.speed * dt
  player.position[2] = player.position[2] + player.velocity[2] * player.speed * dt

  -- animate
  player.phase = (player.phase + dt*6 ) %4

end


Attachments
animation.love
Simple character animation
(22.13 KiB) Downloaded 303 times
8t
Prole
Posts: 8
Joined: Sat Sep 25, 2010 6:30 pm

Re: I'd love some help

Post by 8t »

Since I'm a newb, could someone just write up some code for me, so I can get a general direction for this game? I'll even give the graphics I made so you can get an idea of what I'm trying to do--Pokemon graphics.

Basically, I'm going for a tile based game with characters that snap to a grid. Also, I want some overlapping, like you see in the newer Pokemon games for GBA and DS, or like in Final Fantasy VI.

The names of the sprite strips I'm uploading do not match my code because I had them as separate images on my computer. Each frame is 18x26.
Attachments
Kalyan_Walking_SWNE.png
Kalyan_Walking_SWNE.png (2.86 KiB) Viewed 8282 times
Kalyan_Standing_SWNE.png
Kalyan_Standing_SWNE.png (1.75 KiB) Viewed 8282 times
main.lua
I changed this a little, but my idea failed.
(1.98 KiB) Downloaded 283 times
User avatar
zac352
Party member
Posts: 496
Joined: Sat Aug 28, 2010 8:13 pm
Location: In your head.
Contact:

Re: I'd love some help

Post by zac352 »

8t wrote:Since I'm a newb, could someone just write up some code for me, so I can get a general direction for this game? I'll even give the graphics I made so you can get an idea of what I'm trying to do--Pokemon graphics.

Basically, I'm going for a tile based game with characters that snap to a grid. Also, I want some overlapping, like you see in the newer Pokemon games for GBA and DS, or like in Final Fantasy VI.

The names of the sprite strips I'm uploading do not match my code because I had them as separate images on my computer. Each frame is 18x26.
So a form of isometric graphics, with a simple z-index?
Hello, I am not dead.
8t
Prole
Posts: 8
Joined: Sat Sep 25, 2010 6:30 pm

Re: I'd love some help

Post by 8t »

Not isometric, I meant orthogonal. Just fire up a Blue Version and you'll see what I'm getting at.
Post Reply

Who is online

Users browsing this forum: Ahrefs [Bot], Bing [Bot] and 6 guests