diff options
author | chai <chaifix@163.com> | 2018-12-07 14:29:50 +0800 |
---|---|---|
committer | chai <chaifix@163.com> | 2018-12-07 14:29:50 +0800 |
commit | 354507a4970874bf658ac00fb5d2388c46332fd3 (patch) | |
tree | 6c42a0f20d392927964c0ac512de5963e15618d6 | |
parent | ec6920656d8225538baaac677b62aa564fc1055e (diff) |
*particle system
-rw-r--r-- | bin/SDL2.dll | bin | 1242112 -> 771072 bytes | |||
-rw-r--r-- | bin/game/dust/s_dust_A_0.png | bin | 0 -> 82 bytes | |||
-rw-r--r-- | bin/game/dust/s_dust_A_1.png | bin | 0 -> 93 bytes | |||
-rw-r--r-- | bin/game/dust/s_dust_A_10.png | bin | 0 -> 84 bytes | |||
-rw-r--r-- | bin/game/dust/s_dust_A_2.png | bin | 0 -> 94 bytes | |||
-rw-r--r-- | bin/game/dust/s_dust_A_3.png | bin | 0 -> 95 bytes | |||
-rw-r--r-- | bin/game/dust/s_dust_A_4.png | bin | 0 -> 76 bytes | |||
-rw-r--r-- | bin/game/dust/s_dust_A_5.png | bin | 0 -> 88 bytes | |||
-rw-r--r-- | bin/game/dust/s_dust_A_6.png | bin | 0 -> 87 bytes | |||
-rw-r--r-- | bin/game/dust/s_dust_A_7.png | bin | 0 -> 84 bytes | |||
-rw-r--r-- | bin/game/dust/s_dust_A_8.png | bin | 0 -> 86 bytes | |||
-rw-r--r-- | bin/game/dust/s_dust_A_9.png | bin | 0 -> 83 bytes | |||
-rw-r--r-- | bin/game/main.lua | 42 | ||||
-rw-r--r-- | bin/jin.exe | bin | 1703424 -> 554496 bytes | |||
-rw-r--r-- | bin/lua51.dll | bin | 364544 -> 364544 bytes | |||
-rw-r--r-- | src/libjin/graphics/particles/je_particle.cpp | 6 | ||||
-rw-r--r-- | src/lua/modules/graphics/je_lua_graphics.cpp | 26 |
17 files changed, 41 insertions, 33 deletions
diff --git a/bin/SDL2.dll b/bin/SDL2.dll Binary files differindex 47c1b1e..3f6f1d5 100644 --- a/bin/SDL2.dll +++ b/bin/SDL2.dll diff --git a/bin/game/dust/s_dust_A_0.png b/bin/game/dust/s_dust_A_0.png Binary files differnew file mode 100644 index 0000000..79efc70 --- /dev/null +++ b/bin/game/dust/s_dust_A_0.png diff --git a/bin/game/dust/s_dust_A_1.png b/bin/game/dust/s_dust_A_1.png Binary files differnew file mode 100644 index 0000000..acc2100 --- /dev/null +++ b/bin/game/dust/s_dust_A_1.png diff --git a/bin/game/dust/s_dust_A_10.png b/bin/game/dust/s_dust_A_10.png Binary files differnew file mode 100644 index 0000000..e422644 --- /dev/null +++ b/bin/game/dust/s_dust_A_10.png diff --git a/bin/game/dust/s_dust_A_2.png b/bin/game/dust/s_dust_A_2.png Binary files differnew file mode 100644 index 0000000..1ef2056 --- /dev/null +++ b/bin/game/dust/s_dust_A_2.png diff --git a/bin/game/dust/s_dust_A_3.png b/bin/game/dust/s_dust_A_3.png Binary files differnew file mode 100644 index 0000000..ca2260a --- /dev/null +++ b/bin/game/dust/s_dust_A_3.png diff --git a/bin/game/dust/s_dust_A_4.png b/bin/game/dust/s_dust_A_4.png Binary files differnew file mode 100644 index 0000000..1f67b79 --- /dev/null +++ b/bin/game/dust/s_dust_A_4.png diff --git a/bin/game/dust/s_dust_A_5.png b/bin/game/dust/s_dust_A_5.png Binary files differnew file mode 100644 index 0000000..3969a04 --- /dev/null +++ b/bin/game/dust/s_dust_A_5.png diff --git a/bin/game/dust/s_dust_A_6.png b/bin/game/dust/s_dust_A_6.png Binary files differnew file mode 100644 index 0000000..d2d6df0 --- /dev/null +++ b/bin/game/dust/s_dust_A_6.png diff --git a/bin/game/dust/s_dust_A_7.png b/bin/game/dust/s_dust_A_7.png Binary files differnew file mode 100644 index 0000000..02ba310 --- /dev/null +++ b/bin/game/dust/s_dust_A_7.png diff --git a/bin/game/dust/s_dust_A_8.png b/bin/game/dust/s_dust_A_8.png Binary files differnew file mode 100644 index 0000000..700052c --- /dev/null +++ b/bin/game/dust/s_dust_A_8.png diff --git a/bin/game/dust/s_dust_A_9.png b/bin/game/dust/s_dust_A_9.png Binary files differnew file mode 100644 index 0000000..8de4fcf --- /dev/null +++ b/bin/game/dust/s_dust_A_9.png diff --git a/bin/game/main.lua b/bin/game/main.lua index 8de71f1..3e5182b 100644 --- a/bin/game/main.lua +++ b/bin/game/main.lua @@ -61,6 +61,7 @@ local function createAnimation(path, count, r, c, w, h, loop, speed) local sprs = ssheet:newSprites(count, r, c, w, h, 96, 168) return jin.graphics.newAnimation(sprs, loop, speed) end +local particle_sprites = {} local Pi = 3.1415 function jin.core.onLoad() -- bitmap = jin.graphics.newBitmap(200, 200, function(w, h, x, y) @@ -69,22 +70,25 @@ function jin.core.onLoad() local tex = jin.graphics.newTexture("particle.png") particle_sprite = jin.graphics.newSprite(tex, jin.graphics.SpriteOrigin.MIDDLECENTER) ps = jin.graphics.newParticleSystem() - - ps:setEmitRate(0.02); - ps:setEmitForce(80, 120); - ps:setEmitPosition({50, 50}); - ps:setEmitDirection(-Pi / 10 - Pi / 2, Pi / 10 - Pi / 2); - ps:setParticleLinearAccelaration({0, 10}); - ps:setParticleSpritesMode(jin.graphics.SpriteMode.SINGLE); - ps:setParticleColor({255, 30, 0, 255}); - ps:addParticleTransparencyPoint(1, 0); - ps:addParticleTransparencyPoint(0, 0.5); - ps:enableParticleBlendAdditive(true); - ps:setParticleLife(0.5, 2); - ps:addParticleScalePoint(3, 0); - ps:addParticleScalePoint(0, 1); - ps:addParticleSprite(particle_sprite) - + for i = 0, 10 do + local t = jin.graphics.newTexture("dust/s_dust_A_" .. i .. ".png") + local spr = jin.graphics.newSprite(t, jin.graphics.SpriteOrigin.MIDDLECENTER) + ps:addParticleSprite(spr) + end + ps:setEmitRate(0.02) + ps:setEmitForce(80, 120) + ps:setEmitPosition({0, 0}) + ps:setEmitDirection(-Pi / 10 - Pi / 2, Pi / 10 - Pi / 2) + ps:setParticleLinearAccelaration({0, 10}) + ps:setParticleSpritesMode(jin.graphics.SpriteMode.ANIMATED) + ps:setParticleColor({255, 30, 0, 255}) + ps:addParticleTransparencyPoint(1, 0) + ps:addParticleTransparencyPoint(0, 0.5) + ps:enableParticleBlendAdditive(true) + ps:setParticleLife(0.5, 2) + ps:addParticleScalePoint(3, 0) + ps:addParticleScalePoint(0, 1) + --ps:addParticleSprite(particle_sprite) shader_program = jin.graphics.newShader(shader) shader_program2 = jin.graphics.newShader(shader2) local animation = createAnimation("anim2.png", 27, 3, 10, 200, 200, true, 50) @@ -95,7 +99,7 @@ function jin.core.onLoad() -- music = jin.audio.newSource("forest.ogg") -- music:setVolume(0.5) -- music:setLoop(true) - --music:play() + -- music:play() jin.graphics.clear() jin.graphics.showWindow() timer = jin.time.newTimer() @@ -124,6 +128,8 @@ function jin.core.onUpdate(dt) animator:update(jin.time.getDelta()) timer:update(jin.time.getDelta()) ps:update(dt) + local mx, my = jin.mouse.getPosition() + ps:setPosition(mx, my) end function jin.core.onDraw() @@ -134,7 +140,7 @@ function jin.core.onDraw() jin.graphics.unuseShader() --jin.graphics.draw(sprs[2], 150, 150, 1, 1, 0) local x, y = jin.mouse.getPosition() - animator:render(x, y, 1, 1, 0) + animator:render(50, 150, 1, 1, 0) ps:render() --jin.graphics.print(#sprs, 10, 10) jin.graphics.draw(spr, 100, 200, 1, 1, 0) diff --git a/bin/jin.exe b/bin/jin.exe Binary files differindex fffa828..0bd7bc7 100644 --- a/bin/jin.exe +++ b/bin/jin.exe diff --git a/bin/lua51.dll b/bin/lua51.dll Binary files differindex 4857c1e..175f5c1 100644 --- a/bin/lua51.dll +++ b/bin/lua51.dll diff --git a/src/libjin/graphics/particles/je_particle.cpp b/src/libjin/graphics/particles/je_particle.cpp index fc3dc54..71c0426 100644 --- a/src/libjin/graphics/particles/je_particle.cpp +++ b/src/libjin/graphics/particles/je_particle.cpp @@ -125,6 +125,10 @@ namespace JinEngine void Particle::update(float dt) { + life += dt; + alive = life < lifeTime; + if (!alive) + return; float t = life / lifeTime; if ((updateFlags & UPDATE_COLOR) != 0) color = def->colorDef.overTime.value.getColor(t); @@ -159,8 +163,6 @@ namespace JinEngine spriteIndex = lerp<int>(0, n - 1, t); //jin_log_info("sprite index %d", spriteIndex); } - life += dt; - alive = life < lifeTime; } void Particle::render() diff --git a/src/lua/modules/graphics/je_lua_graphics.cpp b/src/lua/modules/graphics/je_lua_graphics.cpp index ea9a265..c6e6e13 100644 --- a/src/lua/modules/graphics/je_lua_graphics.cpp +++ b/src/lua/modules/graphics/je_lua_graphics.cpp @@ -56,13 +56,13 @@ namespace JinEngine Window* wnd = Window::get(); Window::Setting setting; - setting.width = luax_getfieldinteger(L, 1, "width"); - setting.height = luax_getfieldinteger(L, 1, "height"); - setting.title = luax_getfieldstring(L, 1, "title"); - setting.icon = luax_getfieldstring(L, 1, "icon"); - setting.vsync = luax_getfieldbool(L, 1, "vsync"); - setting.fullscreen = luax_getfieldbool(L, 1, "fullscreen"); - setting.resizable = luax_getfieldbool(L, 1, "resizable"); + setting.width = luax_getfieldinteger(L, 1, "width"); + setting.height = luax_getfieldinteger(L, 1, "height"); + setting.title = luax_getfieldstring(L, 1, "title"); + setting.icon = luax_getfieldstring(L, 1, "icon"); + setting.vsync = luax_getfieldbool(L, 1, "vsync"); + setting.fullscreen = luax_getfieldbool(L, 1, "fullscreen"); + setting.resizable = luax_getfieldbool(L, 1, "resizable"); context.initialized = wnd->start(&setting); if (!context.initialized) { @@ -994,7 +994,7 @@ namespace JinEngine { "destroy", l_destroy }, { "hideWindow", l_hideWindow }, { "showWindow", l_showWindow }, - /* creators */ + /* creators */ { "newBitmap", l_newBitmap }, { "newTexture", l_newTexture }, { "newShader", l_newShader }, @@ -1017,22 +1017,22 @@ namespace JinEngine { "setColor", l_setColor }, { "getColor", l_getColor }, { "present", l_present }, - /* canvas */ + /* canvas */ { "bindCanvas", l_bindCanvas }, { "unbindCanvas", l_unbindCanvas }, - /* shader */ + /* shader */ { "useShader", l_useShader }, - /* shapes */ + /* shapes */ { "point", l_point }, { "line", l_line }, { "rect", l_rect }, { "circle", l_circle }, { "triangle", l_triangle }, { "polygon", l_polygon }, - /* font */ + /* font */ { "setFont", l_setFont }, { "unsetFont", l_unsetFont }, - /* transform */ + /* transform */ { "pushMatrix", l_pushMatrix }, { "clearMatrix", l_clearMatrix }, { "popMatrix", l_popMatrix }, |