'Slider Control' kind of controls in Cocos2d help - user-controls

I am making a game in Cocos2d. I want there to be a dotted line that follows the user's finger. I want the line to be straight. The problem is, how do I check to see how many 'dots' will fit in the distance between the ball and where the user is touching? And make it follow in a STRAIGHT line between the ball's position and the finger's position? So here's a re-clarification:
The ball sits still on the left side of the screen, and is halfway up the screen. The user drags their finger, and a dotted line is drawn between the ball's position and the touch's position. I have a 'dot' image to be used, and I would like it to be used as the dots in the line. So it will have to recreate the sprite as many times as it will fit in the area between the two points. Please tell me if you want me to clarify further, Thanks!!

I would make a CCNode object called dottedLine or something.
The dot image would be a sprite that gets added as a child of the node (multiple times).
I would work out the path from ball to finger touch using Trigonometry/Pythagoras theorem.
For creating the line:
From point 0, the ball, i would add 15-20 pixels towards the touch point along the path, and place a dot, I'd repeat this until I reached the end of the line.
Every dot that was placed I would increment a counter, and set that number as the integer tag of that sprite for use in an update method.
Every time the cctouchesmoved method gets called, i'd call an update method on the dottedLine object.
This method would check the distance between the ball and touch point, divide it by the number of dots currently children of the object and remove or add any that are needed. Recreating the sprites every time you move your finger would be messy and wasteful, so reusing your dots and just setting them new positions as the path between ball and touch point changes would probably be best.
I'm not going to provide you code, i think i've explained more than enough of the working out for you to do some googling and work this out.

Related

Add double lines in the middle of another svg line

so I have a drawing program and I need to implement a "broken line", it is an SVG line with two another lines in the middle of this line, these two line needs to cross perpendicularly to the principal line, maybe this picture can help me to explain the problem:
This line can be drawn in any angle that the user choose
I don't really understand svg's so I'm having a lot of trouble implementing this.
Thank you
So I discovered one way to implement that using polylines and calculating the middle of the source and target coordinates, so when it changes I change the middle point too. After that, I created a marker-mid with the double lines.

How to move marker with animation along routing path?

I want to move marker along curved path.I do receive LatLong every minute.
for example A, B are received LatLong locations. I need right way to make it happen.
I could move using leaflet.animateMarker
but it moves from A point to B which is bad when the path is curved.
curved path. Please advise if you have any idea about how to move the marker along curved path? thanks in advance!
You can use lib from GitHub This. It is very commonly used to animate markers on Leaflet map. Hope this will cover your needs.
Features
Let move your markers along a polyline.
You can zoom in/out, your moving marker will be at the right place !
You can pause or end the animation whenever you want.
You can deal with events.
You can make loop.
You can add the the point one by one.
You can add station at some points of the polyline.

How to drag a polygon in MFC?

I'm new to MFC. I know how to draw a line and how to scribble in MFC. I use CDC and some functions such as LineTo() and MoveTo() to do this. Moreover, I've got FillRect() and Rectangle().Now I want to drag my rectangle or any polygon in the view.It's like you drag a icon on your desktop.
I think the first step is to get the region.Then erase the old polygon and when the mouse move draw a same polygon which depends on the point where the mouse go.
So I search region in MSDN and I got Region class and CRgn class.But before I look into these two class I want to know whether I'm in the right direction.
I need more suggestions on how to learn MFC. Actually,all I need is to finish my homework which is mainly about draw polygons and drag them and link them by line. And I hope I can finish this homework all by myself and MSDN. Can MSDN help me do that?
The CDC::Polyline function will draw a polygon much faster than using LineTo and MoveTo.
You do not need region and do not need to erase the old polygon. Instead, you need to draw everything in the view OnDraw. Any change you want to make with the mouse should change the array of coordinates that represent the polygon and then call Invalidate. In other words, do not draw in the mouse message handlers. Calling Invalidate in the mouse message handlers will cause OnDraw to be called later and it should repaint the entire view.

How can I draw to an XY position in Emacs?

I wanted to allow the Emacs cursor to move around freely outside of actual text (similar to virtualedit=all in Vim).
"Oh," I thought, "I'll just keep track of a virtual cursor and draw it to the screen myself."
But it turns out the actual native C drawing routines (such as draw_glyphs) seem to refer back to the buffer contents to decide what to draw (I could be wrong though).
My next idea was to make a giant overlay of all spaces so I'd have complete freedom where to put stuff. But an overlay only goes over ranges of actual text, so again, this does not seem to give me what I'm looking for.
Is this a reasonable goal without hacking the C code?
I believe the writeable area of a window is intrinsically limited to the buffer with which it is associated, i.e. you have to draw in an area where buffer content exists.
(One example of this limitation is the impossibility of drawing a vertical guide line in the 80th column to help the user identify long lines; currently the best possible implementation of such a feature is to highlight the "overflow" of each too-long line.)
You can do the same as what artist-mode does without adding spaces to the buffer:
when trying to place the cursor after the end of the line, just use an overlay with an after-string property which adds the spaces in the display without modifying the buffer.
Have a look at "artist-mode" (M-xartist-modeRET) - it allows you to draw in Emacs.
From the function documentation: "Artist lets you draw lines, squares, rectangles and poly-lines, ellipses and circles with your mouse and/or keyboard."
You can look at popup.el from the auto-complete package, which can pop up tooltips and menus and such at any position, including positions outside the contents of the buffer. Maybe that will show you how you can do it.

How do I implement a group of strings that starts randomly, but is bound by relevance upon selection?

Okay the title may be a little confusing, but here's what I'm trying to do :) I have a game in XNA where every tap from the user draws a moving circle on the screen. The circle has a tag, say 'dogs' displayed on it. So imagine multiple taps on the screen, and we have all these circles of various colors and sizes moving around the screen with different (but constant) velocities. Each circle with different tags: 'dogs', 'cats' and so on...
Clicking on empty space generates a new circle at that point. Clicking on one of the circles "selects" it, turning it into a greeen shade and slowing its velocity down to a fraction of what it was. Clicking on it again "unselects" it, and restores its original color and velocity (trajectory does not change).
With each circle comes a tag, and as of now I'm populating these tags randomly from a string array (which means there's a chance tags will repeat). I would like the tags for newly created circles to be relevant to previous "selected" tags. So when I click on 'dogs', I would like 'German Shepherd' but I would also like 'dog parks' and 'lemurs' assuming dogs get along well with lemurs.
What would be the best way to approach this problem. In my head I have a massive many-to-many mapping, but I can't seem to translate it to code. Thanks for looking.
FYI I'm using the sample project from here:
http://mobile.tutsplus.com/tutorials/windows/introduction-to-xna-on-windows-phone-7/
At a glance your data structure sounds like a tree, except each node has a list of parents instead of a single parent. You could describe it as many to many like you said, but there's likely more links in the child direction than the parent direction.
Alternatively you could leave it as a tree structure and add a list of associations to nodes, so that like you say lemurs and dogs can be associated, even though they are not in a parent / child relationship.

Resources