精品导航

Displaying the code

Displaying the code

Now that we've got the needed code, it's time to use it in a program.

We've already shown that 'sprites.c' file that holds various icons' codes. Since all of those icons are declared as global constants, we're going to do the same thing here.
To do this next step, you have to open either CircuitBlocks or Arduino IDE. If you have setup Ringo library in any other text editor, that will do the trick as well.
This tutorial is going to be done inside CircuitBlocks, but the process itself is the same for Arduino.
First, open CircuitBlocks and start a new project.

When selecting a new sketch type press 'Code'



You need to select the 'Code' button since we're going to have to type a little bit here.

This process can't be done in a 'Block' project. What you can do is take your block project's code, copy it to the code project, and then add the finishing touches there.

Empty new 'Code' sketch



Now, let's copy our bitmap snippet as the global constant.

For that all we need to do is write the following line:


With our colors' hex codes being between the brackets.

That means that it would all look like this



The SIZE variable actually determines how many pixels are there. Since we have an icon that is 24x26, that would be a total of 624 pixels. If you convert that to hexadecimal (notice the '0x' before the number) it would translate to 270, which is the number we've got here.

The rest of our variable are just color codes for each specific pixel. If you look closely, you'll notice that the white color (0xffff) that colors our icon's outline, is on the "edges" of the code.
Now, all we need to do is print that little icon out.

Printing out our new snake icon



We've also added a little text so that the icon is not lonely on the screen!

Function 'mp.display.drawIcon()' has variables in this order: (imageFile, locationX, locationY, width, height, scale).
Pretty self-explanatory as it is, just like in the previous example.
Here is the full code:


See, it's not that hard!

Transparent bitmaps

What if we want to have an icon that is not a rectangle, but rather a circle or some other shape?

Well, since all icons are rectangles, that means that some pixels are going to have to be transparent.
The problem with bitmaps - they don't have a transparent channel. Luckily, you can just pick a color that will serve as a transparent one, so that each pixel with that color will not be shown.
In the function drawIcon(), you can also add a color parameter.


So for example, if we wanted to draw our snake icon without white color outlines, our function would look something like this:


On our screen now we have 24x26 snake icon located in the upper left corner of the screen, and of course, without white borders.

Now you can get to drawing and importing some more complex images to your new apps!

友情链接:汤姆影院 | 协和影院 | 蘑菇视频入口 | 在线亚洲 | rencai98.com | gzdksw.com | 蘑菇視頻 | 色妞 | 青草草 | zhuoyemall.com | 玖玖爱 | 六月婷婷 | 天天综合 | 欧美午夜 | mogu视频 | 小蓝视频 | 五月丁香 | 天堂在线 | 蘑菇影视 | 红桃视频 | 第一福利 | 青娱 | hebeijiaoyuwang.com | 龙物视频 | 久久视频 | 蘑菇视频网站 | 蘑菇视频ios | 福利盒子 | 蘑菇tv网页版 | mogutv | 秋霞网 | 午夜在线观看 | 玖玖资源站 | fltou.com | 小草社区 | tissu-premier.com | 五福影院 | 樱花视频 | 屁屁影院 | 宅男影院 | lf397.com | 秋霞影院 | 综合影院 | 蘑菇网 | 久久香蕉 | btupic.com | 色啪 | 最新av | 青草青青 | 伊人色 | 蘑菇在线观看网页版 | 看片神器 | bt搜索 | 老王影院 | 无名网 | 酒色世界 | mogu | 资源导航 | 永久地址 | 4008108885.com | 蘑菇网页版入口 | 青青伊人 | sanzhucare-zhpg.com | 蘑菇app | mogus.cc | 福利精品 | 日本高清 | 琳琅导航 | 番号网 | 永久网站 | 亚洲精品 | 四虎影视 | 蓝色导航 | 老司机视频 | dk99999.com | woqidz.com | 精品免费 | zpzb2008.com | jxty00.com | 亚洲网 | 琵琶妞 | 摩天轮社区 | 超碰视频 | tsxhyq.com | dna0126.com | 蘑菇传媒 | 在线午夜 | 性知音 | 导航大全 | p站视频 | 久久久久久 | 蜜芽视频 | 蘑菇短视频入口 | 扒哥黑料 | 迷妹网 | 草莓视 | 久久爱 | 蘑菇传媒在线观看 | 色婷婷