0

I am creating a side scrolling game.

I compute all the points representing what a terrain should look like by doing the following:

  • The points representing the top of the hill are determined by using a sin function.
  • The bottom of the hill is just the bottom of the screen.
  • The left and right edges of the terrain, are the left and right edges of the screen, where the x coords are x=0, and x= screen width.

But I don't know how to draw it on screen, and "fill" it with some other texture. (A predetermined PNG image or something).

How does one override the draw method of a CCNode or CCSprite to accomplish this ?

In the example below I would use a square png image of stars, which I would like to repeat as I scroll the terrain from left to right.

Hills

Edit: In the tutorial below, they do all kinds of calculations and wrap a sprite around the hills. But I just want to do something simple, like fill the hills with a simple "noise" texture (no stripes etc), or a solid color. How can I do that?

: http://www.raywenderlich.com/32954/how-to-create-a-game-like-tiny-wings-with-cocos2d-2-x-part-1

EDIT: To clarify: I know one can override the draw method. But I don't know what code to put in it to accomplish the problem I described above.

Rahul Iyer
  • 19,924
  • 21
  • 96
  • 190

1 Answers1

0

Create a new class that subclasses CCNode or CCSprite, and add a draw method:

- (void) draw {

}

The draw method will automatically execute each frame. Put whatever "drawing" code you like within it.

Pluvius
  • 171
  • 6