c++ - move obstacles randomly in game scene in cocos2d-x -


I am creating a game in Xcode using the cocos2d-x (c ++) game engine, and I Starting a game in the game I tried to move obstacles randomly in this game, but it is progressing in sequential order, please solve me the following code I used to move the barrier

  obs1 = CCSprite :: create ("branch.png"); Int val = arc4random% 7; obs1-> setPosition (ccp (winwsize / val, winhsize / 8)); This- & gt; Add Chald (Obs 1, -1); obs1-> SetVisible (true); Schedule (schedule_selector (SceneThree :: OnUpdateFrame)); Zero GameScene :: OnUpdateFrame3 (Boat deltaTime3) {if (obs1-> getPosition () x & lt; -. (Winwsize / 2)). {obs1-> SetPosition (ccp (obs1-> getPosition () x + (2 * winwsize), obs1-> getPosition () y)). } Obs1-> SetPosition (ccp (obs1-> getPosition () x17, obs1-> getposition () wi).); }   

First of all, you are only using a random value for the initial position Are there. And on every tick (this is an update function), you just want to reduce 17 by x position, which can result in gradual steps.

In addition, how your random number is generated, value 0-6, so you will get a value like "winWsize / (a ​​number from 0-6)", as a result, or if not Value IMO will be limited (compared to full screen)

Why not make sure that you use this (arc4random ()% winWSize) in your "OnUpdateFrame3" function, so make sure that This is something like arc4random ()% winWSize (this will give value 0-winWSize)?

Try every tick to get a new random position zero GameScene :: OnUpdateFrame3 (float deltaTime3) {float xValue = arc4random ()% winWSize; obs1-> SetPosition (ccp (Xvalue, obs1-> getPosition () wi).); }

But it is only moving forward with X axis, u can also use similar technology as Y axis too. Also, arc4random can not work on Android, so you should also see it,

Or, you can also use "timestamp" to make your own random value Are there. This is your choice.

Comments

Popular posts from this blog

Java - Error: no suitable method found for add(int, java.lang.String) -

java - JPA TypedQuery: Parameter value element did not match expected type -

c++ - static template member variable has internal linkage but is not defined -