![]() If you stop and think about it, this approach makes a great deal of sense. On the other hand OpenGL and most mathematicians treat the bottom left corner of the screen as the origin. It is also most common for graphics files to store their image data starting from the top left pixel, but by no means is this universal. It is common for UI systems, the most famous of which being Windows, to set the origin at the top left of the screen. There are two major approaches to dealing with locations in 2D, having the location (0,0) at the top left of the screen and having the location (0,0) at the bottom left of the screen. One of the most confusing things when working in 2D graphics is dealing with all the various coordinate systems. There are two things we can take away from the results.ġ- The position (0,0) is at the bottom left corner of the screen.Ģ- By default, the position of a sprite is relative to it’s own center point. This is telling the sprite to position itself at the pixel location (0,0). ![]() So, what exactly is happening here? Well after we created our sprite we called: sprite->setPosition(0, 0) Hmmm, probably not exactly what you expected to happen, but hey, congratulations, you just rendered your first sprite! GraphicsScene.cpp #include "GraphicsScene.h"Īuto sprite = Sprite::create("decepticon.png") Just be certain to add the image to the resources directory of your project.Ĭlass GraphicsScene : public cocos2d::Layer Of course you can use whatever image you want. It’s 400×360, with a transparent background named decepticon.png. Personally I am going to use this somewhat… familiar image: First we are going to need an image to draw. Ok, let’s jump right in with with a simple example. The only changes you should have to make are to change your delegate to #include a different file and change the type of scene you call createScene() on. I am going to assume you have a working AppDelegate, so I will only focus on creating a new scene object. This tutorial assumes you ran through the prior part and created a project already. Now that we have Cocos2d-x installed and configured and our project created, we are going to take a look at basic graphics operations.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |