Skip to content

Commit 23ed8e1

Browse files
author
Arcadio Garcia Salvadores
committed
Keyboard package post
1 parent 64cdbd4 commit 23ed8e1

File tree

4 files changed

+87
-10
lines changed

4 files changed

+87
-10
lines changed

_layouts/post.html

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -4,23 +4,23 @@
44
{% assign author = site.data.authors[page.author] %}
55
<article class="post" itemscope itemtype="http://schema.org/BlogPosting">
66

7-
<header class="post-header">
8-
<h1 class="post-title" itemprop="name headline">{{ page.title }}</h1>
9-
<p class="post-meta">
10-
<time datetime="{{ page.date | date_to_xmlschema }}" itemprop="datePublished">{{ page.date | date: "%b %-d, %Y" }}</time>{% if page.author %}
11-
<span itemprop="author" itemscope itemtype="http://schema.org/Person"><img src="{{ author.pic }}" style="height:40px;border-radius:20px;margin-left:30px;"/> <a href="{{ site.baseurl }}/authors#{{ author.name }}"><span itemprop="name">{{ author.name }}</span></a> (<a href="http://twitter.com/{{ author.twitter }}">@{{ author.twitter }}</a>)</span>{%
12-
endif %}</p>
7+
<header class="post-header-pretty" style="background-image:url('{{ site.baseurl }}{{ page.heropic }}');">
8+
<div class="post-header-content">
9+
<h1 class="post-title" itemprop="name headline">{{ page.title }}</h1>
10+
<p class="post-meta">
11+
<time datetime="{{ page.date | date_to_xmlschema }}" itemprop="datePublished">{{ page.date | date: "%b %-d, %Y" }}</time>{% if page.author %}
12+
<span itemprop="author" itemscope itemtype="http://schema.org/Person"><img src="{{ author.pic }}" style="height:40px;border-radius:20px;margin-left:30px;"/> <a href="{{ site.baseurl }}/authors#{{ author.name }}"><span itemprop="name">{{ author.name }}</span></a>
13+
(<a href="http://twitter.com/{{ author.twitter }}">@{{ author.twitter }}</a>)</span>{% endif %}</p>
14+
</div>
1315
</header>
1416

1517
<div class="post-content" itemprop="articleBody">
1618
{{ content }}
1719
</div>
1820

1921
<div class="categories">
20-
Tags:
21-
{% for category in page.categories %}
22-
<a href="{{ site.baseurl }}/tags#{{ category }}"> {{ category }} </a>
23-
{% endfor %}
22+
Tags: {% for category in page.categories %}
23+
<a href="{{ site.baseurl }}/tags#{{ category }}"> {{ category }} </a> {% endfor %}
2424
</div>
2525

2626
</article>

_posts/2017-6-10-keyboard.md

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
---
2+
layout: post
3+
title: "The keyboard package"
4+
date: 2017-6-10 19:45:11 +0200
5+
author: arcadio
6+
categories: keyboard packages
7+
heropic: /pictures/keyboard.jpg
8+
---
9+
10+
The keyboard is one of the most popular input methods in PC games, and thanks to the `keyboard` package it is really easy to incorporate it into your game.
11+
12+
First of all, you will need to add the package as a dependency to your game. You can do it using the command line `clockwork-tools`, opening a command line in your project folder and typing
13+
14+
`clockwork add keyboard`
15+
16+
Once you have added the dependency, you just need to spawn a `keyboard` object in any level you want to depect keyboard input. Add it to the level like this:
17+
18+
{% highlight xml %}
19+
<object name="keyboard" type="keyboard" x="0" y="0" ></object>
20+
{% endhighlight %}
21+
22+
and you will be ready to start detecting keyboard input!
23+
24+
The `keyboard` object you just created will trigger two events, `keyboardDown` and `keyboardUp`, that you can listen to in order to find out when a key is pressed or released. For example, this would be a component that will move right when a certain key is pressed, and move left when another one is released:
25+
26+
{% highlight js %}
27+
{
28+
name: "someObject",
29+
events: [
30+
{
31+
name: "keyboardDown", code: function (event) {
32+
if(event.key==65){ // 'A' is pressed
33+
this.var.$x++;
34+
}
35+
}
36+
},
37+
{
38+
name: "keyboardUp", code: function (event) {
39+
if(event.key==66){ // 'B' is released
40+
this.var.$x--;
41+
}
42+
}
43+
}
44+
]
45+
}
46+
{% endhighlight %}
47+
48+
Just like that, you can add your own logic to detect keyboard input and act acordingly.
49+
50+
The key code corresponding to each key is the standard one reported by the browser, [here you can find a list of the most key codes](https://gist.github.com/arcadiogarcia/e477a424eb9a4355724fdfed8ad7469b), or you could just log them (via `this.engine.debug.log(event.key)`) and find out the numbers for the keys you are interested in.
51+
52+
Finally, remember that if you need to remember something about how the component is used, you can quickly access the package documentation from Visual Studio Code, running the `Browse Clockwork package documentation` command.

_sass/_base.scss

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -272,4 +272,29 @@ pre {
272272
opacity:1;
273273
margin-left:0px;
274274
}
275+
}
276+
277+
.post-header-pretty{
278+
background: black;
279+
background-size:cover;
280+
background-position: center;
281+
}
282+
283+
.post-header-content{
284+
padding:50px;
285+
background: rgba(0,0,0,0.5);
286+
}
287+
288+
.post-header-pretty .post-title{
289+
color:white;
290+
}
291+
292+
.post-header-pretty a{
293+
color: cornflowerblue;
294+
padding: 0px 4px 0px 4px;
295+
background: rgba(0,0,0,0.5);
296+
}
297+
298+
.post-header-pretty .post-meta{
299+
color:white;
275300
}

pictures/keyboard.jpg

79.2 KB
Loading

0 commit comments

Comments
 (0)