Page 1 of 1

Adding custom sprite frames

Posted: Tue Sep 10, 2019 6:21 pm
by marquise
Hello. I'm currently making a custom sprite that goes over the standard small Mario and i'm trying to make some extra frames for example a frame to look up and one to duck. Been reseaching and experimenting with LunaLua and I've sort of got it half working, as in The frame I want to display flickers on and off while holding down and running either direction. But can't seem to get it working while just holding down. Here's a an example of it in action:

Image

And here's the code I'm using:

Code: Select all

function onTick()
    if (player.downKeyPressing) then
        player:mem(0x114, FIELD_WORD, 23)
    end
end

Would anyone be able to help point out where I'm going wrong here?

Thank you.

Re: Adding custom sprite frames

Posted: Tue Sep 10, 2019 8:05 pm
by Hoeloe
First of all, if you're using onTick for setting the player's frame, I suggest using player:setFrame(23) rather than the memory address. Honestly, I suggest using that anyway. Also you should use player.keys.down rather than the outdated player.downKeyPressing

As for making it not happen while you're walking - consider what you're actually saying here: "If the down key is pressed, set the player's frame to 23." You have nothing anywhere telling it to consider whether you're moving left or right, or if you're even on the ground. Try considering something like:

if player.keys.down and not player.keys.left and not player.keys.right then

You may also want to add conditions for climing, swimming, etc.

Re: Adding custom sprite frames

Posted: Wed Sep 11, 2019 4:06 am
by marquise
Thank you, that code got it working. I've mostly been finding out what code is what by looking at the documentation and haven't seen that code at all.

Some very good points you've made there. I shall take that on board. Thank you again.

Re: Adding custom sprite frames

Posted: Wed Sep 11, 2019 6:32 am
by Emral
marquise wrote:
Wed Sep 11, 2019 4:06 am
Thank you, that code got it working. I've mostly been finding out what code is what by looking at the documentation and haven't seen that code at all.

Some very good points you've made there. I shall take that on board. Thank you again.
For ducking in particular, one other solution to all these conditionals could be to use the "is ducking?" flag directly:

if player:mem(0x12E, FIELD_BOOL) then (as per the docs)

If you're in a scenario where there's a 1:1 overlap in functionality between a source frame number and a desired frame number, you can also remap the frame directly. While for ducking there's a simple offset that can be used, too, there are other states that don't have this luxury. Consider, for example, the skidding state (where the player tries to move the opposite direction to which they previously moved. They only do it on the ground and under specific conditions, so it would be easier to just kinda cheat a little and piggyback off SMBX's decision of what frame to set:

local frameRemappingTable = {
[6] = 12, --remaps the skidding frame location from sheet position 6 to 12
[1] = 10, --another random example to showcase that this table can be expanded
}

function onTickEnd()
if frameRemappingTable[player.frame] then
player.frame = frameRemappingTable[player.frame] -- If a remap is desired, do it.
end
end

Re: Adding custom sprite frames

Posted: Wed Sep 11, 2019 8:35 am
by Hoeloe
Enjl wrote:
Wed Sep 11, 2019 6:32 am

For ducking in particular, one other solution to all these conditionals could be to use the "is ducking?" flag directly:
I don't believe this will work for this case, since this appears to be trying to add a ducking frame to small Mario, who currently doesn't actually have a duck state. I don't believe this flag is ever set when you're playing as small Mario.

Re: Adding custom sprite frames

Posted: Wed Sep 11, 2019 8:43 am
by Emral
Hoeloe wrote:
Wed Sep 11, 2019 8:35 am
Enjl wrote:
Wed Sep 11, 2019 6:32 am

For ducking in particular, one other solution to all these conditionals could be to use the "is ducking?" flag directly:
I don't believe this will work for this case, since this appears to be trying to add a ducking frame to small Mario, who currently doesn't actually have a duck state. I don't believe this flag is ever set when you're playing as small Mario.
Ohh duh, sorry. Don't know how I missed that.

Re: Adding custom sprite frames

Posted: Wed Sep 11, 2019 8:55 am
by Hoeloe
marquise wrote:
Wed Sep 11, 2019 4:06 am
by looking at the documentation
Oh I should also note that the documentation isn't fully up to date. The best places to find information are the handbook, this video series, and the Codehaus Discord server.