有没有办法在捕获ios设备屏幕时捕获CAEmitterCells(使用CAEmitterLayer生成)?
UIGetScreenImage()有效,但由于它是私有方法,我不允许使用它.
UIGraphicsBeginImageContext似乎不起作用,从结果图像中简单地省略了粒子.
编辑:
这是我目前用于捕获视图的代码.我实际上正在使用aroth在这里提供的代码录制一个30秒长的屏幕视频.它的工作原理是每秒记录25个自身的图像(它的UIView子类)及其子视图(在我们的例子中包括UIView,其层是CAEmitterLayer),并使用AVAssetWriter来组成记录.
这是非常令人满意的,所以我只是将相关的行放在这里:我在XCode中使用ARC工具对代码进行ARC编辑,因此代码可能与内存管理有点不同.
- (CGContextRef) createBitmapContextOfSize:(CGSize) size {
CGContextRef context = NULL;
CGColorSpaceRef colorSpace;
int bitmapByteCount;
int bitmapBytesPerRow;
bitmapBytesPerRow = (size.width * 4);
bitmapByteCount = (bitmapBytesPerRow * size.height);
colorSpace = CGColorSpaceCreateDeviceRGB();
if (bitmapData != NULL) {
free(bitmapData);
}
bitmapData = malloc( bitmapByteCount );
if (bitmapData == NULL) {
fprintf (stderr, "Memory not allocated!");
return NULL;
}
context = CGBitmapContextCreate (bitmapData,
size.width,
size.height,
8, // bits per component
bitmapBytesPerRow,
colorSpace,
kCGImageAlphaNoneSkipFirst);
CGContextSetAllowsAntialiasing(context,NO);
if (context== …Run Code Online (Sandbox Code Playgroud) 我目前正在研究一个高效的计算引擎,用于 CPU 和 GPU 中的粒子模拟。我最近一直在研究八叉树,我成功地为空间中的粒子编写了八叉树的工作版本,并且还有效地处理了它们的碰撞。现在我必须在我的八叉树中插入三角形网格(STL 对象),以便我也可以处理粒子和对象三角形之间的碰撞。我很困惑如何以有效的方式将三角形插入到已经创建的八叉树中?请提出实现这一目标的方法。如果这有帮助,我正在使用 C++。已经谢谢了。
我正在创建一个Web应用程序,它具有交互式背景,粒子在弹跳.在任何时候屏幕上都有大约200个圆形颗粒,最多约800个颗粒.正在为粒子运行的一些碰撞和效果是以下原型.我想知道我是否可以通过使用网络工作人员来进行这些计算来提高性能?
/**
* Particles
*/
Jarvis.prototype.genForegroundParticles = function(options, count){
count = count || this.logoParticlesNum;
for (var i = 0; i < count; i++) {
this.logoParticles.push(new Particle());
}
}
Jarvis.prototype.genBackgroundParticles = function(options, count){
count = count || this.backgroundParticlesNum;
for (var i = 0; i < count; i++) {
this.backgroundParticles.push(new Particle(options));
}
}
Jarvis.prototype.motion = {
linear : function(particle, pIndex, particles){
particle.x += particle.vx
particle.y += particle.vy
},
normalizeVelocity : function(particle, pIndex, particles){
if (particle.vx - particle.vxInitial > 1) {
particle.vx -= …Run Code Online (Sandbox Code Playgroud) 在我的游戏中我使用
static final float FRUSTUM_WIDTH = 10;
static final float FRUSTUM_HEIGHT = 15;
Run Code Online (Sandbox Code Playgroud)
因此,当我绘制粒子时,它们占据整个屏幕并且非常大!那么我该如何缩小它们以满足我的需求呢?
//皮尤实验室
我正在使用SpriteKit的粒子发射器系统在背景中构建一个移动的星形场,其中玩家的船位于屏幕的中心.
当玩家触摸屏幕的某个区域时,我会计算角度并为玩家精灵转动该方向设置动画.
但是,当我将它应用于星形场时,星形场的整个矩形都会旋转.然而,我想要的是,单个粒子只是开始向新方向移动.
这是将整张纸与整个点旋转并且仅使点移动到新角度之间的区别.那有意义吗?
这就是我到目前为止玩家正确旋转但星球场"像一整张纸一样旋转"的情况:
-(void)touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event {
// Choose one of the touches to work with
UITouch *touch = [touches anyObject];
CGPoint location = [touch locationInNode:self];
CGPoint center = CGPointMake(CGRectGetMidX(self.frame), CGRectGetMidY(self.frame));
CGPoint offset = rwSub(location, center);
SKEmitterNode *starfield = (SKEmitterNode *)[self childNodeWithName:@"starfield"];
SKSpriteNode *player = (SKSpriteNode *)[self childNodeWithName:@"player"];
SKAction *rotateNode = [SKAction rotateToAngle: (CGFloat)atan2(offset.y, offset.x) duration:0.5 shortestUnitArc:TRUE];
[player runAction: rotateNode];
SKAction *rotateStarfieldNode = [SKAction rotateToAngle: (CGFloat)(atan2(offset.y, offset.x) - M_PI_2) duration:0.5 shortestUnitArc:TRUE];
[starfield runAction: rotateStarfieldNode];
}
Run Code Online (Sandbox Code Playgroud) 所以我慢慢地知道如何通过代码在游戏中操纵粒子系统和发射器,但有一个简单的任务我无法知道如何...当我按住鼠标按钮时,我怎么能产生粒子?当没有按下时,我尝试通过将发射器的maxCount设置为0来解决这个问题,但是它根本不会发射粒子,或者只是使现有的发射器立即消失,这看起来非常不自然,我不想要它.有没有办法在渲染方法中"手动"发出它们?
我有火焰ParticleEffect作为火箭的尾气。虽然火箭移动缓慢,但火焰看起来不错,但是当火箭开始快速移动时,火焰无法真正跟上,因为它的粒子速度是相对于世界而不是火箭而言的。结果是在几秒钟内从屏幕上消失的光点。
我可以在运行时更新发射器速度,还是可以设置某种粒子效果的速度参考点(也在运行时)?
谢谢你的帮助!
在我的控制台我得到的错误:"遗漏的类型错误:不能为空的读取属性'的getContext’"我只是找不到我做了错误......或者我做了什么错.那么也许你可以帮我找到它?请帮忙 :)
enter code here
var canvas = document.getElementById("myCanvas");
var ctx = canvas.getContext("2d");
var cW = canvas.width = 1000;
var cH = canvas.height = 500;
var particleAmount = 10;
var particles = [];
for(var i=0;i<particleAmount;i++) {
particles.push(new particle());
}
function particle() {
this.x = (Math.random() * (cW-(40*2))) + 40;
this.y = (Math.random() * (cH-(40*2))) + 40;
this.xv = Math.random()*20-10;
this.yv = Math.random()*20-10;
}
function draw () {
ctx.fillStyle = "black";
ctx.fillRect(0,0,cW,cH);
for(var ii=0;ii<particles.length;ii++){
var p = particles[ii];
ctx.fillStyle = "red"; …Run Code Online (Sandbox Code Playgroud) 我不知道为什么会出现这个 javascript 错误。很难弄清楚这一点。
这是我的 main.js:
jQuery( document ).ready( function( $ ) {
/*
PARTICLES
-------------------*/
particlesJS("particles-js", {
"particles": {
"number": {
"value": 80,
"density": {
"enable": true,
"value_area": 800
}
},
"color": {
"value": "#823a09"
},
"shape": {
"type": "circle",
"stroke": {
"width": 0,
"color": "#000000"
},
"polygon": {
"nb_sides": 5
},
"image": {
"src": "img/github.svg",
"width": 100,
"height": 100
}
},
"opacity": {
"value": 0.5,
"random": false,
"anim": {
"enable": false,
"speed": 1,
"opacity_min": 0.1,
"sync": false
}
}, …Run Code Online (Sandbox Code Playgroud) 我正在尝试制作一个脚本,以便在按下按钮时粒子系统会更改为某种颜色,除了更改粒子颜色之外,它一切正常,当我尝试时会出现以下错误:
NullReferenceException:不要创建自己的模块实例,而是从 ParticleSystem 实例获取它们
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class Attack : MonoBehaviour
{
public int MovementDirection = 0;
public int State = 0;
public GameObject attackOrb; //The prefab for our attack hitbox
public Transform Player; //Where the player is
public float R = 0.0F;
public float G = 0.0F;
public float B = 0.0F;
public float A = 1.0F;
private ParticleSystem attackEffect;
// Start is called before the first frame update
void Start()
{
attackEffect = gameObject.GetComponent<ParticleSystem>(); …Run Code Online (Sandbox Code Playgroud) particles ×10
javascript ×3
libgdx ×3
ios ×2
java ×2
android ×1
c# ×1
c++ ×1
collision ×1
html5 ×1
html5-canvas ×1
iphone ×1
objective-c ×1
octree ×1
performance ×1
sprite-kit ×1
system ×1
velocity ×1