Sorry your browser is not supported!

You are using an outdated browser that does not support modern web technologies, in order to use this site please update to a new browser.

Browsers supported include Chrome, FireFox, Safari, Opera, Internet Explorer 10+ or Microsoft Edge.

AppGameKit Classic Chat / Draw movement path for sprite - need feedback

Author
Message
Timshark
17
Years of Service
User Offline
Joined: 30th Jun 2007
Location: Oslo, Norway
Posted: 24th Nov 2014 23:31 Edited at: 25th Nov 2014 00:04
Hi people of agk!

I made a little program that makes a sprite move along the path you draw with your mouse.
press the mouse button and draw whatever line you want. When you release the button the sprite will follow the path you have drawn.



nothing exceptional, but maybe useful for some - BUT I need something that I don´t know enough about:

What I need is to show the line you draw on the screen and then delete it when you release the mousebutton.
What is the easiest and most efficient way to do this? With "setrendertoimage"?

I never want what I know.
easter bunny
12
Years of Service
User Offline
Joined: 20th Nov 2012
Playing: Dota 2
Posted: 25th Nov 2014 02:01 Edited at: 25th Nov 2014 02:12
Simple method usnig drawline.



Other ways could be creating a sprite at each position, storing the IDs in an array and deleting them afterwards, or trying something with memblocks (modifying the image of a sprite). Use your imagination xD

edit: SetRenderToImage would be a lot simpler than memblocks

something like this would work [psuedo code]:

although I probably wouldn't use this method, try experimenting with it and see if you can get it to work



EDIT:
Here's my complete modified version if your code (changes comented).



Audacia Games - Latest WIP - AUTOMAYTE 2.1, AppGameKit one click deploy to Android
"When you've finished 90% of your game, you only have 90% left"
Blendman
10
Years of Service
User Offline
Joined: 17th Feb 2014
Location: Arkeos
Posted: 25th Nov 2014 09:29 Edited at: 25th Nov 2014 11:48
Hi

It's fun, I have made a same code like yours to add undo/redo system to my painting application (animatoon).

Here is the base code I use for Animatoon (see on showcase forum), only the part to draw a brush on a layer :



http://www.dracaena-studio.com
Timshark
17
Years of Service
User Offline
Joined: 30th Jun 2007
Location: Oslo, Norway
Posted: 25th Nov 2014 11:03 Edited at: 25th Nov 2014 11:08
@easter bunny

Thank you. I tried your snippet but nothing happens on my screen..?? My need wasn´t clear enough. What I need is to see the line AS you draw it, not after it has been drawn. Thats also the reason for the extra syncs you commented in the code.

@ Blendman
Thanks. This is close. Although, as I understand it, setrendertoimage() only works with power of 2 images. Thats the reason for the slight offset of the sprite in your program. The image stretches to fit the 1024,768 size. If you change the image and screen resolution to 512,512 there is no offset.

Now - how to do this with a screen resolution of 1024,768.....

I never want what I know.
BatVink
Moderator
21
Years of Service
User Offline
Joined: 4th Apr 2003
Location: Gods own County, UK
Posted: 25th Nov 2014 11:22
Somewhere(!) I have a project for writing signatures on the screen, like the delivery man asks you to do when receiving a parcel. If I can find it, I will post it.

In summary, I recorded the position of the pointer every time it moved 10 pixels from the previous one. Then I drew lines from each point to the next.

Doing it this way means you can "erase" the line by removing points from the array. You can erase forwards or backwards by removing from the front or back of the array. So you could erase your line from behind as the sprite travels along it.

Quidquid latine dictum sit, altum sonatur
Blendman
10
Years of Service
User Offline
Joined: 17th Feb 2014
Location: Arkeos
Posted: 25th Nov 2014 11:52
@timshark : in the code I have posted, you have the two versions. For android, you need a power of 2 image for renderimage, and for windows, you do what you want. With a 1024*768 screen, it's :


@Batvink : in this thread, I have tried to create an eraser : http://forum.thegamecreators.com/?m=forum_view&t=212671&b=41.
SetSpriteMask() is very slow, so this example isn't great for real time.

Matty_H has posted a shader example for an eraser, but I haven't tested it yet. If I can do an example which works fine for an eraser, I will post it in the same thread.

If you find another technic (erase the image and not delete the points on the path array ^^), you can post it too .

http://www.dracaena-studio.com
Timshark
17
Years of Service
User Offline
Joined: 30th Jun 2007
Location: Oslo, Norway
Posted: 25th Nov 2014 11:58 Edited at: 25th Nov 2014 12:12
@Batvink

Sounds interesting.

@ Easter Bunny
I got your code to work now. What I had to do was to put back the first sync() you commented out. The one after:
x=getpointerX()
y=GetPointerY()



I never want what I know.
Blendman
10
Years of Service
User Offline
Joined: 17th Feb 2014
Location: Arkeos
Posted: 25th Nov 2014 12:27
You need to put back this sync() because you are inside a loop (repeat / until finished = 1)

http://www.dracaena-studio.com
Timshark
17
Years of Service
User Offline
Joined: 30th Jun 2007
Location: Oslo, Norway
Posted: 25th Nov 2014 16:39 Edited at: 25th Nov 2014 17:32
@ Blendman
Quote: " in the code I have posted, you have the two versions. For android, you need a power of 2 image for renderimage, and for windows, you do what you want. With a 1024*768 screen, it's : Rimage=CreateRenderImage(1024,768,0,0)
result = Creasprite(Rimage)"

This was in your original example. the drawn line is still offset in tthe upper and lower part of the screen.

I run this on a Mac.

Quote: "You need to put back this sync() because you are inside a loop (repeat / until finished = 1)"


Yes of course. Strange how blind one can be sometimes. It was me who put it there in the first place

Thank you all for splendid help. I now have something that works. To put this in context: I needed this for the editor of my game to draw sprite paths for later use. Speed is not a big issue in the editor so I´m happy with what I have now. But if speed was important I think Blendmans setRenderToImage() solution would be faster.(??)

Anyway, this is my final solution for now:



I never want what I know.

Login to post a reply

Server time is: 2024-11-25 11:27:51
Your offset time is: 2024-11-25 11:27:51