Page 1 of 1

I'd love some help

Posted: Wed Oct 13, 2010 8:04 pm
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?

Re: I'd love some help

Posted: Wed Oct 13, 2010 8:13 pm
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.

Re: I'd love some help

Posted: Thu Oct 14, 2010 3:13 am
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.

Re: I'd love some help

Posted: Thu Oct 14, 2010 6:59 pm
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. :)

Re: I'd love some help

Posted: Thu Oct 14, 2010 8:08 pm
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)

Re: I'd love some help

Posted: Thu Oct 14, 2010 9:09 pm
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



Re: I'd love some help

Posted: Mon Oct 18, 2010 8:50 pm
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.

Re: I'd love some help

Posted: Tue Oct 19, 2010 12:11 am
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?

Re: I'd love some help

Posted: Tue Oct 19, 2010 4:48 am
by 8t
Not isometric, I meant orthogonal. Just fire up a Blue Version and you'll see what I'm getting at.