Make a "SpriteButton" plugin

Get help using Construct 2

Post » Fri Aug 30, 2013 1:51 am

So far I am very impressed with Construct2. I would like to make a "SpriteButton" plugin (I know some are available, but this is for learning how to make plugins)

I currently have a project that does what I want, I'm just not sure about the best way to make it a reusable component.

My "manual method"

Create a Sprite, set up image to have 3 frames (normal, hover, pressed) and define those frames in the sprite animation window.

defined the following events:
mouse: Cursor is over (sprite) --> (sprite) set animation frame to 1
mouse: Cursor is not over (sprite) --> (sprite) set animation frame to 0
touch: isTouching (sprite) --> set animation frame to 2 (& my game-specific actions)

with touch enabling mouse input, this works for what I want. So, on to the detailed questions:

If I want to make this a reusable component, would it be better to make it a behavior that is attached to a sprite, or a new object type?

With the expectation that every "SpriteButton" would have the same frames defined in the same order in the source image, the goal is to have the plugin automatically set the right frame without any further action from the user other than selecting the source image. Then, it would define its own event(s), such as SpriteButton:IsPressed to do the game logic. Is this the right way to design this? I am happy to look at the existing behaviors/plugins to do the low-level coding (I am reasonably adept at JS) but would like to ensure that I'm starting out on the right foot.
B
6
S
1
Posts: 22
Reputation: 446

Post » Fri Aug 30, 2013 2:27 am

The events are fairly easy to set up, but on the other hand you get the experience.

For that alone I'd say go for it.
Image ImageImage
B
172
S
50
G
184
Posts: 8,444
Reputation: 116,107

Post » Fri Aug 30, 2013 8:49 pm

If we end up using Constuct2 for this project, it will be a team of artists (non-programmers) and programmers (like me) -- so, my main job will most likely be to make plugins like this so that the artists don't have to do any scripting. The quicker I can get up to speed, the better.
B
6
S
1
Posts: 22
Reputation: 446

Post » Fri Aug 30, 2013 10:15 pm

I'm making some progress on this, and I've hit a problem. I figure I'd toss it out here in case someone knows the answer before I stumble upon it. I notice that the button plugin has code to register an onClick handler for the html button and hook into that to fire the OnClicked condition. Can I do this if my SpriteButton is a behavior attached to a Sprite object? I'm not seeing an obvious way to do it.

I will continue to search through the forums and docs, but in case it's an easy answer that I'm just missing, thought I'd toss it out here.
B
6
S
1
Posts: 22
Reputation: 446

Post » Sat Aug 31, 2013 1:26 am

Okay, I've gotten most of the things figured out and don't need any immediate help. Forum posts and looking at the dragndrop behavior seemed to have most of the answers I need.
B
6
S
1
Posts: 22
Reputation: 446

Post » Fri Sep 06, 2013 9:23 pm

I have my current version at https://www.dropbox.com/s/x46uie9isi0cvn3/SpriteButton.c2addon

and a topic over in the "share your plugins" section, so this topic is closed.
B
6
S
1
Posts: 22
Reputation: 446


Return to How do I....?

Who is online

Users browsing this forum: BiffanyPFH, dop2000, Klarner and 22 guests