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.

Newcomers AppGameKit Corner / [ AGK] [Sprites][Multiple IDs] How do I create multiple sprites with the range of id's in only 1 command

Author
Message
Alex Goaga
9
Years of Service
User Offline
Joined: 6th Nov 2015
Location:
Posted: 20th Sep 2016 22:44
Hi guys,

I have a problem when I try to create multiple sprites with specific images and size ( tried the search option on the forum but didn't quite find the answers I was seeking for . also searched in the Manual but the same issue appeared )

This is one of my generation codes



( turnuri = towers in another language )

And this code

canistre = 0
numar_canistre = 20


canistra = gas cans in another language

The questions are :
1) How do I know what ID's are using the towers and the gas cans in order to be touched by the sprite that the player will use?
2) How I can know create the gas cans on the top of the towers , usually the are randomly created and some of them are created inside the tower sprites?

I want to use the most simplest command :



But this one affects ONLY the last gas can...I'm guessing that the last one has the last ID so the player can touch it. But why not the rest? They are not "technically "created with the same ..ID? while canistre < numar_canistre canistra = createsprite(200)

If is needed i will provided the code translated in English.

Thank you for your time and future answers.
Phaelax
DBPro Master
21
Years of Service
User Offline
Joined: 16th Apr 2003
Location: Metropia
Posted: 20th Sep 2016 23:55
Quote: " have a problem when I try to create multiple sprites with specific images and size "

What kind of problem? Your creation code looks ok to me.

Quote: "How do I know what ID's are using the towers "


Well, you specified the IDs yourself:
for turnuri=1 to 100
createsprite(turnuri,1)



Personally, I tend to let the command generate the ID for me and I store it into an array.


From looking at your code, I see a canister is deleted when the player hits it. So I'm guessing it's an item the player can pick up. We can make this more robust using a UDT to set properties to each item. In this case, I'll assume the canister is a gas can and holds a random amount of fuel (for example). Create your canisters in an array just like how I have also done with the towers.








To check collision amongst all items, you have to loop through all the IDs. You weren't updating the value of 'canistra' once you were done creating the canisters, so it was going to stay the last value it was assigned, which was the last canister.

"I like offending people, because I think people who get offended should be offended." - Linus Torvalds
Alex Goaga
9
Years of Service
User Offline
Joined: 6th Nov 2015
Location:
Posted: 21st Sep 2016 09:50
Marvelous work! It's perfect for what I needed. Works flawless.

About the
Quote: "Quote: "How do I know what ID's are using the towers ""
I was hopping that somehow by using any other method than arrays , I could see each tower ID by using the for turnuri=1 to 100 to be auto-creating somehow ...a wanna-be-array...something like that...( I don't know what exactly i had in mind ...)


I will try using the array to create the perfect position for the gas can creations. ( on the top of the towers ) , and i will come back to say if i managed to succeed or fail

Thank you for your time
Phaelax
DBPro Master
21
Years of Service
User Offline
Joined: 16th Apr 2003
Location: Metropia
Posted: 21st Sep 2016 16:45
One thing you can do for canister placement is randomize the X value only. Then from that point start at the top of the screen and measure down to the top of whatever tower is there. Then you can place the canister right on top of the tower.

"I like offending people, because I think people who get offended should be offended." - Linus Torvalds
Alex Goaga
9
Years of Service
User Offline
Joined: 6th Nov 2015
Location:
Posted: 22nd Sep 2016 06:30 Edited at: 22nd Sep 2016 06:56
can't seem to figure it out.

Tried to use this :



*EDIT*
I forgot to add this :
the tower creation is based on the entire level distance so in order to be created I use this

SetSpritePosition(towers[nr].id,random(starting_distance,total_distance_of_the_game-last_bulding_position ),90-tower_height)


But it seems that somehow it's giving me a crash at the running , but the compiler works perfectly...

What's your idea to place some of them on the top of towers and some of them ( witch have a collision with the tower ) to put them on top ( i've bypassed this a little by using the gravity , and let them fall from the "sky" )

Login to post a reply

Server time is: 2024-11-22 03:24:39
Your offset time is: 2024-11-22 03:24:39