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 / Cloning sprites with main sprite behaviour

Author
Message
Midget Blaster
AGK Developer
3
Years of Service
User Offline
Joined: 7th May 2016
Location:
Posted: 15th May 2016 19:16
So far, I have this

clonedenemy = CloneSprite(enemy)

if GetSpriteExists (enemy)
SetSpritePosition ( enemy, 200, y# )
SetSpritePosition(clonedenemy, 300, y#)
y# = y# + 4
endif

I also have that the level restarts if there is a collision between the enemy and a player. However, there are about 100 enemies per level, and I want to know is there an easier way of cloning hundreds of sprites at a time, with their parents behaviour, and then it just being a matter of placing one down individualy?

Thanks
BatVink
Moderator
16
Years of Service
User Offline
Joined: 4th Apr 2003
Location: Gods own County, UK
Posted: 15th May 2016 20:14
There are a couple of things:

1. Put the IDs and positions of all your sprites in an array. Then you can iterate through them using a loop, making the necessary offsets.
2. You can use 2D Physics fixed joints and a kinematic "Master" enemy. when you move the master, all others will move with it.
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
Quidquid latine dictum sit, altum sonatur
TutCity is being rebuilt
Midget Blaster
AGK Developer
3
Years of Service
User Offline
Joined: 7th May 2016
Location:
Posted: 15th May 2016 21:42
Could you please give me a very simple example of what you mean?
I tried, and I failed big time

clonedenemy = CloneSprite(enemy)
DIM cloneArray[5]
cloneArray[1] = SetSpritePosition(clonedenemy, 300, y#)
BatVink
Moderator
16
Years of Service
User Offline
Joined: 4th Apr 2003
Location: Gods own County, UK
Posted: 16th May 2016 16:14
Written without an editor, there may be syntax errors. It is making a grid of 10x10 enemies from square sprites:



With this setup it is easy to apply a movement to all enemies based on an algorithm or formula.
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
Quidquid latine dictum sit, altum sonatur
TutCity is being rebuilt
hoyoyo80
3
Years of Service
User Offline
Joined: 11th May 2016
Location:
Posted: 19th May 2016 08:33
BatVlink, can elaborate more on this "arrEnemy[thisEnemy]" usage of thisEnemy. Later on how to iterate through all the tEnemy with all confusing bracket and .

Login to post a reply

Server time is: 2019-11-12 19:27:52
Your offset time is: 2019-11-12 19:27:52