Post here for help and support regarding LunaLua and SMBX2's libraries and features.
|
|
|
|
-
Marioman2007
- Lakitu
- Posts: 465
- Joined: Tue Aug 25, 2020 3:19 am
- Flair: Dr. Bones
- Pronouns: He/Him
Postby Marioman2007 » Mon May 30, 2022 12:06 pm
LunarCatUSA wrote: ↑Mon May 30, 2022 10:05 am
Okay, and to clarify;
It should be under "OnTick()" and I use the function "player.frame = 48"?
Yes, under onTick() or onDraw().
And you should do
Code: Select all player.frame = 48 * player.direction
Or
|
|
|
|
|
|
|
|
|
-
Emral
- Cute Yoshi Egg
- Posts: 9718
- Joined: Mon Jan 20, 2014 12:58 pm
- Flair: Phoenix
Postby Emral » Mon May 30, 2022 12:12 pm
onTick is a bad idea because onTick runs before the internal code sets the animation frame. onTickEnd is better because it runs after, onDraw ideal.
|
|
|
|
|
|
|
|
|
-
LunarCatUSA
- Hoopster
- Posts: 115
- Joined: Sat Mar 06, 2021 9:56 am
- Flair: Soda-Butler
Postby LunarCatUSA » Mon May 30, 2022 12:26 pm
Okay so good news!
I used:
Code: Select all function onDraw()
-- Player Stunned --
if ouch == true then
player:setCurrentSpriteIndex(0,0,false)
end
Thing is, this is working for the character when they face the right. I just need to make it the sprite for when they face the left. At least the sprite is now loading, so that's good.
Added in 24 minutes 2 seconds:
Okay so I made it like...
Code: Select all function onDraw()
-- Player Injured --
if ouch == true and player.direction == 1 then
player:setCurrentSpriteIndex(0,0,false)
end
if ouch == true and player.direction == -1 then
player:setCurrentSpriteIndex(0,1,false)
end
The problem is that the left sprite doesn't spawn and instead the player model disappears/blinks out of existence before going back to normal. The sprite can load no problem so am I calling the left direction incorrectly?
|
|
|
|
|
|
|
|
|
-
Hoeloe
- Foo
- Posts: 1463
- Joined: Sat Oct 03, 2015 6:18 pm
- Flair: The Codehaus Girl
- Pronouns: she/her
Postby Hoeloe » Tue May 31, 2022 1:40 pm
Why are you not doing what you've been told to? Just set player.frame, no need to mess with setCurrentSpriteIndex.
|
|
|
|
|
|
|
|
|
-
krakin
- Birdo
- Posts: 2890
- Joined: Sun Dec 11, 2016 8:02 pm
- Flair: i wish squids and octos were real
- Pronouns: he/him
-
Contact:
Postby krakin » Tue May 31, 2022 5:02 pm
Hoeloe wrote: ↑Tue May 31, 2022 1:40 pm
Why are you not doing what you've been told to? Just set player.frame, no need to mess with setCurrentSpriteIndex.
Maybe because not everyone is a LunaLua genius?
|
|
|
|
|
|
|
|
|
-
deice
- Volcano Lotus
- Posts: 543
- Joined: Fri Jul 23, 2021 7:35 am
Postby deice » Tue May 31, 2022 6:33 pm
krakin wrote: ↑Tue May 31, 2022 5:02 pm
Maybe because not everyone is a LunaLua genius?
they're not even being asked to intuit anything? they've clearly been told to use the frame field but instead opted for a different method without articulating why they chose not to use what they've already been explained. hoeloe's question seems fairly genuine, and i'm not sure how you could interpret it as condescending.
|
|
|
|
|
|
|
|
|
-
LunarCatUSA
- Hoopster
- Posts: 115
- Joined: Sat Mar 06, 2021 9:56 am
- Flair: Soda-Butler
Postby LunarCatUSA » Tue May 31, 2022 7:06 pm
Hoeloe wrote: ↑Tue May 31, 2022 1:40 pm
Why are you not doing what you've been told to? Just set player.frame, no need to mess with setCurrentSpriteIndex.
Because it hasn't been working for me. That's why I needed to use setCurrentSpriteIndex instead.
|
|
|
|
|
|
|
|
|
-
Hoeloe
- Foo
- Posts: 1463
- Joined: Sat Oct 03, 2015 6:18 pm
- Flair: The Codehaus Girl
- Pronouns: she/her
Postby Hoeloe » Wed Jun 01, 2022 12:02 pm
LunarCatUSA wrote: ↑Tue May 31, 2022 7:06 pm
Hoeloe wrote: ↑Tue May 31, 2022 1:40 pm
Why are you not doing what you've been told to? Just set player.frame, no need to mess with setCurrentSpriteIndex.
Because it hasn't been working for me. That's why I needed to use setCurrentSpriteIndex instead.
That means you were doing something else wrong. Setting player.frame is effective.
|
|
|
|
|
|
|
|
|
-
LunarCatUSA
- Hoopster
- Posts: 115
- Joined: Sat Mar 06, 2021 9:56 am
- Flair: Soda-Butler
Postby LunarCatUSA » Thu Jun 02, 2022 11:22 am
Great news everyone!
I figured out the player.frame thing. Turns out, the model was just in the incorrect direction on the spritesheet.
So now, it's all working. Thanks again.
|
|
|
|
|
|
|
|
|
-
LunarCatUSA
- Hoopster
- Posts: 115
- Joined: Sat Mar 06, 2021 9:56 am
- Flair: Soda-Butler
Postby LunarCatUSA » Sun Jun 05, 2022 10:09 pm
If it's not too much trouble, how would I go about making an NPC fly around in a circle clockwise? Do I need to do something like:
Code: Select all v.speedX = math.sin(2*math.pi)
v.speedY = math.sin(2*math.pi)
|
|
|
|
|
|
|
|
|
-
Emral
- Cute Yoshi Egg
- Posts: 9718
- Joined: Mon Jan 20, 2014 12:58 pm
- Flair: Phoenix
Postby Emral » Mon Jun 06, 2022 6:21 am
LunarCatUSA wrote: ↑Sun Jun 05, 2022 10:09 pm
If it's not too much trouble, how would I go about making an NPC fly around in a circle clockwise? Do I need to do something like:
Code: Select all v.speedX = math.sin(2*math.pi)
v.speedY = math.sin(2*math.pi)
Remember that a sine is something that expresses a motion over time, so you need some form of time variable in the equation. You might also want to modulate the motion with a frequency (speed of going along the circle) and amplitude (radius of the circle).
Code: Select all v.speedX = math.sin(lunatime.time() * frequency) * amplitude
v.speedY = math.cos(lunatime.time() * frequency) * amplitude
The above solution has the potential to drift, because of rounding issues. So what I tend to do is treat the sine/cosine as positions on the circle the NPC should move along, rather than the speed necessary follow it:
Code: Select all local oldX = v.x - v.spawnX
local oldY = v.y - v.spawnY
local newX = math.sin(lunatime.time() * frequency) * amplitude
local newY = math.cos(lunatime.time() * frequency) * amplitude
v.speedX = newX - oldX
v.speedY = newY - oldY
v.spawnX and v.spawnY are the spawn coordinates of the NPC, but those are also just numbers and can be swapped out with an origin point of your own definition.
|
|
|
|
|
|
|
|
|
-
LunarCatUSA
- Hoopster
- Posts: 115
- Joined: Sat Mar 06, 2021 9:56 am
- Flair: Soda-Butler
Postby LunarCatUSA » Mon Jun 06, 2022 12:43 pm
Okay, thanks.
Also, is there any way I can prevent my NPC from facing the other direction when going upwards?
Like, say I wanted to have it face only the left side of the screen while it's going in circles. (It has 8 frames, 4 frames for one side, 4 for the other with a framestyle = 1)
Added in 11 hours 53 minutes 1 second:
Say I wanted an NPC to remain in its first frame or a 'Dormant' frame until the player comes within a certain x-axis proximity to them. Then its full animation plays and at the end of the animation, it transforms into a hostile, moving enemy. I know how to use the v:transform(someNpc) function, I just want to know how I can keep it in the first frame until the player gets close enough to it.
|
|
|
|
|
|
|
|
|
-
LunarCatUSA
- Hoopster
- Posts: 115
- Joined: Sat Mar 06, 2021 9:56 am
- Flair: Soda-Butler
Postby LunarCatUSA » Tue Jun 07, 2022 3:07 pm
Instead of making a dormant npc frame, I wonder, is it possible to make an effect for an NPC? Make the npc a single framed one and then give it an effect gif before transforming it into another npc?
|
|
|
|
|
|
|
|
|
-
deice
- Volcano Lotus
- Posts: 543
- Joined: Fri Jul 23, 2021 7:35 am
Postby deice » Tue Jun 07, 2022 3:50 pm
LunarCatUSA wrote: ↑Tue Jun 07, 2022 3:07 pm
Instead of making a dormant npc frame, I wonder, is it possible to make an effect for an NPC? Make the npc a single framed one and then give it an effect gif before transforming it into another npc?
you could render the npc invisible for a fixed period of time, spawn the effect at it's location, then transform it. your other idea could also work, you just have to set the npc's "animationFrame" field to whichever frame you want it to be stuck on (zero-based, so the frame at the very top of the sprite is animation frame 0, the one below is 1, etc.).
|
|
|
|
|
|
|
|
|
-
LunarCatUSA
- Hoopster
- Posts: 115
- Joined: Sat Mar 06, 2021 9:56 am
- Flair: Soda-Butler
Postby LunarCatUSA » Tue Jun 07, 2022 7:25 pm
Alright well I made an effect.png and an effect.txt file with the latter having all correct gfxwidth, gfxheight, frames, and framespeed. Is there anything else I need for when I use the Effect.spawn(946,xpos,ypos)?
Added in 2 hours 25 minutes 41 seconds:
deice wrote: ↑Tue Jun 07, 2022 3:50 pm
LunarCatUSA wrote: ↑Tue Jun 07, 2022 3:07 pm
Instead of making a dormant npc frame, I wonder, is it possible to make an effect for an NPC? Make the npc a single framed one and then give it an effect gif before transforming it into another npc?
you could render the npc invisible for a fixed period of time, spawn the effect at it's location, then transform it. your other idea could also work, you just have to set the npc's "animationFrame" field to whichever frame you want it to be stuck on (zero-based, so the frame at the very top of the sprite is animation frame 0, the one below is 1, etc.).
Alright, so it would be like:
Code: Select all
proximity = math.abs(v.x - player.x)
if proximity >= 220 then
v.animationFrame = 0
end
if v.animationFrame == 3 then
v:transform(162,true,true)
end
All under onDraw()? But when I try it, the NPC doesn't advance past the 2nd frame. I wonder if it has anything to do with FrameSpeed or FrameDelay.
Added in 22 minutes 55 seconds:
Hmmm... It seems I somehow got the animation frames to go in reverse. Weird.
Added in 12 minutes 17 seconds:
Okay, it's working now. I just had to change the framestyle. Thanks again!
|
|
|
|
|
|
|
|
|
-
LunarCatUSA
- Hoopster
- Posts: 115
- Joined: Sat Mar 06, 2021 9:56 am
- Flair: Soda-Butler
Postby LunarCatUSA » Mon Jun 20, 2022 12:14 am
So, the Wohlsoft page has a deprecated page for the Multipoint function because its an earlier build. That being said, does anyone know how I would go about adding two checkpoints to my level without the player having to physically run into the CP flag npc?
|
|
|
|
|
|
|
|
|
-
Hoeloe
- Foo
- Posts: 1463
- Joined: Sat Oct 03, 2015 6:18 pm
- Flair: The Codehaus Girl
- Pronouns: she/her
Postby Hoeloe » Mon Jun 20, 2022 11:01 am
LunarCatUSA wrote: ↑Mon Jun 20, 2022 12:14 am
So, the Wohlsoft page has a deprecated page for the Multipoint function because its an earlier build. That being said, does anyone know how I would go about adding two checkpoints to my level without the player having to physically run into the CP flag npc?
Multipoints are deprecated because that's the old library from back when SMBX only supported one checkpoint in a level.
These days, both checkpoint NPCs can be used multiple times with no issues, and checkpoints can be created from Lua directly using the Checkpoint class.
|
|
|
|
|
|
|
|
|
-
LunarCatUSA
- Hoopster
- Posts: 115
- Joined: Sat Mar 06, 2021 9:56 am
- Flair: Soda-Butler
Postby LunarCatUSA » Mon Jun 20, 2022 1:00 pm
So something like...
Code: Select all local checkpoints = API.load("checkpoints");
if event == true then
checkpoints.addLuaCheckpoint(ThisX, ThisY, ThatSection);
end
|
|
|
|
|
|
|
|
|
-
Hoeloe
- Foo
- Posts: 1463
- Joined: Sat Oct 03, 2015 6:18 pm
- Flair: The Codehaus Girl
- Pronouns: she/her
Postby Hoeloe » Mon Jun 20, 2022 4:27 pm
No. Look at the documentation, it's just this:
Code: Select all local myCheckpoint = Checkpoint{x=ThisX, y=ThisY, section=ThatSection}
Then, when you want to collect the checkpoint you can just do:
|
|
|
|
|
|
|
|
|
-
Emral
- Cute Yoshi Egg
- Posts: 9718
- Joined: Mon Jan 20, 2014 12:58 pm
- Flair: Phoenix
Postby Emral » Mon Jun 20, 2022 4:29 pm
Hoeloe wrote: ↑Mon Jun 20, 2022 4:27 pm
No. Look at the documentation, it's just this:
Code: Select all local myCheckpoint = Checkpoint{x=ThisX, y=ThisY, section=ThatSection}
Then, when you want to collect the checkpoint you can just do:
To BE fair you made the docs today and didn't link them.
|
|
|
|
|
Return to “LunaLua Help”
Users browsing this forum: No registered users and 2 guests
|