The Daily Click ::. Forums ::. Klik Coding Help ::. Spread Values And How?
 

Post Reply  Post Oekaki 
 

Posted By Message

Søren Jensen



Registered
  10/11/2010
Points
  20
30th November, 2010 at 20:11:43 -

Ok so i need to create a hidden collision object on every enemy when they are created.

So on ####
{{Create Enemy at 0,0
{{Create Collision at 0,0
{{Set Enemey val(a) = Spread 999999
{{Set Collision val(a) = Enemy val(a)
{{Position Enemy at gamex,gamey

always
If Collision val(a) = Enemey val(a)
{{position collision at enemy 0,0
{{Set visibility of Collision to Invissible

However at some reason all the collisions still ends up on 1 enemy.

What am i doing wrong?




Edited by Søren Jensen

 
n/a

GamesterXIII



Registered
  04/12/2008
Points
  1110

I am an April Fool
30th November, 2010 at 20:40:16 -

Try this.

# of Object "Collision" < # of Object "Enemy"
- Create Object Collision at -50,-50

Always
- Spread 1 into Value A Of "Enemy"
- Spread 1 into Value A Of "Collision"

Compare Two General Values - Value A of "Collision" = Value A of "Enemy"

Set X of "Collision" to X of "Enemy"
Set Y of "Collision" to Y of "Enemy"

Edited by GamesterXIII

 
n/a

Don Luciano

Heavy combat pancake

Registered
  25/10/2006
Points
  380

VIP Member
30th November, 2010 at 21:07:43 -

You need loops for that.

Create enemies

1.
enemy spread value 0 in A :this spreads value starting from 0, do not place in the same event that starts the loop

2.
start loop "awesome" count number of enemies times

3.
on loop "awesome"
enemy alt A = loopindex("awesome")
-
create collision
set collision alt A to fixed of enemy


Now the positioning part. you can also use sticky object extension instead of this.
4.
always
start loop "stickem" number of enemies

5.
on loop "stickem"
enemy alt A = loopindex("stickem")
collision alt A = fixed of enemy
-
collision set position to enemy

Edited by Don Luciano

 
Code me a sausage!

Søren Jensen



Registered
  10/11/2010
Points
  20
30th November, 2010 at 23:34:45 -

Yay! thanx a bunch.. works smooth

I used ur method Gamester since thats the most understandable.. i hate loops

So to continue on. So what if the Enemy is destroyed and the collision bob also needs to be destroyed?


Edited by Søren Jensen

 
n/a

Don Luciano

Heavy combat pancake

Registered
  25/10/2006
Points
  380

VIP Member
1st December, 2010 at 00:24:00 -

what gamester wrote:
Compare Two General Values - Value A of "Collision" = Value A of "Enemy"
-
destroy enemy
destroy collision


But unless you have a way of selecting enemies, i would suggest using a loop. Don't be a loop hater, loops are great

 
Code me a sausage!

Søren Jensen



Registered
  10/11/2010
Points
  20
1st December, 2010 at 19:02:11 -

yeah works with 1 attachment but not 2. Tobad u cant compare 3 values in 1 command!

 
n/a

GamesterXIII



Registered
  04/12/2008
Points
  1110

I am an April Fool
1st December, 2010 at 19:55:49 -


Originally Posted by Søren Jensen
yeah works with 1 attachment but not 2. Tobad u cant compare 3 values in 1 command!



Can you post a MFA?

I know you can do this pretty easily. You could try linking the objects by multiple values:

Example:

Always
-Spread 1 into Value A of "Player"
-Spread 1 into Value B of "Player"

Compare Two General Vales - Value A of "Collision" = Value A of "Player"
-Set X of "Collision" to X of "Player"
-Set Y of "Collision" to Y of "Player"
-Set Value B of "Collision" to Value B of "Player"

Player HP = 0
-Set Value B of "Player" to 1

Value B of Player = 1
-Destroy

Value B of "Collision" = 1
-Destroy

Edited by GamesterXIII

 
n/a

UrbanMonk

BRING BACK MITCH

Registered
  07/07/2008
Points
  49566

Has Donated, Thank You!Little Pirate!ARGH SignKliktober Special Award TagPicture Me This Round 33 Winner!The Outlaw!VIP MemberHasslevania 2!I am an April FoolKitty
Picture Me This Round 32 Winner!Picture Me This Round 42 Winner!Picture Me This Round 44 Winner!Picture Me This Round 53 Winner!
1st December, 2010 at 20:27:11 -

If you must use a separate object for collision detection then may I recommend using only one, and just change it's position in a loop and check for collisions there?

Way less memory usage, and a lot faster.

Although if it were me I'd drop loops altogether and make a separate frame for each enemy as the "collision mask" frame, then switch to that frame, check for collision, and switch back. If you switch back to the enemies frame before the end of the main event loop the collision mask frame will never be seen.


Just some ideas for you. This is especially useful for flash games where loops can kill the frame rate.

 
n/a

Don Luciano

Heavy combat pancake

Registered
  25/10/2006
Points
  380

VIP Member
1st December, 2010 at 20:29:49 -

Thats actually a very good idea.

 
Code me a sausage!

GamesterXIII



Registered
  04/12/2008
Points
  1110

I am an April Fool
1st December, 2010 at 20:32:57 -


Originally Posted by urbanmonk

Just some ideas for you. This is especially useful for flash games where loops can kill the frame rate.



Loops can easily kill the framerate outside of flash too.

I try to avoid loops wherever possible as a personal preference, and because of this very reason.

 
n/a
   

Post Reply



 



Advertisement

Worth A Click