Drawing to the screen - and making it stick

sharpleaf

  • Posts: 90
I asked this question in the Stencyl IRC and the replies were all very interesting. There were multiple concepts into how to get this done, yet I couldn't get it to happen. Here's the idea: I want to make a simple drawing "game". Since I'm brand new to Stencyl (and everything really) I wanted to make my first goal to be able to click the mouse and have a pixel appear where I clicked and have it STAY (that's been the kicker).
So, mouse click = permanent pixel placement, using only blocks in Design Mode.
I say using only blocks because I wouldn't have the foggiest on how to meddle in the AS3.
Also, if someone else new finds this thread, it would be a good learning experience if it were in all blocks.

Here was my shot. It doesn't work, but I don't know why.


Ready, go!

sharpleaf

  • Posts: 90
by the way, x and y are just number attributes (variables).

Greg

  • *
  • Posts: 1259
When you say it doesn't work, what isn't working?  Are the pixels showing up and then disappearing, or not showing up at all?

I tried recreating your behavior (something equivalent at least) and it seemed to work for me.


Alexin

  • *
  • Posts: 3127
I think he's only showing us the solution he came up with, and not actually asking for help.
"Find the fun"
alexin@stencyl.com

Greg

  • *
  • Posts: 1259
After re-reading it, you might be right.  But he did put this "Here was my shot. It doesn't work, but I don't know why.", which is why I thought he was still looking for help.  :)

sharpleaf

  • Posts: 90
Yeah I'm looking for help :)

The real fun was to see if people came up with different solutions to the same problem. I like to see that kind of stuff because it helps me learn technique (of which I have none :) ) As an example: Greg, you posted your solution with "loop counter" you basically combined my x and y variables into 1. i never would have thought of that. Same with the "increment". Totally didn't even think of using it. I was basically doing the i++; or i=i+1; thing you do in Java. You taught me something! Thank you!

When I say that my try didn't work, I mean that nothing happens at all..... I click on the screen and drag the mouse around and all I notice is a build up of lag (the mouse gets jittery) but nothing appears on the screen at all.

I'll try what you did and see if it works for me. Looking at it initially it looks like the same thing i did, but cleaner so if this does work, I'll not know why mine didn't.

sharpleaf

  • Posts: 90
yeah, your solution totally works :)

But, why didn't mine?

Now to make it a smooth line when moving the mouse around!
(any suggestions?)

//Alex

sharpleaf

  • Posts: 90
I'd also like to see if anyone else can come up with a solution.

I say this because as I played around with the one that exists so far, I ran int a fundamental problem that would render the game useless. The frame rate drops very quickly.

So far, the solution given is to add the location of every mouse click to 2 lists (and x coordinate list and y coordinate list), and then run through every entry in the lists and have it draw a pixel at the points, every frame.

This works until the list starts getting full and it has to run through more and more entries every frame. The more you click, the more lag/frame rate reduction occurs.

So would anyone out there have a better idea on how to do this?

Greg

  • *
  • Posts: 1259
The list definitely gets huge fast, making this approach unfeasible.  You're probably better of capturing points less frequently and then drawing lines between each of the points.  If the points are close enough, it might look OK.

Also, you don't want to keep adding points if the mouse isn't moving anywhere -- it doesn't do any good to have overlapping points.  So you'd want some way to make sure that you only add a point if it's far enough away from an existing point (may add overhead). 

Even with these changes, I'm not sure how well this will perform.  You'd need to cap off the maximum number of points eventually. 

sharpleaf

  • Posts: 90
Yeah, that's why I'm wondering if there is some list-less solution.
The only thing I've heard of would be to edit a raw offscreen image (like an actual .bmp file) and then have that image blasted to the screen every frame. But I don't think that can be done with blocks :)

Alexin

  • *
  • Posts: 3127
In the past, I used a Shape to draw bezier curves across mouse clicks and I could get hundreds of them with a negligible performance hit. It basically did what you want, I think.
"Find the fun"
alexin@stencyl.com

sharpleaf

  • Posts: 90
Hi Alexin!

Could you elaborate? I'd be interested to see how you did this.

Alexin

  • *
  • Posts: 3127
I'll get back to you later, with an example.
"Find the fun"
alexin@stencyl.com

Epic428

  • Posts: 1118
Out of curiosity Alexin, Did the shapes and bezier curves support collisions, etc, like any other shape and actor?  If so, then I think this may be highly beneficial to Jesse's game Quaintbrush.
James Moore - Official Support & Documentation.
We cannot and will not respond to PM's asking questions. Please make a new thread in the forums if you have any questions, Thank you.
For better support and faster response times, please post your logs regarding any Stencyl related issues. Debug > Logs > Generate Logs