在学习了C++的基础知识后,我目前开始使用SFML.我已经了解了Arrays,References以及它之前的所有内容,但却努力掌握使用类的概念.
在SFML中,我创建了一个简单的sprite移动程序,但是,我想将这些信息移到一个类中(假设它将被称为"Player").我搞砸了很多但是我无法让它发挥作用.
我已经尝试在类中创建一个函数来检查播放器输入,但我无法访问我在main中创建的精灵.我想将与玩家相关的所有内容移到Player类中,但需要一些建议.
这样做的正确方法是什么?(请不要说回去学习课程,这是我想要了解的地方!)
main.cpp中
#include <SFML/Graphics.hpp>
#include <string>
#include <iostream>
int main()
{
//character position
enum Direction{ Down, Left, Right, Up };
sf::Vector2i source(1, Down);
//window
sf::RenderWindow window(sf::VideoMode(1200, 700), "Testing");
window.setKeyRepeatEnabled(false);
//player character
sf::Texture pTexture;
sf::Sprite pSprite;
if(!pTexture.loadFromFile("image/playerSprite.png"))
std::cout << "Texture Error" << std::endl;
pSprite.setTexture(pTexture);
pSprite.setScale(1.5f, 1.5f);
//game loop
while (window.isOpen())
{
sf::Event event;
while (window.pollEvent(event))
{
if (event.type == sf::Event::Closed)
window.close();
}
window.clear();
if (sf::Keyboard::isKeyPressed(sf::Keyboard::Up)) //move up
{
source.y = Up;
pSprite.move(0, -0.2);
//animation
source.x++;
if(source.x * 32 …Run Code Online (Sandbox Code Playgroud) 我有这样的数据框,称为df:
a b c d e f
b c f a a a
d f a b c c
f e d f f d
Run Code Online (Sandbox Code Playgroud)
第一行实际上是列名.让我们举个例子来解释这里的含义是:df[1,1]是b的,这意味着存在从关系a到b,所以在列中的值意味着从"列名",以该条目关系.
我想创建一个matrix(df1)6*6维,列和行名都是列名df.如果从"i"到"j"之间存在关系,则(i,j)条目为1,否则为0.
我想要的输出是:
a b c d e f
a 0 1 0 1 0 1
b 0 0 1 0 1 1
c 1 0 0 1 0 1
d 1 1 0 0 0 1
e 1 0 1 …Run Code Online (Sandbox Code Playgroud) 带花括号:
<div theBestProp={"diagonal-texture"}> ...
Run Code Online (Sandbox Code Playgroud)
vs不带花括号:
<div theBestProp="diagonal-texture"> ...
Run Code Online (Sandbox Code Playgroud)
同样的问题与“ ref”道具有关:
大括号(来自React的文档),可通过this._input访问:
<div ref={(c) => this._input = c} ...
Run Code Online (Sandbox Code Playgroud)
与没有大括号相比,可以通过this.refs.commander访问:
<div ref="commander"> ...
Run Code Online (Sandbox Code Playgroud)
我还注意到,所有内容都以字符串形式出现。为了这:
<PriceOption id="1" yes="true" price="free" audience="for individuals" plan="Starter" />
Run Code Online (Sandbox Code Playgroud)
道具将是这样(所有字符串):
{
"id": "1",
"yes": "true",
"price": "free",
"audience": "for individuals",
"plan": "Starter"
}
Run Code Online (Sandbox Code Playgroud)
因此,我认为传递布尔值和数字的唯一方法如下:
<PriceOption id={1} yes={true} price="free" audience="for individuals" plan="Starter" />
Run Code Online (Sandbox Code Playgroud)
对?
我正在尝试禁用地图集地图上的滚动缩放,但它无法正常工作.谁能告诉我我的代码有什么问题?我得到的错误是"Uncaught TypeError:无法读取属性'禁用'未定义"
<script>
L.mapbox.accessToken = 'pk.token';
var map = L.mapbox.map('map', 'mapbox.streets', {
legendControl: {
position: 'topright'
}
})
.setView([56.3, 11.5], 7);
var popup = new L.Popup({ autoPan: false });
// statesData comes from the 'us-states.js' script included above
var statesLayer = L.geoJson(statesData, {
style: getStyle,
onEachFeature: onEachFeature
}).addTo(map);
function getStyle(feature) {
return {
weight: 2,
opacity: 0.1,
color: 'black',
fillOpacity: 0.7,
fillColor: getColor(feature.properties.density)
};
}
// get color depending on population density value
function getColor(d) {
return d > 1000 …Run Code Online (Sandbox Code Playgroud) 我有一个对象:
person = {
birth_year: 1970,
first_name: "John",
last_name: "Doe",
occupation: "Doctor",
city: "Boston",
married: true
}
Run Code Online (Sandbox Code Playgroud)
我有一个按给定顺序排列的键名称数组:
keys = ["occupation", "last_name", "city"]
Run Code Online (Sandbox Code Playgroud)
我想得到这个数组:
["Doctor", "Doe", "Boston"]
Run Code Online (Sandbox Code Playgroud)
重要的是,答案应该保证顺序(JavaScript 不保证对象迭代的顺序)。
我认为 lodash/underscore 中可能有一些实用函数可以简单地完成此操作,但无法弄清楚。
我有一个自定义模块包装外部命令(csrun.exe),并解析输出,以便我可以在PowerShell中使用它.
除了外部命令写入stderror以及清除cmdlet中的错误之外,所有内容都可以正常工作.这将清除(即$error.count是0和$lasterrorcode是0,但一旦我回到那个是叫我的小命令的脚本,$error并$lasterrorcode不再清晰,错误$error引用的外部命令的底层异常
System.Management.Automation.RemoteException: The compute emulator is not running.
Run Code Online (Sandbox Code Playgroud)
我尝试过,尝试捕获,清除上述变量.无论如何,调用脚本保留对错误的引用.
$__azureEmulatorPath = "C:\Program Files\Microsoft SDKs\Azure\Emulator\"SDKs\Azure\Emulator\"
$__azureEmulator = __azureEmulatorPath + "csrun.exe"
function Get-EmulatorStatus() {
[OutputType([ComputeEmulatorStatus])]
[cmdletbinding()]
param()
$output = (& $__azureEmulator /status | Out-String)
if ($error.Count -gt 0 -or $LASTEXITCODE -ne 0) {
Write-Host ($Error | Format-List -Force | Out-String)
Write-Host Clearing Error and Continuing
$error.Clear()
$LASTEXITCODE = 0
}
#error from …Run Code Online (Sandbox Code Playgroud) 鉴于以下
var content = [{
"set_archived": false,
"something": [{
"id": "aa7bb3db-19a2-4ef6-5944-892edaaf53c3",
"modified": "2016-12-01T18:23:29.743333Z",
"created": "2016-12-01T18:23:29.743333Z",
"archived": false
}]
},
{
"set_archived": true,
"something": [{
"id": "aa7bb3db-19a2-4ef6-5944-892edaaf53c3",
"modified": "2017-01-30T19:42:29.743333Z",
"created": "2017-01-30T19:42:29.743333Z",
"archived": false
}]
}
];
Run Code Online (Sandbox Code Playgroud)
使用 Lodash,我如何确定对象数组中的一个set_archived或something.archived是否等于真?
所以在这种情况下,因为第二个对象set_is_archived是真的,那么预期的响应应该是真的。如果任一对象中的所有项目均为假,则响应应为假。
在 PHP 中,我有以下代码来创建目录中所有图像的数组。
$dir = '/public/images/';
$files = scandir($dir);
Run Code Online (Sandbox Code Playgroud)
NodeJS 的等价物是什么?
我正在寻找在目录中创建所有图像的数组。
在开发中的 Laravel webpack mix 中使用它,以便它可以通过命令行在本地计算机或服务器本身上运行。
而不是以下内容,因为目录中存在未知数量的图像以及名称。
if (mix.config.inProduction) {
mix.version(['public/images/50x50-1.png', 'public/images/50x50-1.svg'])
}
Run Code Online (Sandbox Code Playgroud)
所需代码:
if (mix.config.inProduction) {
var imagesArray = // get the list here
mix.version(imagesArray)
}
Run Code Online (Sandbox Code Playgroud) 我想通过比较数组中的前一个对象和当前对象来减少对象数组,如果前一个对象的ID与当前对象不同,那么我将前一个对象写入结果列表并用当前对象覆盖它,否则我求和两个对象的值。最后,它应该是精简数组,没有重复。
我有这样的数据:
[{
Clicks: 210,
Company: "A",
_id: { CompanyID: 5 }
},
{
Clicks: 35,
Company: "C",
_id: { CompanyID: 3 }
},
{
Clicks: 15,
Company: "B",
_id: { CompanyID: 2 }
},
{
Clicks: 13,
Company: "A",
_id: { CompanyID: 5 }
}]
Run Code Online (Sandbox Code Playgroud)
并希望将其简化为以下形式:
[{
Clicks: 223,
Company: "A",
_id: { CompanyID: 5 }
},
{
Clicks: 35,
Company: "C",
_id: { CompanyID: 3 }
},
{
Clicks: 15,
Company: "B",
_id: { CompanyID: 2 }
}] …Run Code Online (Sandbox Code Playgroud)