Click and drag paint - only want it to apply once

For questions about using Classic.

Post » Wed Nov 18, 2009 8:19 pm

Ok, here's my situation: I am making a top-down, grid-based sand castle game. The game terrain is comprised of a few hundred "sandTerrain" objects, each one of which is a tile on the grid. Each tile has a "height" value of 1 to 4, which is represented by the coloration of the tile.

I'm giving players the ability to either add height to the sand, or lower the height. They can hold down and drag the mouse button across the terrain to edit a line of sand. I am running into two problems with this:

1. If the player moves the mouse really fast, some squares on the grid are skipped, and instead of a full line of edited squares I have a dotted line. Which makes sense; the mouse is moving faster than the code is checking. I suspect that I'll need to learn about fast loops and use those to do this, but any other thoughts or techniques would be very appreciated.

2. Second, if the player is moving the mouse anywhere below max speed, the mouse hovers over an individual square long enough for the code to check at least twice, usually three or four times. This means that a piece of terrain at height 4 can be lowered down to height 1 faster than the eye can follow. Ideally, each single piece of terrain can only be raised or lowered once per mouse click. In order to make another change, the player would need to let go of the button they're holding, and then click again.

I am unsure of a good way to fix the second problem, so any advice would definitely be appreciated.


You can download a stripped-down version of my .cap file here:
http://www.mediafire.com/?yv3rhozqzrw

I am using Construct version 0.99.42
B
1
G
3
Posts: 4
Reputation: 833

Post » Wed Nov 18, 2009 9:53 pm

You can't rely on mouse. Instead, record mouse coordinates each frame and "draw" a line to the previous mouse location and so on. Mark the points the line overlaps.

Too tired to give more concrete example, I'm sure someone can give you a simpler solution.
B
62
S
21
G
12
Posts: 1,910
Reputation: 13,155

Post » Sun Nov 22, 2009 12:25 am

yeah it's not that the code is not going fast enough. Computer mice only output discrete variations. It's up to the software to interpret that as needed.
B
3
S
2
G
4
Posts: 1,445
Reputation: 4,665

Post » Mon Nov 23, 2009 2:31 pm

Once an object has been clicked once set a private variable to 1 and add a condition to check the variable in the raise and lower code. then make a new event for on mouse released terrain object set variable to 0 that should take care of the once per mouse click problem.
B
5
S
2
G
4
Posts: 632
Reputation: 2,829


Return to Help & Support using Construct Classic

Who is online

Users browsing this forum: No registered users and 6 guests