This forum is read only and just serves as an archive. If you have any questions, please post them on

1 decade ago by BennyT

Hi all,

I am working on my platformer and I have created some power up entities based on the trigger entity from the entity pack.

Couple of questions regarding them getting to work properly (surprisingly I couldn't find much in the forum about this).

1. Should I use the entity.touches() method or entity.check(other) when it comes to collisions?
2. What is the best way to make it disappear after it has been triggered? (the kill() method)?
3. How can I get the effect (eg. double strength) to last only for a period of time (eg. 5secs)?

Thankyou for your help and I am hoping this thread will be useful to others when it comes to designing power ups.

1 decade ago by lazer

1. I usually use touches() only when I need to check against a specific entity. Eg if the mouse pointer touches a GUI entity, do X. If an entity needs to touch various kinds of other entities I use check.

2. Yes, I would suggest kill()

3. Look up ig.Timer() - start a timer when the powerup is activated. Then you can do something like:

In check function:
if other is powerup
this.strength += strengthBoost
kill powerup
start strength boost timer

In update function:
if strength boost timer delta > 0
this.strength -= strengthBoost
destroy strength boost timer (or reset and pause it, however you want to handle it)

1 decade ago by BennyT

Thanks Lazer for the feedback!

1. I followed your advice and went with the entity.check() method rather than touch. I will try using touch() for a power up hidden in a box. When player touches box, then open, then powerup flies out.

2. I went with kill() for the method in the check() method, but ran into a problem with the timer. When you kill the entity - the update() method is not called again and hence you can never deactivate the powerup after a time limit. See code:

I don't really want to set a generic timer in the main.js file to be used for any kind of timing but is that a quick fix?

1 decade ago by lazer

I was thinking you could check for the powerup pickup in your player's check method, not the powerup. Then you can set the timer in your player entity instead of the powerup entity. If the powerup entity has any specific attributes (eg seconds to boost for) that are specific to it only you can always set those as a variable in the player entity right before killing the powerup in the check method (eg this.strengthBoostTime = other.strengthBoostTime) (this being the player and other being the powerup it touched).

1 decade ago by BennyT

Actually that is a really good point lazer.

I just updated the gist (in the last couple of minutes) with a solution where the player effects the powerup.

But on second thoughts - your logic makes more sense. I thought the code was looking a bit clunky with making a request for the player, set the timer, etc.

I will work on the new gist and probably add my player entity as well.

1 decade ago by lazer

Yeah, there are a few different options. Yours can work also, just depends on preference I guess. The idea of setting everything in the powerup using "other" to refer to the player also works if you want to have effects distinct in the code for various powerups (as opposed to mashing powerup related stuff into the player entity). You could still even set the timer in the player from the powerup using "other" if you wanted and then kill the powerup straight after.

I've recently taken to putting stuff like that into one entity. Eg in my rough brainstorm game for One Game a Month I have various "tools" that the player can use, similar to powerups in that they are all the same kind of entity, just with different effects. Prune tool, fertilizer, water, etc. Each of these tools is actually one entity (EntityTool) with different "kinds". So one is kind 'water', one is kind 'fertilizer', etc. Then I use conditionals in that one entity's code to separate out the effects. You can see the code here: (and the game at

Having said that I've had second thoughts about this system. I'm not sure if there's any real benefit other than a slightly smaller codebase of doing this over separating each tool/powerup/whatever into its own entity. I think for the next game I would probably try separating them out into different entities instead for organizational purposes.
Page 1 of 1
« first « previous next › last »