The Daily Click ::. Forums ::. Klik Coding Help ::. Shadows for Enemies
 

Post Reply  Post Oekaki 
 

Posted By Message

Del Duio

Born in a Bowling Alley

Registered
  29/07/2005
Points
  1078

GOTW WINNER CUP 1!GOTW WINNER CUP 2!GOTW WINNER CUP 3!GOTW WINNER CUP 4!Evil klikerHasslevania 2!The OutlawSanta Boot
11th July, 2006 at 08:08:01 -

Hey guys, I don't know if this is possible or not but what I'd like to do is everytime an enemy active object is created, I want to have a separate active object follow him around underneath him for a shadow. I've done this successfully with the main hero character, but the problem is how can you make sure that ALL the shadows won't follow the same enemy instead of one for each?

If it has something to do with the spread value I'm afraid I don't really get it. I know arrays really well though, could I do it using an array?

Thanks!

 
--

"Del Duio has received 0 trophies. Click here to see them all."

"To be a true ninja you must first pick the most stealthy of our assorted combat suits. Might I suggest the bright neon orange?"

DXF Games, coming next: Hasslevania 2- This Space for Rent!

Radix

hot for teacher

Registered
  01/10/2003
Points
  3139

Has Donated, Thank You!VIP MemberGOTW WINNER CUP 1!GOTW WINNER CUP 2!GOTW WINNER CUP 3!GOTW WINNER CUP 4!
11th July, 2006 at 08:31:59 -

Uh, I suppose it's possible to do with an array, but that'd be serious overkill. I don't feel like explaining spread values, so if you can't do that just have a counter that is incremented every time an enemy is created and set some alterable value of both the enemy and the shadow object to its current value when they appear. Then use those values for your object focus.

 
n/a

axel

Crazy?

Registered
  05/02/2005
Points
  4766

Game of the Week WinnerYou've Been Circy'd!
11th July, 2006 at 10:00:10 -

No need for that. You can do this:

*Always
-Destroy "shadow"

*Always
-Create "shadow" at (0;0) from "enemy"

Just be sure to have the destroy event before the create event.

 
n/a

Del Duio

Born in a Bowling Alley

Registered
  29/07/2005
Points
  1078

GOTW WINNER CUP 1!GOTW WINNER CUP 2!GOTW WINNER CUP 3!GOTW WINNER CUP 4!Evil klikerHasslevania 2!The OutlawSanta Boot
11th July, 2006 at 10:34:53 -

I'll have to try that out Axel. Yeah, sorry about being a total spread value n00b Radix, I don't blame ya. I tried to do something with spread values before but it didn't work out so hot.

If I didn't need to distinguish flying enemies from ground ones I wouldn't put the shadows in at all, by giving them some transparency (which is why I need the secondary object instead of just drawing it as part of the enemy's sprite) it looks more realistic. Of course, nothing else in the game looks realistic, so maybe drawing them in solid isn't such a bad idea afterall.

Thanks for your replies!

 
--

"Del Duio has received 0 trophies. Click here to see them all."

"To be a true ninja you must first pick the most stealthy of our assorted combat suits. Might I suggest the bright neon orange?"

DXF Games, coming next: Hasslevania 2- This Space for Rent!

Werbad



Registered
  18/09/2002
Points
  235
11th July, 2006 at 11:51:08 -

When you create the enemy, create a shadow aswell
then just always position the shadow at the enemy
as long as there is as many shadows as enemies they should be positioned one per enemy

 
n/a

Klikmaster

Master of all things Klik

Registered
  08/07/2002
Points
  2599

Has Donated, Thank You!You've Been Circy'd!VIP MemberPS3 Owner
11th July, 2006 at 11:54:39 -

Lol, axels way won't work
Learn how to use spread value

 
n/a

axel

Crazy?

Registered
  05/02/2005
Points
  4766

Game of the Week WinnerYou've Been Circy'd!
11th July, 2006 at 12:18:16 -

Yes it will, fool. I'll make an example.

 
n/a

axel

Crazy?

Registered
  05/02/2005
Points
  4766

Game of the Week WinnerYou've Been Circy'd!
11th July, 2006 at 12:25:15 -

http://aggggge.frac.dk/shadowexample.gam

There. See? It even works in TGF. No spread a value, no fastloops.

 
n/a

Klikmaster

Master of all things Klik

Registered
  08/07/2002
Points
  2599

Has Donated, Thank You!You've Been Circy'd!VIP MemberPS3 Owner
11th July, 2006 at 13:11:52 -

So? Your shadows will lag behind wen they move

 
n/a

axel

Crazy?

Registered
  05/02/2005
Points
  4766

Game of the Week WinnerYou've Been Circy'd!
11th July, 2006 at 15:06:59 -

No they won't. Not if have the right event order.

http://aggggge.frac.dk/shadowexample.gam (updated)

See? I win.

 
n/a

Flava



Registered
  30/07/2002
Points
  684

Has Donated, Thank You!Code MonkeyVIP MemberThe Cake is a LieThe Spinster
11th July, 2006 at 16:45:09 -

Pretty inefficient way of doing things though.
Spreading values is probably the best way - easy to do, plus you're not always destroying and creating new objects. I'm not sure - I would have thought that creating and destroying objects every single split of a second would cause some performance problems on crappy computers. Whereas I am fairly sure you wouldn't have a single problem with spreading values.

Also spreading values allows you to destroy both the object and shadow together, as well as changing animation and stuff. It can be pretty buggy if you do these things using Axel's method.

Image Edited by the Author.

 
This is a signature. Have this one on me.

axel

Crazy?

Registered
  05/02/2005
Points
  4766

Game of the Week WinnerYou've Been Circy'd!
11th July, 2006 at 18:03:06 -

My method only takes two lines of code. Is that inefficient? And I have used it in many games before, and never had any problems with it

Well, do however you like. It's the final product that really matters anyway.

Image Edited by the Author.

 
n/a

RapidFlash

Savior of the Universe

Registered
  14/05/2002
Points
  2712
11th July, 2006 at 20:29:20 -

Use the Spread Values command for some random Alterable Value for both your shadows and enemies. Then, use a fastloop to position the shadow with its corresponding enemy.
I believe Ben Mercer has a shadow engine, or you can use this one: http://www.klik-me.com/KMv2/article.asp?id=24 if you need any help.

As for the Spread Value command: think of it like assigning each object an ID. The first object's alterable value is the initial value (usually 0), the second object's alterable value is the initial value plus one, and so on. Remember to respread the alterable value whenever you create or destroy an object.

 
http://www.klik-me.com

axel

Crazy?

Registered
  05/02/2005
Points
  4766

Game of the Week WinnerYou've Been Circy'd!
11th July, 2006 at 21:58:52 -

Really, you can use whatever you like. I know that it sounds crazy, creating and destroying a lot of objects 50 times per second, but I've never had any problems with it, so what can be so wrong about it?

Now, the exact same thing, but with spread a value/fastloop. It's CCA because I don't have fastloop on my TGF:

http://aggggge.frac.dk/shadowexample.cca

 
n/a

axel

Crazy?

Registered
  05/02/2005
Points
  4766

Game of the Week WinnerYou've Been Circy'd!
11th July, 2006 at 22:48:57 -

... Okay...?

I tested shadowexample.gam with 200 smiley-objects; no problems and no slowdown at all. Will you have 200+ flying enemies on screen at the same time in your game, Del Duio?

Image Edited by the Author.

 
n/a

Flava



Registered
  30/07/2002
Points
  684

Has Donated, Thank You!Code MonkeyVIP MemberThe Cake is a LieThe Spinster
12th July, 2006 at 04:33:54 -

Yeh Phizzy is right

 
This is a signature. Have this one on me.

NeoHunter



Registered
  30/10/2004
Points
  207
12th July, 2006 at 04:50:54 -

I gotta go with Axel on this one, as I'd rather do two lines, then a whole slew of code to get shadows.

Btw this works, and works well enough, as I tested it at work, and even when I gave EVERYTHING a shadow, the game ran fine. The only way this is going to slow things down, is if your computer is a outdated POS.

 
Ohno! The body floats!
-The Teatons

axel

Crazy?

Registered
  05/02/2005
Points
  4766

Game of the Week WinnerYou've Been Circy'd!
12th July, 2006 at 04:59:50 -

Flava, Phizzy: How do you even know that it really DOES slow the game down? Right now you're just assuming so because it's (to you) an awkward way of coding it. At least prove me wrong before jumping to conclusions. o_O

 
n/a

Flava



Registered
  30/07/2002
Points
  684

Has Donated, Thank You!Code MonkeyVIP MemberThe Cake is a LieThe Spinster
12th July, 2006 at 07:03:55 -

No, it's called common sense.
If you want to be unprofessional then fine be lazy and use a two line piece of code. I've just run both programs on my computer and your method uses up more memory. Try it yourself. Okay, it doesn't use up much more memory - but put the rest of your games objects in there and it could prove to be a difference on certain computers.

Your method works fine - if you want a ton of bouncing balls with no animation and no actions at all, then you can use your methods. I'm just saying that spreading values is more efficient, uses less memory and allows the creator/developer to do more things with the objects (such as animating, destroying .etc). And even if it is a few more lines of code - the idea to being a game creator is not to be lazy. If you're lazy, then your game will suck.

I'm just saying - you'll have to add backdrops, scrolling, characters, weapons and all kinds of other things moving at once. And while the player is playing a shadow (which will probably have semi-transparency?) will be created every single split of a second and then destroyed.

Sure, use Axel's method - it probably won't make too much a difference. But please don't be lazy with anything else.

Image Edited by the Author.

 
This is a signature. Have this one on me.

axel

Crazy?

Registered
  05/02/2005
Points
  4766

Game of the Week WinnerYou've Been Circy'd!
12th July, 2006 at 07:14:00 -

It may be a lazy and unproffessional approach, but it's not the end of the world, and it's a lot easier than messing around with spread a value and fastloops, which can be pretty hard unless you know what you're doing.

I'd probably use the spread a value version myself actually, but it's Del Duio's own choice which method he wants to use in his game

 
n/a

Flava



Registered
  30/07/2002
Points
  684

Has Donated, Thank You!Code MonkeyVIP MemberThe Cake is a LieThe Spinster
12th July, 2006 at 07:16:04 -

I'm fairly sure you don't need to use fastloops when using spread values neither.. I can't remember.

 
This is a signature. Have this one on me.

axel

Crazy?

Registered
  05/02/2005
Points
  4766

Game of the Week WinnerYou've Been Circy'd!
12th July, 2006 at 07:18:15 -

Me neither, but it only took 8 lines of code anyway.

http://aggggge.frac.dk/shadowexample.cca

 
n/a

Del Duio

Born in a Bowling Alley

Registered
  29/07/2005
Points
  1078

GOTW WINNER CUP 1!GOTW WINNER CUP 2!GOTW WINNER CUP 3!GOTW WINNER CUP 4!Evil klikerHasslevania 2!The OutlawSanta Boot
12th July, 2006 at 07:52:52 -

So it sounds to me like a spread value basically makes active objects into a single dimensional array. If so, that's just what I want then. Thank you for all of your replies!

 
--

"Del Duio has received 0 trophies. Click here to see them all."

"To be a true ninja you must first pick the most stealthy of our assorted combat suits. Might I suggest the bright neon orange?"

DXF Games, coming next: Hasslevania 2- This Space for Rent!

Werbad



Registered
  18/09/2002
Points
  235
12th July, 2006 at 09:43:44 -

* Always
- Shadow set position at enemy
This works fine and people not aware of this are stupid

 
n/a

Radix

hot for teacher

Registered
  01/10/2003
Points
  3139

Has Donated, Thank You!VIP MemberGOTW WINNER CUP 1!GOTW WINNER CUP 2!GOTW WINNER CUP 3!GOTW WINNER CUP 4!
12th July, 2006 at 10:09:49 -

That will only work for a single object. It may kinda-work for several (MMF showing rare intelligence) but the game will get confused before long, and there's no way to manage destructions. So no. That's almost as horrible as Axel's method.

 
n/a

Flava



Registered
  30/07/2002
Points
  684

Has Donated, Thank You!Code MonkeyVIP MemberThe Cake is a LieThe Spinster
12th July, 2006 at 10:13:19 -

Spreading values allows you to somewhat assign a 'unique ID' to each shadow and object.
So a shadow with ID 1 will assign to the object with ID 1 .etc
This way, you can delete both the object and the correct shadow, or change animations of each or whatever.

Basically spreading values lets you do more things and is completely bug free (if you do it correctly)

 
This is a signature. Have this one on me.

AndyUK

Mascot Maniac

Registered
  01/08/2002
Points
  14586

Game of the Week WinnerSecond GOTW AwardHas Donated, Thank You!VIP Member
12th July, 2006 at 13:23:48 -

It's not good because it's overkill.
The game is doing more work than it needs to and thats bad for minimum system requirements.

Anyway all you need to do is


(amount of shadows < amount of enemy) - create shadow at 0,0
(always) - shadow follow enemy.

that works.

 
.

Radix

hot for teacher

Registered
  01/10/2003
Points
  3139

Has Donated, Thank You!VIP MemberGOTW WINNER CUP 1!GOTW WINNER CUP 2!GOTW WINNER CUP 3!GOTW WINNER CUP 4!
12th July, 2006 at 13:33:31 -

See my last post. That does work thanks to some sort of magic, but it can get confused and there's no guaranteed way to manage destructions. I would use either spread values or my original suggestion, depending whether the enemies are already in the frame or are created at runtime.

Keep in mind that just because you can do something in less events doesn't mean that less instructions are required to actually achieve it: I'm not sure exactly what happens when you use that method, but I can imagine it being some complex stuff, each and every frame, to determine which objects aren't paired with a shadow and vise versa, then allocation, then the actual positioning. While on the other hand if alt values are used to find the object focus directly, it's conceivably (and I'd say likely to be) more efficient.

 
n/a

DanielRehn



Registered
  18/09/2002
Points
  139
12th July, 2006 at 14:26:10 -

What Werbad said is correct... works fine! It's simple to manage destructions as well.. when a unit dies, destroy 1 shadow.. when a unit is summoned add 1 shadow...

 
n/a

Radix

hot for teacher

Registered
  01/10/2003
Points
  3139

Has Donated, Thank You!VIP MemberGOTW WINNER CUP 1!GOTW WINNER CUP 2!GOTW WINNER CUP 3!GOTW WINNER CUP 4!
13th July, 2006 at 00:34:19 -

mispost

Image Edited by the Author.

 
n/a

DeadmanDines

Best Article Writer

Registered
  27/04/2006
Points
  4758
13th July, 2006 at 08:32:45 -

"See my last post. That does work thanks to some sort of magic, but it can get confused and there's no guaranteed way to manage destructions."


I think Radix' description of it as 'some sort of magic' is probably quite accurate, lol. I'm not certain, but I have a feeling that object pairing in MMF is a quirk of the Runtime rather than an intended feature.

MMF seems to handle objects in the order they were created, with older objects being processed first. This applies to events, but it also applies to the Spread Value routine. They're indexed according to the same basis.

The result is that if you spread values in two objects and then tell those objects to follow each other, the objects with the same spread values will naturally line up.

I've personally never found a problem with MMF's auto allocation, but I don't doubt there are some. This IS mmf we're talking about after all!


My favourite method for doing the shadiw thing would just be to spread a value so that they have ID numbers. Then use a simple Always event to auto-position them. When an object dies, select the shadow with the same ID and kill that too. If an object is created, create a shadow as well. At the start, use a fastloop to make sure that the number of shadows is equal to the number of enemies (fastloop prevents a momentary delay at the start).

That's the way I do it, and it's never gone wrong for me.

Since MMF auto-positions objects, you CAN do this without Spread values. Just delete any old shadow (using the 'pick at random...' condition to make sure you only delete one of them, not all). MMF will reposition them again. But this leaves a visible flicker as MMF re-sorts the objects, so it's not recommended.

 
191 / 9999 * 7 + 191 * 7

AndyUK

Mascot Maniac

Registered
  01/08/2002
Points
  14586

Game of the Week WinnerSecond GOTW AwardHas Donated, Thank You!VIP Member
13th July, 2006 at 12:43:18 -

ah, i would have seen your post Radix, but for some reason i was looking at only the first page, not all of them like i usually do.

 
.

Werbad



Registered
  18/09/2002
Points
  235
13th July, 2006 at 18:28:49 -

the "auto allocation" is one of the few things in MMF that is actually working (unless you're completley worthless)
I have never had any problems that I haven't been able to solve using this...

 
n/a

Radix

hot for teacher

Registered
  01/10/2003
Points
  3139

Has Donated, Thank You!VIP MemberGOTW WINNER CUP 1!GOTW WINNER CUP 2!GOTW WINNER CUP 3!GOTW WINNER CUP 4!
13th July, 2006 at 22:18:06 -

It's bad coding practice. Don't do it. Or at least don't tell other people to do it. End story.

 
n/a

Werbad



Registered
  18/09/2002
Points
  235
14th July, 2006 at 07:32:06 -

-_-...
ラヂクスは本当にお馬鹿さんですね。。。

 
n/a

Radix

hot for teacher

Registered
  01/10/2003
Points
  3139

Has Donated, Thank You!VIP MemberGOTW WINNER CUP 1!GOTW WINNER CUP 2!GOTW WINNER CUP 3!GOTW WINNER CUP 4!
14th July, 2006 at 08:41:42 -

Yes, we've all got access to machine translations. If you had anything worth saying you wouldn't do so in moonspeak, coward.

 
n/a

Del Duio

Born in a Bowling Alley

Registered
  29/07/2005
Points
  1078

GOTW WINNER CUP 1!GOTW WINNER CUP 2!GOTW WINNER CUP 3!GOTW WINNER CUP 4!Evil klikerHasslevania 2!The OutlawSanta Boot
14th July, 2006 at 11:43:59 -

Well, there are going to be a lot of active objects in the game in general (land objects like trees, bushes, water sources and etc. I'm glad they give you a 10,000 active limit- I hope I don't use half of it though!

So far, all enemies are going to be created when your invisible line of sight collides with an invisible active picture named "encounter". Then a random enemy is created on that spot. So far, all I've done is ground enemies. There will still be flying enemies, but I may have them on the frame beforehand. Since the ground enemies so far all have an appearing animation of them crawling out of the dirt, creating them this way seems to work, and they don't need a shadow.

Okay, so I was messing around with the spread values last night a bit, and I have a question about it. You have the option to Spread a Value to an active's alterable variable, right? Now if you want to assign it an incrementing ID#, what's the best way to do this? A counter? Oh, and yes the shadows all have semi-transparency to make them look better, and 3 frames of animation where they grow and shrink depending on the relative altitude of the flying creature (in the case I have now, a bat).

 
--

"Del Duio has received 0 trophies. Click here to see them all."

"To be a true ninja you must first pick the most stealthy of our assorted combat suits. Might I suggest the bright neon orange?"

DXF Games, coming next: Hasslevania 2- This Space for Rent!

Knudde (Shab)

Administrator
Crazy?

Registered
  31/01/2003
Points
  5125

Has Donated, Thank You!Clickzine StaffKlikCast StarVIP MemberGhostbuster!Dos Rules!I donated an open source project
14th July, 2006 at 13:36:25 -

Errr...guys.

Always - Destroy Shadow.
Always - Shoot Shadow at speed 0
Always - Bring shadow to back


 
Craps, I'm an old man!

Werbad



Registered
  18/09/2002
Points
  235
14th July, 2006 at 13:39:59 -

We all got translators, I know japanese
there is a slight difference
Anyways, there has been posted quite alot of examples, use whichever one you feel like...

 
n/a

RapidFlash

Savior of the Universe

Registered
  14/05/2002
Points
  2712
15th July, 2006 at 23:07:47 -

"Okay, so I was messing around with the spread values last night a bit, and I have a question about it. You have the option to Spread a Value to an active's alterable variable, right? Now if you want to assign it an incrementing ID#, what's the best way to do this? A counter? Oh, and yes the shadows all have semi-transparency to make them look better, and 3 frames of animation where they grow and shrink depending on the relative altitude of the flying creature (in the case I have now, a bat)."

Spreading a Value should give your objects an incremental ID, unless I'm misunderstanding your question.
Also, I've had a lot of problems with MMF auto-allocation, epescially with shadows.

 
http://www.klik-me.com
   

Post Reply



 



Advertisement

Worth A Click