HomeForumsGeneral DiscussionEngine's time logic

This topic has 3 voices, contains 13 replies, and was last updated by  GPP 157 days ago.

Viewing 14 posts - 1 through 14 (of 14 total)
Author Posts
Author Posts
November 30, 2011 at 3:34 am #564

GPP

I’m assuming cocos2d has a time-logic mechanism built into its engine wherein you can call the timecount method within spawn loops.

So for example, let’s say you created a class called ‘spawn point’ and wrote a loop for spawning baddies. Obviously you dont want them to all spawn at once, so within the loop you’d create an if statement, but what is the method for saying, “spawn +1 AFTER 15 seconds?”

November 30, 2011 at 3:58 pm #2175

CyberGreg

Check the Cocos2d docs and look for the schedule: interval: method

You’d create your spawn method and then add a “schedule” with interval: 15

:-)

November 30, 2011 at 5:55 pm #2176

GPP

Thanks for the headsup! Would it be a method? Which class would the method be a part of? The gamestate?

November 30, 2011 at 6:50 pm #2177

CyberGreg

No prob :-)
You actually have lots of options; the way Nat has the project laid out you’d probably add the “spawn” method to the Enemy class then every enemy you create would have the option to spawn whether you need to or not.

November 30, 2011 at 7:30 pm #2178

GPP

Interesting. I didnt think it’d be part of the enemy class, but that does make sense.

So on TILED (the tileset program) when you place an object and then designate its type as “spawnpoint” I’m assuming that’s the method name? And that baddies would continually spawn from that point?

I think there’s something I may be missing here.

December 1, 2011 at 12:45 pm #2179

CyberGreg

Yes you could but I think something like: “spiderspawner” and then “skeletonspawner” would work better. :-)

You’d have to create / add your spawn method in the Enemy class, actually I’d put it in the Character class. So you’d create a generic “spawn” method that takes some parameters and then when defining your “spiderspawner” your call the spawn method.

I am going to do this too but haven’t gotten around to writing the code.. yet. :-)

December 1, 2011 at 9:31 pm #2180

GPP

I see, it’s trickier than it sounds.

btw, do you know of the Objective C Mobile Dev wiki site? I remember going to it several times, but I can’t find it. It detailed Objective-C and Objective-C 2.0x development for both the android and iphone.

December 1, 2011 at 10:58 pm #2181

CyberGreg

Sorry, no – my goto search site is stackoverflow

December 2, 2011 at 1:04 am #2182

GPP

Thanks for answering all my questions, you’ve been a champ. I was looking at the Cocos2D-x wiki and it looks like you also need to write a collision detection for bullets and baddies.

I’m surprised Cocos2D doesnt have its own method for that already written.

December 2, 2011 at 6:18 pm #2183

joeb

You might be able to cheat on this if you use the MAYBECREATE method in the update delta. For example, you could have a ‘spawn’ item that has no sprite so it’s invisible, or use a sprite and do setVisible=NO;, then in the update delta of the item have it spawn an enemy.
The mod function is VERY helpful for executing something at a time interval other than every time. Tinker with the probability value to make it even more random.

For example, to have a 50% chance of spawning a spider every 15 seconds, it would look like this:

if(0==timer%15)
{
[[self getLevel] maybeCreate:@”SPIDER” position:self.position probability:0.5f flip:NO];
timer=1;
}
timer++;

December 2, 2011 at 6:26 pm #2184

GPP

That’s an interesting loop setup. Btw, I am learning objective-c while simultaneously trying to plot out how it all would work.

What does the ‘flip’ refer to in

position:self.position probability:0.5f flip:NO

December 2, 2011 at 6:27 pm #2185

joeb

The flip is the method that rotates the object in the air with the ‘swoosh’ sound. Think of the bones that pop out of the chests in quexlor. Unless you want your spiders flying out (which you may lol) keep it set to NO :)

December 2, 2011 at 6:29 pm #2186

CyberGreg

Edit: yeah, what ^^^ he said ;-)

Check the super class; pretty sure its a boolean that determines whether or not the item animates in a “flipped” motion or just kind of appears (drops).

:-)

December 14, 2011 at 12:17 am #2201

GPP

Just to clarify, would I be writing a method for each enemy e.g. one for the spider, skeleton, etc?

Or would I write on method and then call that method to the spider in the code? But then how would I identify that code and call that method on Tiled when I am placing my objects. That’s what I am not getting

Viewing 14 posts - 1 through 14 (of 14 total)

You must be logged in to reply to this topic.