How do I make a NPC's graphic rotate automatically?

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

Moderator: Userbase Moderators

Chilly14
Snifit
Snifit
Posts: 236
Joined: Thu Jul 18, 2019 10:28 pm
Flair: wash your hands and stay at home
Pronouns: he/him

How do I make a NPC's graphic rotate automatically?

Postby Chilly14 » Wed Oct 16, 2019 4:14 pm

Y'know Enji's Plonker NPC? Well, I'm trying to get a NPC's graphic to rotate automatically with code copied from the Plonker NPC. But either nothing happens or generates an error. Can you show me how?
Current code: https://hastebin.com/degatarimu.cpp

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

Re: How do I make a NPC's graphic rotate automatically?

Postby Emral » Wed Oct 16, 2019 4:23 pm

You removed pretty much the entire draw function. That's why it doesn't work.
Plonker code for reference:
https://hastebin.com/zufitoziro.rb
Draw function: 183-237

Of note: I'm the weird person who's too used to Graphics.glDraw's family of functions to switch to using the Sprite class, because I find it easier to work with. Your mileage will almost certainly vary. The piece of code you didn't remove (the for loop) rotates four vectors (vt) defining the top left, top right, bottom right, bottom left corner of the drawn area (relative to 0,0) by the NPC's angle. The rotated result is (ought to be) later used for the vertices of the draw call (offset by the npc's pivot, so that it draws relative to the NPC, not 0,0).

Chilly14
Snifit
Snifit
Posts: 236
Joined: Thu Jul 18, 2019 10:28 pm
Flair: wash your hands and stay at home
Pronouns: he/him

Re: How do I make a NPC's graphic rotate automatically?

Postby Chilly14 » Wed Oct 16, 2019 6:54 pm

Okay, I changed the code; for some reason, it's still not working.
Code now: https://hastebin.com/quzokirobi.cpp

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

Re: How do I make a NPC's graphic rotate automatically?

Postby Emral » Thu Oct 17, 2019 12:45 am

The draw event needs to be registered in order to run.

Chilly14
Snifit
Snifit
Posts: 236
Joined: Thu Jul 18, 2019 10:28 pm
Flair: wash your hands and stay at home
Pronouns: he/him

Re: How do I make a NPC's graphic rotate automatically?

Postby Chilly14 » Thu Oct 17, 2019 12:41 pm

Enjl wrote:
Thu Oct 17, 2019 12:45 am
The draw event needs to be registered in order to run.
But I thought I did it already.

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

Re: How do I make a NPC's graphic rotate automatically?

Postby Emral » Thu Oct 17, 2019 12:45 pm

I see the line is commented out in your onInitAPI, meaning it won't run.

Chilly14
Snifit
Snifit
Posts: 236
Joined: Thu Jul 18, 2019 10:28 pm
Flair: wash your hands and stay at home
Pronouns: he/him

Re: How do I make a NPC's graphic rotate automatically?

Postby Chilly14 » Thu Oct 17, 2019 3:40 pm

Thank you! It's finally working! :D


Return to “LunaLua Help”

Who is online

Users browsing this forum: No registered users and 27 guests

SMWCentralTalkhausMario Fan Games GalaxyKafukaMarioWikiSMBXEquipoEstelari