≡
Products
▼
Support
▼
Company
▼
Forum
Ambiera Forum
Discussions, Help and Support.
Create a new account
,
Search
, or Login:
Create reply in
question about frame rate drop
Posted by:
(you are not logged in)
Enter the missing letter in: "Internationa?"
(you are not logged in)
Text:
[quote][b]tim12345[/b] wrote: Update: Ohhhkaaay I have found a solution! It was very simple! I learned it by studying other coppercube .js files. Maybe nobody will find this useful, but I will share it anyways! In order to move an object manually through the 'every few seconds' command independent of frames... I first created a behavior .js file with this code and put it in the extensions folder: [code]/* <behavior jsname="behavior_DeclareDeltaTime" description="Declare Delta Time"> < </behavior> */ behavior_DeclareDeltaTime = function() { this.LastTime = null; }; behavior_DeclareDeltaTime.prototype.onAnimate = function(node, timeMs) { var node1 = this.NodeToScale; if (this.LastTime == null) { this.LastTime = timeMs; return false; } var delta = timeMs - this.LastTime; this.LastTime = timeMs; if (delta > 200) delta = 200; ccbSetCopperCubeVariable("delta", delta) return true; }; [/code] This creates a new coppercube behavior in the editor. Now I apply this to any object in the scene (doesn't matter which one) and all it does is calculate the delta value and send it off to a coppercube variable called "delta". [img]http://www.timiscool.net/fr4.png[/img] Then what I did was create an action .js file with this code and put it in the extensions folder: [code]/* <action jsname="action_MovePositionByDelta" description="Move Position by Delta"> <property name="NodeToMove" type="scenenode" /> <property name="SpeedX" type="float" default="0" /> <property name="SpeedY" type="float" default="0.06" /> <property name="SpeedZ" type="float" default="0" /> </action> */ action_MovePositionByDelta = function() { }; action_MovePositionByDelta.prototype.execute = function(NodeToMove) { var delta = ccbGetCopperCubeVariable("delta"); var oldPos = ccbGetSceneNodeProperty(this.NodeToMove, "Position"); newXspeed = this.SpeedX*delta; newYspeed = this.SpeedY*delta; newZspeed = this.SpeedZ*delta; vecMove=new vector3d(newXspeed, newYspeed, newZspeed); newPos=oldPos.add(vecMove); ccbSetSceneNodeProperty(this.NodeToMove,"Position",newPos); } ; [/code] And what this does is calculates a frame independent speed using the delta coppercube variable... Now there is a new action which looks like this... [img]http://www.timiscool.net/fr5.png[/img] Here we can choose an object to move and enter a speed value for xyx coordinates. The speed value should be very small... something like 0.06. Alternatively, you can just use javascript to do this using basically the same code. So now if I have a cube that moves in a certain direction every 1 ms either through javascript or with the new coppercube action, running at 40 frames per second like this... [img]http://www.timiscool.net/fr6.png[/img] And I use a 'do later' action to stop the movement after 1500ms. We then get a result like this. [img]http://www.timiscool.net/fr7.png[/img] And let's say say so much stuff is happening in your game, that the frame rate drops down to a measly 10 frames per second... well... now we get this result!! [img]http://www.timiscool.net/fr8.png[/img] Problem solved! Very simple! Maybe there is a simpler way, but I will use this method for the time being. Now if you'll excuse me! I have to make some repairs to my game...[/quote]
Possible Codes
Feature
Code
Link
[url] www.example.com [/url]
Bold
[b]bold text[/b]
Image
[img]http://www.example.com/image.jpg[/img]
Quote
[quote]quoted text[/quote]
Code
[code]source code[/code]
Emoticons
Copyright© Ambiera e.U. all rights reserved.
Privacy Policy | Terms and Conditions | Imprint | Contact