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 / [SOLVED] DrawBox and Sprites

Author
Message
MateiSoft
12
Years of Service
User Offline
Joined: 22nd Oct 2012
Location:
Posted: 4th Jul 2018 12:33
Hello Community,

I created a box using drawbox command and I want to transform it into an image and into a sprite, then. Anyone know any command that I can retrieve some parameters from the box I made? Thank you!

www.alexmatei.com

The author of this post has marked a post as an answer.

Go to answer

puzzler2018
User Banned
Posted: 4th Jul 2018 12:53
I normally use

swap()
drawbox( x1, y1, x2, y2 ....................)
render()
BoxSprite = createsprite ( getimage( x1, y1, x2, y2 ))

But this will work on preprocessing (before you head into the main loop )

Im not sure how effective it will be if its running in the main loop, cause will need

swap() and render() for it to grab the image and using those commands will make your screen go blank for a split second.

Others may have some other insirational ideas im sure.

MateiSoft
12
Years of Service
User Offline
Joined: 22nd Oct 2012
Location:
Posted: 4th Jul 2018 13:03
I think if I use in an instance like when not clicking the middle mouse and iterate it once, it should work.
www.alexmatei.com
Phaelax
DBPro Master
21
Years of Service
User Offline
Joined: 16th Apr 2003
Location: Metropia
Posted: 4th Jul 2018 13:27
If you're just drawing a box, there's really no need grabbing the image then a sprite, you can just make a sprite and use 0 for the image number. This will make a blank sprite which you can size and color however you want.

Tiled TMX Importer V.2
XML Parser V.2
Base64 Encoder/Decoder
Purple Token - Free online hi-score database
Legend of Zelda

"I like offending people, because I think people who get offended should be offended." - Linus Torvalds
MateiSoft
12
Years of Service
User Offline
Joined: 22nd Oct 2012
Location:
Posted: 4th Jul 2018 13:34 Edited at: 4th Jul 2018 13:34
Hi Phaelax,

Think about the fact that I create a rubber selector for some sprites in a scene. I tried resizing a sprite by "getrawmousex()" and "getrawmousey()" coordinates, but it returns the wrong size. I have "drawbox" rubber band and I want the sprite create afterwards to have the same size as the "drawbox"
www.alexmatei.com
Phaelax
DBPro Master
21
Years of Service
User Offline
Joined: 16th Apr 2003
Location: Metropia
Posted: 4th Jul 2018 13:37
I'm not following. You can resize the sprite box anytime to any size. Are you drawing a solid box or just the outline?
Tiled TMX Importer V.2
XML Parser V.2
Base64 Encoder/Decoder
Purple Token - Free online hi-score database
Legend of Zelda

"I like offending people, because I think people who get offended should be offended." - Linus Torvalds
MateiSoft
12
Years of Service
User Offline
Joined: 22nd Oct 2012
Location:
Posted: 4th Jul 2018 13:46
just the outline.

Let me put this scenario: Middle Click -> DrawBox(not filled, so just the outline) -> Drawbox, follows the cursor while we still have middle click state 1 -> Let go of Middle Click, create a sprite and resize it same as the previous box (drawbox)
www.alexmatei.com
Van B
Moderator
22
Years of Service
User Offline
Joined: 8th Oct 2002
Location: Sunnyvale
Posted: 4th Jul 2018 14:19
You would probably be better off just storing the values, like store the start X and Y of the selection box then store the end X and Y until the mouse button is released, then you'd have the 2 sets of coordinates.

Then, you would use those to decide what size to make the sprite and where it starts - width is X2-X1, height is Y2-Y1, then you can SETSPRITESIZE for that, and SETSPRITEPOSITION to X1,Y1 and it'll be in the same place as the selection. Is this so you can check for collisions on sprites to know what is selected?

I think I said I'd make you an example for this but never got round to it. Feel free to catch me on FB later if you get stuck.
The code is dark and full of errors
MateiSoft
12
Years of Service
User Offline
Joined: 22nd Oct 2012
Location:
Posted: 4th Jul 2018 14:32 Edited at: 4th Jul 2018 14:32
Hello Andrew!
Nice to see you again!

Yes it is indeed! One more try, here:

I have the following code:



I store the values exactly as mentioned but the size is wrong
www.alexmatei.com
Markus
Valued Member
20
Years of Service
User Offline
Joined: 10th Apr 2004
Location: Germany
Posted: 4th Jul 2018 14:48 Edited at: 4th Jul 2018 14:49
This post has been marked by the post author as the answer.
u need the distance between, drawbox using absolute position for the rectangle corners but the sprite size only width and height
width#=abs(crrmsx# -oldmsx# )
height#=abs(crrmsy#-oldmsy# )
AGK (Steam) V2017.12.12 : Windows 10 Pro 64 Bit : NVIDIA (390.65) GeForce GTX 1050 Ti : Mac mini OS High Sierra (10.13)
MateiSoft
12
Years of Service
User Offline
Joined: 22nd Oct 2012
Location:
Posted: 4th Jul 2018 17:12
One other question,

If I want to move a sprite by mouse but starting from it's (sprite) position, how can I add this feature?



Thank you for your help!
www.alexmatei.com
puzzler2018
User Banned
Posted: 4th Jul 2018 17:47
Set the mouse position first of the sprite with

SetRawMousePosition( GetSpriteX( spr ) , GetSpriteY ( spr) )

But others probably have a better solution - im not 2D anymore
MateiSoft
12
Years of Service
User Offline
Joined: 22nd Oct 2012
Location:
Posted: 4th Jul 2018 17:49
Forgot to mention that I have multiple sprites to move
www.alexmatei.com
puzzler2018
User Banned
Posted: 4th Jul 2018 18:00
Are you making something like a card game - so can pick up cards and move - just out of interest..

try looping through,



This is really rough and not tested - but thats how i would achieve it
MateiSoft
12
Years of Service
User Offline
Joined: 22nd Oct 2012
Location:
Posted: 4th Jul 2018 18:08
It's an editor.

I tried looping through but all the sprites are positioning where the mouse is. All of them.
www.alexmatei.com
puzzler2018
User Banned
Posted: 4th Jul 2018 18:18
Try





MateiSoft
12
Years of Service
User Offline
Joined: 22nd Oct 2012
Location:
Posted: 5th Jul 2018 17:55
Hi puzzler,

It still positioning in the middle of the mouse
www.alexmatei.com
puzzler2018
User Banned
Posted: 5th Jul 2018 19:25
Jeeeze that was certainly mind boggling

fubarpk
Retired Moderator
19
Years of Service
User Offline
Joined: 11th Jan 2005
Playing: AGK is my friend
Posted: 6th Jul 2018 07:34
SetSpriteOffset ( iSpriteIndex, x, y )
The offset point is the point that the sprite will rotate around, with (0,0) being the top left corner and (width,height) being the bottom right corner. The offset can also be used to position the sprite using SetSpritePositionByOffset,

SetSpritePositionByOffset ( iSpriteIndex, fX, fY )
mmediately positions the specified sprite to the given X,Y world coordinates. The default world coordinate system has 0,0 as the top left corner, and 100,100 as the bottom right hand corner of the screen (this can be changed using SetVirtualResolution).
fubar

Login to post a reply

Server time is: 2024-11-23 18:18:53
Your offset time is: 2024-11-23 18:18:53