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 / DrawLine Need Help

Author
Message
Behdadsoft
15
Years of Service
User Offline
Joined: 7th Apr 2009
Location: Tehran-Iran
Posted: 23rd Jan 2016 20:00 Edited at: 23rd Jan 2016 20:56
Hi.

I want make a game like Fruit Ninja. so I wrote below script for draw line with mouse but I need some question:

1- how can inc the thickness of the line?
2- how can check collision between Sprite and Line? (I think this work is impossible because I can't find any command for do this)

Thanks.

Phaelax
DBPro Master
21
Years of Service
User Offline
Joined: 16th Apr 2003
Location: Metropia
Posted: 23rd Jan 2016 20:49
Easiest way is probably to turn your line into a sprite.


"I like offending people, because I think people who get offended should be offended." - Linus Torvalds
Behdadsoft
15
Years of Service
User Offline
Joined: 7th Apr 2009
Location: Tehran-Iran
Posted: 24th Jan 2016 05:52 Edited at: 24th Jan 2016 05:53
Thanks Phaelax it's grate idea.

I improved it but seem during drawing line, more than one line is drawn. what do you think?

Phaelax
DBPro Master
21
Years of Service
User Offline
Joined: 16th Apr 2003
Location: Metropia
Posted: 24th Jan 2016 11:17
Don't delete and recreate the sprite, simply hide it with setSpriteVisible.

And you don't need to make 'line' global, just return the new sprite ID from the function



I can't say for sure why you're seeing two lines though.

"I like offending people, because I think people who get offended should be offended." - Linus Torvalds
Behdadsoft
15
Years of Service
User Offline
Joined: 7th Apr 2009
Location: Tehran-Iran
Posted: 24th Jan 2016 12:06
Quote: "Don't delete and recreate the sprite, simply hide it with setSpriteVisible."


I Think should be delete sprite and recreate it because if I Draw a line and use setSpriteVisible, fruits can collide with it. or I can check if line is invisible, then collide= 0.

Quote: "I can't say for sure why you're seeing two lines though."


Unfortunately, I see the two lines and don't know why draw two line.
Digital Awakening
AGK Developer
22
Years of Service
User Offline
Joined: 27th Aug 2002
Location: Sweden
Posted: 24th Jan 2016 12:36
You don't have to manually draw a sprite. AppGameKit will draw all visible sprites when you call sync(). I think SetSpriteActive makes it so it doesn't register collisions but can't look it up right now.
Digital Awakening
AGK Developer
22
Years of Service
User Offline
Joined: 27th Aug 2002
Location: Sweden
Posted: 24th Jan 2016 19:53
Seems like you need to use SetSpritePhysicsOff() to stop the physics for the sprite.
Behdadsoft
15
Years of Service
User Offline
Joined: 7th Apr 2009
Location: Tehran-Iran
Posted: 25th Jan 2016 05:12
Quote: "Seems like you need to use SetSpritePhysicsOff() to stop the physics for the sprite."


why?

I used Physics only for Fruits.
Digital Awakening
AGK Developer
22
Years of Service
User Offline
Joined: 27th Aug 2002
Location: Sweden
Posted: 25th Jan 2016 08:07
If you use physics to check collision between line and fruits and don't delete the sprite it doesn't work to just hide it.
Behdadsoft
15
Years of Service
User Offline
Joined: 7th Apr 2009
Location: Tehran-Iran
Posted: 25th Jan 2016 10:11
Quote: "If you use physics to check collision between line and fruits and don't delete the sprite it doesn't work to just hide it.
"


I use GetSpriteCollision() for check Collision Between Line and Fruits.
Behdadsoft
15
Years of Service
User Offline
Joined: 7th Apr 2009
Location: Tehran-Iran
Posted: 25th Jan 2016 17:54 Edited at: 25th Jan 2016 17:59
@Digital Awakening

do you know why after draw line, we see two or three line?
Digital Awakening
AGK Developer
22
Years of Service
User Offline
Joined: 27th Aug 2002
Location: Sweden
Posted: 25th Jan 2016 18:20
I Think this is because AppGameKit draws the sprite and then you draw it manually. I am also thinking that perhaps you are creating more than one sprite.
Phaelax
DBPro Master
21
Years of Service
User Offline
Joined: 16th Apr 2003
Location: Metropia
Posted: 25th Jan 2016 20:03
I'm not seeing where he's manually drawing the sprite. But perhaps it's redrawing it faster than its size can be updated, giving an appearance of two?

"I like offending people, because I think people who get offended should be offended." - Linus Torvalds
Digital Awakening
AGK Developer
22
Years of Service
User Offline
Joined: 27th Aug 2002
Location: Sweden
Posted: 25th Jan 2016 20:28
Quote: "I'm not seeing where he's manually drawing the sprite. But perhaps it's redrawing it faster than its size can be updated, giving an appearance of two?"


My bad, it's the name of the function that fooled me

Then I am pretty sure that he's creating multiple sprites somehow. AppGameKit shouldn't draw the sprite multiple times unless EnableClearColor( 0 ) is used. My head is too tired to figure it out.
Behdadsoft
15
Years of Service
User Offline
Joined: 7th Apr 2009
Location: Tehran-Iran
Posted: 26th Jan 2016 09:02
Quote: "I'm not seeing where he's manually drawing the sprite. But perhaps it's redrawing it faster than its size can be updated, giving an appearance of two?"


yes, I see two or three line in mobile and pc. but when I make a capture of the game, captured file is shown normally.
CJB
Valued Member
20
Years of Service
User Offline
Joined: 10th Feb 2004
Location: Essex, UK
Posted: 26th Jan 2016 09:06
It is drawing more than one line because that is what you are telling it to do. While the pointer is pressed, you will continue drawing lines for 0.1 seconds and then you will continue to create and delete line sprites until the pointer is released. What is it you are trying to achieve? You need to revisit your nested ifs. Maybe add a flag to check whether the line has been drawn.
V2 T1 (Mostly)
Phone Tap!
Uzmadesign
Behdadsoft
15
Years of Service
User Offline
Joined: 7th Apr 2009
Location: Tehran-Iran
Posted: 28th Jan 2016 07:47 Edited at: 28th Jan 2016 07:59
Quote: "It is drawing more than one line because that is what you are telling it to do. While the pointer is pressed, you will continue drawing lines for 0.1 seconds and then you will continue to create and delete line sprites until the pointer is released."


in my CretaeSpriteLine() Function, Used if GetSpriteExists(line) = 0 then line = createSprite(0). so until line sprite is exists, can't create another sprite.
also if I don't wait for 0.1, I can't draw line like Fruits Ninja game.

Login to post a reply

Server time is: 2024-09-29 09:21:00
Your offset time is: 2024-09-29 09:21:00