SpriteSheet 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.
KyleFlores1014
Citizen
Posts: 73
Joined: Thu May 25, 2017 1:43 pm

SpriteSheet Help

Post by KyleFlores1014 »

I was trying this spritesheet that my friend sent me. Ive tried multiple ways which wasnt efficient so I tried this but now Im getting an error I dont know whats wrong. I tried my best to debug it but I cant see it. If theres a better way of doing this, just reply with it. Thanks
Spritest.zip
(16.05 KiB) Downloaded 151 times
brogrammer
Prole
Posts: 15
Joined: Tue Oct 17, 2017 11:26 pm

Re: SpriteSheet Help

Post by brogrammer »

you need to make sure activeF is not nil when first drawing the player
coz it's not going to be magically 0.1 seconds later in the first frame
KyleFlores1014
Citizen
Posts: 73
Joined: Thu May 25, 2017 1:43 pm

Re: SpriteSheet Help

Post by KyleFlores1014 »

Ive found my mistake there. Sorry for that, I have fixed it and the only problems are when the player moves it doesnt transition to the walking animation
Spritest.zip
(16.06 KiB) Downloaded 146 times
User avatar
Azhukar
Party member
Posts: 478
Joined: Fri Oct 26, 2012 11:54 am

Re: SpriteSheet Help

Post by Azhukar »

KyleFlores1014 wrote: Thu Oct 19, 2017 12:06 pm Ive found my mistake there. Sorry for that, I have fixed it and the only problems are when the player moves it doesnt transition to the walking animation
You need to increment your table index CF.
KyleFlores1014
Citizen
Posts: 73
Joined: Thu May 25, 2017 1:43 pm

Re: SpriteSheet Help

Post by KyleFlores1014 »

Will this transition my sprite to the walking animation? and how do I do this?
User avatar
Azhukar
Party member
Posts: 478
Joined: Fri Oct 26, 2012 11:54 am

Re: SpriteSheet Help

Post by Azhukar »

Code: Select all

ETime = ETime + dt
if ETime > 0.1 then
	CF = CF + 1
	if CF > total then
		CF = 1
	end
	activeF = frames[CF]
	ETime = 0
end
Notice that in your original code you had the variable ETime with a small "t" and with a capital "T", this makes them two completely different variables. Pick a naming convention and stick with it, I recommend https://en.wikipedia.org/wiki/CamelCase and not shortening words unless you're dealing with really long variable names. Short names only make your code unreadable.

You're also indexing your "Player.png" image incorrectly, you need to take into account the vertical position of your quads, not just horizontal.
KyleFlores1014
Citizen
Posts: 73
Joined: Thu May 25, 2017 1:43 pm

Re: SpriteSheet Help

Post by KyleFlores1014 »

I didnt realize that but now I have fixed and now im recieving an error when pressing A or D? I dont know why it does this
Spritest.zip
(16.09 KiB) Downloaded 141 times
User avatar
Azhukar
Party member
Posts: 478
Joined: Fri Oct 26, 2012 11:54 am

Re: SpriteSheet Help

Post by Azhukar »

Notice I wrote

Code: Select all

if CF > total then
In your code you have

Code: Select all

if CF < total then
The reason why you're getting that error is that you increment CF but never limit what value it can be, meaning it will be incremented forever and you'll start indexing your table where you did not intend.
KyleFlores1014
Citizen
Posts: 73
Joined: Thu May 25, 2017 1:43 pm

Re: SpriteSheet Help

Post by KyleFlores1014 »

I tried it but still does the same. It can be read after the 3rd or 4th walking animation, also I have tried testing each frame and it works I just dont know why it does this.
Spritest.zip
(16.12 KiB) Downloaded 143 times
User avatar
Azhukar
Party member
Posts: 478
Joined: Fri Oct 26, 2012 11:54 am

Re: SpriteSheet Help

Post by Azhukar »

It should be

Code: Select all

if CF > total then
But you're setting the 'total' to 8 for WalkR and WalkL, when it should be 6 in those cases. You can ditch the 'total' variable altogether if you use

Code: Select all

if CF > #frames then
You seem to be struggling with very basic concepts, I recommend you try to go through your code line by line and think of what happens when each line gets executed and in what order will they get executed.
Post Reply

Who is online

Users browsing this forum: Ahrefs [Bot], Semrush [Bot] and 49 guests