Adding custom sprite frames

Post here for help and support regarding LunaLua and SMBX2's libraries and features.

Moderator: Userbase Moderators

marquise
Shy Guy
Shy Guy
Posts: 5
Joined: Sat Sep 29, 2018 5:20 pm
Flair: Family man

Adding custom sprite frames

Postby marquise » Tue Sep 10, 2019 6:21 pm

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.

Hoeloe
Phanto
Phanto
Posts: 1465
Joined: Sat Oct 03, 2015 6:18 pm
Flair: The Codehaus Girl
Pronouns: she/her

Re: Adding custom sprite frames

Postby Hoeloe » Tue Sep 10, 2019 8:05 pm

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.

marquise
Shy Guy
Shy Guy
Posts: 5
Joined: Sat Sep 29, 2018 5:20 pm
Flair: Family man

Re: Adding custom sprite frames

Postby marquise » 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.

Emral
Cute Yoshi Egg
Cute Yoshi Egg
Posts: 9891
Joined: Mon Jan 20, 2014 12:58 pm
Flair: Phoenix

Re: Adding custom sprite frames

Postby Emral » Wed Sep 11, 2019 6:32 am

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

Hoeloe
Phanto
Phanto
Posts: 1465
Joined: Sat Oct 03, 2015 6:18 pm
Flair: The Codehaus Girl
Pronouns: she/her

Re: Adding custom sprite frames

Postby Hoeloe » 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.

Emral
Cute Yoshi Egg
Cute Yoshi Egg
Posts: 9891
Joined: Mon Jan 20, 2014 12:58 pm
Flair: Phoenix

Re: Adding custom sprite frames

Postby Emral » Wed Sep 11, 2019 8:43 am

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.

Hoeloe
Phanto
Phanto
Posts: 1465
Joined: Sat Oct 03, 2015 6:18 pm
Flair: The Codehaus Girl
Pronouns: she/her

Re: Adding custom sprite frames

Postby Hoeloe » Wed Sep 11, 2019 8:55 am

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.


Return to “LunaLua Help”

Who is online

Users browsing this forum: No registered users and 24 guests

SMWCentralTalkhausMario Fan Games GalaxyKafukaMarioWikiSMBXEquipoEstelari