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 / SetScissors with a rotated Rectangle?

Author
Message
ManOfActionTM
12
Years of Service
User Offline
Joined: 16th May 2011
Location: Sahuarita, Arizona
Posted: 2nd Apr 2014 01:40
I'm trying to split a sprite along a line, any ideas on how to do that?

I've got a couple, but they are fairly complex, and are currently destroying my mind! Hoping someone has an easier way!
Marl
12
Years of Service
User Offline
Joined: 19th Nov 2011
Location: Bradford, UK
Posted: 2nd Apr 2014 02:43 Edited at: 2nd Apr 2014 02:48
You probably need to be a bit more specific on what you want, or you might just get some random code;

Splits a sprite along a line, uses setscissor, rotates a rectangle and everything. What more is there?

Attachments

Login to view attachments
ManOfActionTM
12
Years of Service
User Offline
Joined: 16th May 2011
Location: Sahuarita, Arizona
Posted: 2nd Apr 2014 02:53
Okay I'm trying to split a sprite into two sprites given a line.

My thoughts go something like this:

1. Clone the Sprite
2. Somehow do a SetSpriteScissor on both the clone and original sprite
3. Set Center of Mass and Offset to something that would ignore the invisible part of the sprite

Unfortunately, with SetSpriteScissor requiring a box, not a line, I'm struggling a bit
Marl
12
Years of Service
User Offline
Joined: 19th Nov 2011
Location: Bradford, UK
Posted: 2nd Apr 2014 03:16 Edited at: 2nd Apr 2014 03:17
It really depends on why you want to do the split and if you want to rotate the parts independently after they are split.

Using setscissor, you might not have to clone the sprite, just re-use it in a different place or with different characteristics.


Again, pretty much guess work without more of an example to work to.

Attachments

Login to view attachments
ManOfActionTM
12
Years of Service
User Offline
Joined: 16th May 2011
Location: Sahuarita, Arizona
Posted: 2nd Apr 2014 03:19
Yeah, I'm going to want to have the sprites rotate and move independently after the split.

btw, thanks for your help so far!
Phaelax
DBPro Master
20
Years of Service
User Offline
Joined: 16th Apr 2003
Location: Metropia
Posted: 2nd Apr 2014 03:23
You can do this with memblocks.

ManOfActionTM
12
Years of Service
User Offline
Joined: 16th May 2011
Location: Sahuarita, Arizona
Posted: 2nd Apr 2014 03:26
I'm intrigued...do you have an example (even in pseudocode)?
Marl
12
Years of Service
User Offline
Joined: 19th Nov 2011
Location: Bradford, UK
Posted: 2nd Apr 2014 03:28 Edited at: 2nd Apr 2014 03:36
Rotation is going to be the limiting factor.

Since the scissoring operation works on rectangles, you can only have horizontal and vertical splits across sprites. Rotate by any angle other than 90 degrees and it's going to get messy.

Again, it's back to the why - which will dictate how much stress you are prepared to go through to get it working as you want.

I suspect for all but the simplest tasks, you're going to need to lay down the sprite and pick it back up in pieces using getImage().

Edit:
Quote: "You can do this with memblocks."

Why did I just flash back to "you can do that with the poke command"
ManOfActionTM
12
Years of Service
User Offline
Joined: 16th May 2011
Location: Sahuarita, Arizona
Posted: 2nd Apr 2014 03:46
I would like to have a somewhat realistic slice along the sprite where the user has just swiped. Think of real scissors cutting up the sprite.

My long (and not sure if it's going to work) solution is:


So I've done a bit, but it's a lot of work for something I'm not sure it's going to work, which is why I was wondering if someone had a better way that definitely worked.
Marl
12
Years of Service
User Offline
Joined: 19th Nov 2011
Location: Bradford, UK
Posted: 2nd Apr 2014 16:49 Edited at: 2nd Apr 2014 16:57
I don't think it can be done that way, setscissor is used to cut a sprite for display, the "cut" sprites can't be manipulated unless drawn and re-grabbed as new images - in which case rectangles again apply.

Something like ;

1) Work our where the swipe crossed the sprite
2) Find the middle of this line
3) Set Sprite Offset to be at that position
4) Work out angle of swipe
5) rotate sprite by minus that angle so the split is horizontal
6) Grab the top of the sprite as new image
7) Grab the bottom of the sprite as new image
8) Hide original sprite
9) Create new sprites from top and bottom images
10) Set offsets for both sprites to be position of join
11) rotate new sprites by the angle of the swipe and position.
12) Move new sprites away from each other

Grabbing images is slow and not something you would want to do a lot of, but as this is in response to a user action, you could probably get away with it.

Attachments

Login to view attachments
ManOfActionTM
12
Years of Service
User Offline
Joined: 16th May 2011
Location: Sahuarita, Arizona
Posted: 2nd Apr 2014 19:46
Very cool! Thank you so much!!!
Ancient Lady
Valued Member
20
Years of Service
User Offline
Joined: 17th Mar 2004
Location: Anchorage, Alaska, USA
Posted: 3rd Apr 2014 06:04
Yes, thank you. Good stuff to work with.

Cheers,
Ancient Lady
AGK Community Tester and AppGameKit Master
BatVink
Moderator
20
Years of Service
User Offline
Joined: 4th Apr 2003
Location: Gods own County, UK
Posted: 7th Apr 2014 15:51
If this is a Fruit Ninja type game, you might want to consider "pre-cut" versions of your images. You can then select the closest match after the swipe. If somebody is swiping rapidly they won't be analysing just how accurate the cut was.

ManOfActionTM
12
Years of Service
User Offline
Joined: 16th May 2011
Location: Sahuarita, Arizona
Posted: 7th Apr 2014 16:41
Yeah, that's what we ended up doing. I'm not sure what we were doing incorrectly from the instructions from Marl, but it wasn't coming out right. So we switched to what you suggested, BatVink, and it's looking great!

(still looking for my badges--where are they?!?!
ManOfActionTM
12
Years of Service
User Offline
Joined: 16th May 2011
Location: Sahuarita, Arizona
Posted: 7th Apr 2014 16:42
nevermind! I happened to see the edit under my user name! Yay! Badges!
Impetus73
12
Years of Service
User Offline
Joined: 28th Aug 2011
Location: Volda, Norway
Posted: 11th Apr 2014 13:26
Marl, we think alike, I was thinking the exact same solution, you provided

----------------
AGK programmer
Did Amiga / AMOS programming in the 90's.

Login to post a reply

Server time is: 2024-03-29 15:14:11
Your offset time is: 2024-03-29 15:14:11