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 Chat / Totally Noob Question

Author
Message
sprcoll
6
Years of Service
User Offline
Joined: 26th Aug 2012
Location:
Posted: 3rd Jan 2018 19:09
Hello all together, hope that someone helps.

I want to open a sprite, which is not visible before i make a collision, and this two times.
I use the following code:

loadimage(1,"one.png")
createsprite (1,1)
loadimage(2,"two.png")

if button = 1 and getspritecollision (mouse with sprite one)
createsprite (2,2)
setspriteposition(2,x,y)

This works fine, but if i want a collision with sprite two and there create sprite 3, it doesn´t work.

I have found a method that works, but i don´t know if it is good.

i create the sprite three at the top of the code and set this one invisible and if i make a collision with the second sprite i make it visible.

I guess, there is a better way.

Thanks for hepl

Scraggle
VIP Member
15
Years of Service
User Offline
Joined: 10th Jul 2003
Location: Yorkshire
Posted: 3rd Jan 2018 19:42
The collision is probably still hitting sprite 1.
You have said what is happening to sprite 1 after the collision but if it's no longer needed then try deleting it or moving it offscreen.
Jack
14
Years of Service
User Offline
Joined: 4th Oct 2004
Location: [Germany]
Posted: 3rd Jan 2018 20:12
Hello sprcoll,

can you send more code, so we can also compile? And can you explain, what you want to do with it in detail?
I see the possible error, that you may use getspritecollision outsite a loop - it's unusal and brings up the question, how this code should behave.


[/url]
CJB
Valued Member
14
Years of Service
User Offline
Joined: 10th Feb 2004
Location: Essex, UK
Posted: 4th Jan 2018 15:27 Edited at: 4th Jan 2018 15:28
Instead of createsprite (2,2), just do createsprite (2)... If you need to keep track of the spawned sprite IDs then you'll need to set up a dynamic array to store the values as they are generated.

EDIT: Also, when you post a question, try to make the subject relevant to the question. That way people can find it when they use the search facility
Conjured Entertainment
AGK Developer
13
Years of Service
User Offline
Joined: 12th Sep 2005
Location: Nirvana
Posted: 4th Jan 2018 15:29
Quote: "
loadimage(1,"one.png")
createsprite (1,1)
loadimage(2,"two.png")

if button = 1 and getspritecollision (mouse with sprite one)
createsprite (2,2)
setspriteposition(2,x,y)

This works fine, but if i want a collision with sprite two and there create sprite 3, it doesn´t work.
"


createsprite (2,2) should not be in a button condition without deleting the sprite first.

You only need to create it once, so create all your sprites outside of your loops at the beginning.

Quote: "I have found a method that works, but i don´t know if it is good.

i create the sprite three at the top of the code and set this one invisible and if i make a collision with the second sprite i make it visible."

Right

if all you want is visibility on the collision, then that is all you need to do to the sprite you already created, not recreate the sprite.

If you want to check that collision only x times then use a variable to count it and add that condition to the collision check

Coding things my way since 1981 -- Currently using AppGameKit V2 Tier 1
sprcoll
6
Years of Service
User Offline
Joined: 26th Aug 2012
Location:
Posted: 4th Jan 2018 18:41
Thanks to all of your help. Here is a little bit more code

loadimage (20,"mouse".png)
createsprite (20,20)

loadimage (21,"menu_1".png)
createsprite (21,21)

loadimage (22,"menu_2.png")

loadimgae (23,"menu_3.png")

do

if button = 1 and getspritecollision (20,21)
createsprite (22,22)
setspriteposition (22, 1300, 100)
endif

Until here it works.

if button = 1 and getspritecollision (20,22)
createsprite (23,23)
setspriteposition (23,1300,200)
endif

Sync()

If i compile this, i get a massage that sprite 22 doesn´t exist but i have this one created before.

puzzler2018
1
Years of Service
User Offline
Joined: 8th Oct 2017
Location:
Posted: 4th Jan 2018 19:02 Edited at: 4th Jan 2018 19:04
Wouldnt it be easier to do

Conjured Entertainment
AGK Developer
13
Years of Service
User Offline
Joined: 12th Sep 2005
Location: Nirvana
Posted: 4th Jan 2018 21:37
Quote: "Wouldnt it be easier to do..."


YES

That is what I'm talking about, create the sprites first, then change them under conditions in your loop.

Coding things my way since 1981 -- Currently using AppGameKit V2 Tier 1
sprcoll
6
Years of Service
User Offline
Joined: 26th Aug 2012
Location:
Posted: 7th Jan 2018 17:12
OK, thank you. Now it works good.

Login to post a reply

Server time is: 2018-10-15 23:03:02
Your offset time is: 2018-10-15 23:03:02