Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>This is a pretty broad question unfortunately, which makes it difficult to answer in any definitive terms. If you are hoping to create actual platforms that can be bounced on (in a doodle jump manner) you are going to need to implement collision detection between the Monsters and the Platform ccNodes. There are numerous tutorials online for cocos2d collision detection, both simple implementation and the more advanced box 2d/chipmunk based solutions.</p> <p>If you are looking to clone doodle jump fairly closely, there is an open source version of a clone available on github <a href="https://github.com/haqu/tweejump" rel="nofollow">here</a> - though I've not actually looked at the code.</p> <p>Finally, if you mean that you simply want to restrict the movement of the monsters to a particular area of the screen (so they don't keep running off the edge) you just need to position the target to an area on the screen and alter the<code>ccAction</code> so that the <code>ccMoveTo</code> uses the left most point of the 'platform' as the furthest point left it can move to and the right most point as the furthest right. (I'll confess I've not played Doodle Jump so have no idea what the enemies actually do).</p> <p>If the enemies run back and forth across the platform you should look into using <a href="http://www.cocos2d-iphone.org/api-ref/0.99.5/interface_c_c_repeat_forever.html" rel="nofollow">ccRepeatForever</a> on your movement sequence and have two destination positions in the <code>CCSequence</code> : one that moves the monster to the left of the platform, the other to move it to the right.</p> <p><strong>Additional Info</strong></p> <p>Ok, I see what you are trying to do. This should get you started:</p> <p><strong>Platforms</strong> are created in <code>initPlatforms</code>. This calls <code>initPlatform</code> a number of times. This grabs an image from the <code>AtlasSprite</code> for the platform, creates a <code>ccSprite</code> for each platform and assigns it a unique tag. </p> <p>Then, in <code>- (void)step:(ccTime)dt</code> it loops through all the platforms and moves them to their correct location based on how far the bird has moved:</p> <pre><code>for(t; t &lt; kPlatformsStartTag + kNumPlatforms; t++) { AtlasSprite *platform = (AtlasSprite*)[spriteManager getChildByTag:t]; //etc... </code></pre> <p>So, the bit you are waiting for:</p> <p>If you want to add a monster to these platforms, you will have to follow a similar pattern. To get started try something like this (You will want to have a cleaner design than this though but it should put you on the right track)</p> <p>in <code>initPlatform</code> add the following to the end of the function</p> <pre><code>// add a monster sprite AtlasSprite *monster = [AtlasSprite spriteWithRect:CGRectMake(608,128,64,64) spriteManager:spriteManager]; [spriteManager addChild:monster z:3 tag:currentPlatformTag + 1000]; </code></pre> <p>(I've just grabbed an image from the existing Atlas. You could replace the above with your actual 'Monster' sprite object. Notice I add 1000 to the<code>currentPlatformTag</code>. This is just for testing; you should have a <code>monsterTag</code> implementation eventually.</p> <p>So now every platform has a 'monster' (Again, you will only want to target random platforms) so we need to update the positions for the monsters.</p> <p>In <code>- (void)step:(ccTime)dt</code> directly after you get the current platform</p> <pre><code>AtlasSprite *platform = (AtlasSprite*)[spriteManager getChildByTag:t]; </code></pre> <p>You now also need to get the current monster (remembering to use the updated tag value we created for 'monsters':</p> <pre><code>AtlasSprite *monster = (AtlasSprite*)[spriteManager getChildByTag:t + 1000]; </code></pre> <p>Then, a few lines below where we reposition the platform we will need to reposition the monster</p> <pre><code>platform.position = pos; // We update the monster and set it a 32 pixels above the platform: monster.position = ccp(pos.x, pos.y + 32); </code></pre> <p>So now each platform has a monster on it whose y position moves with the the platforms :-) Hope this helps</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload