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?
I'd love some help
Forum rules
Before you make a thread asking for help, read this.
Before you make a thread asking for help, read this.
- Robin
- The Omniscient
- Posts: 6506
- Joined: Fri Feb 20, 2009 4:29 pm
- Location: The Netherlands
- Contact:
Re: I'd love some help
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.
Re: I'd love some help
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.
And thanks for the love.
- Attachments
-
- main.lua
- (7.59 KiB) Downloaded 287 times
- Robin
- The Omniscient
- Posts: 6506
- Joined: Fri Feb 20, 2009 4:29 pm
- Location: The Netherlands
- Contact:
Re: I'd love some help
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:
?
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.
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.
Re: I'd love some help
You're trying to accomplish cardinal directions?
Edit:
Code: Select all
directions={
["N"]=0,
["E"]=math.pi/2,
["S"]=math.pi,
["W"]=math.pi*1.5
}
Code: Select all
--Usage:
love.graphics.draw(myImg, x, y, directions[myDir], sx, sy, ox, oy)
Hello, I am not dead.
Re: I'd love some help
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
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
Re: I'd love some help
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.
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
-
- main.lua
- I changed this a little, but my idea failed.
- (1.98 KiB) Downloaded 282 times
Re: I'd love some help
So a form of isometric graphics, with a simple z-index?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.
Hello, I am not dead.
Re: I'd love some help
Not isometric, I meant orthogonal. Just fire up a Blue Version and you'll see what I'm getting at.
Who is online
Users browsing this forum: Ahrefs [Bot] and 11 guests