精品导航

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!

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