Page 1 of 1

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

Posted: Wed Oct 16, 2019 4:14 pm
by Chilly14
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

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

Posted: Wed Oct 16, 2019 4:23 pm
by Enjl
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).

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

Posted: Wed Oct 16, 2019 6:54 pm
by Chilly14
Okay, I changed the code; for some reason, it's still not working.
Code now: https://hastebin.com/quzokirobi.cpp

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

Posted: Thu Oct 17, 2019 12:45 am
by Enjl
The draw event needs to be registered in order to run.

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

Posted: Thu Oct 17, 2019 12:41 pm
by Chilly14
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.

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

Posted: Thu Oct 17, 2019 12:45 pm
by Enjl
I see the line is commented out in your onInitAPI, meaning it won't run.

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

Posted: Thu Oct 17, 2019 3:40 pm
by Chilly14
Thank you! It's finally working! :D