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 » Thu Oct 19, 2017 10:44 am

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 49 times

brogrammer
Prole
Posts: 14
Joined: Tue Oct 17, 2017 11:26 pm

Re: SpriteSheet Help

Post by brogrammer » Thu Oct 19, 2017 11:18 am

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 » 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
Spritest.zip
(16.06 KiB) Downloaded 43 times

User avatar
Azhukar
Party member
Posts: 478
Joined: Fri Oct 26, 2012 11:54 am

Re: SpriteSheet Help

Post by Azhukar » Thu Oct 19, 2017 12:33 pm

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 » Thu Oct 19, 2017 12:45 pm

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 » Thu Oct 19, 2017 1:20 pm

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 » Thu Oct 19, 2017 1:41 pm

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 39 times

User avatar
Azhukar
Party member
Posts: 478
Joined: Fri Oct 26, 2012 11:54 am

Re: SpriteSheet Help

Post by Azhukar » Thu Oct 19, 2017 2:05 pm

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 » Fri Oct 20, 2017 10:03 am

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 44 times

User avatar
Azhukar
Party member
Posts: 478
Joined: Fri Oct 26, 2012 11:54 am

Re: SpriteSheet Help

Post by Azhukar » Fri Oct 20, 2017 4:28 pm

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: Bing [Bot], nosuchfile and 16 guests