Following on from this question:
How should I go about animating over 200 images in iOS?
i'd like to know how to use a texture atlas in Xcode, but not with cocos2d. Too much of the project is already completed for me to port it over to cocos2d now. This will also be the only animation with this number of images.
The only tutorials out there seem to involve cocos2d or corona. I've downloaded Zwoptex and have packed all my sprites but, even then, i'm not sure if i should be trimming them, allowing rotation, giving them padding or even how i handle my retina images.
I've been looking at this link: http://mysterycoconut.com/blog/2011/01/cag1/ as recommended to me from my last question but it seems to gloss over many parts that i'm struggling with.
I'd really appreciate any help with this.
The texture atlas is designed to run with Cocos2D, there is a lot of dependencies with the other components. So I don't think that's a good choice for you.
The tutorial you posted is good otherwise. It could be most easy to use, but it gives a very good entry point. The main parts of this code are the - display and the - (void)displayLayer: methods:
The display method is call when the layer needs to its content. The animation will call (indirectly) the display method and here we call the displayLayer which will change the image to display (I hope I've been clear :!).
Here how you can refactor the display method if you want use a zwooptex file (or other) with non fixed size:
// Implement displayLayer: on the delegate to override how sample rectangles are calculated; remember to use currentSampleIndex, ignore sampleIndex == 0, and set the layer's bounds
- (void)display;
{
static const CGRect sampleRects[11] = {
{ 0, 0, 38, 47 }, // run
{ 0, 47, 46, 47 },
{ 82, 0, 40, 47 },
{ 122, 0, 30, 47 },
{ 152, 0, 36, 47 },
{ 38, 0, 44, 47 },
{ 188, 0, 42, 47 },
{ 230, 0, 26, 47 },
{ 46, 47, 28, 47 },
{ 74, 47, 28, 47 },
{ 102, 47, 28, 47 },
};
unsigned int idx = [self currentSampleIndex];
if (idx == 0)
return;
self.bounds = CGRectMake(0, 0, sampleRects[idx-1].size.width, sampleRects[idx-1].size.height);
self.contentsRect = CGRectMake(sampleRects[idx-1].origin.x/256.0f, sampleRects[idx-1].origin.y/128.0f, sampleRects[idx-1].size.width/256.0f, sampleRects[idx-1].size.height/128.0f);
}
#end
If you have any question, don't hesitate. ;)
Related
I'm developing wheel of fortune where I want the wheel to iterate four times while spinning, and stop to a particularly given value. All I want is to spin the wheel four times and stop to a particular slice. I'm thinking below code can work my idea.
Animated.loop(
Animated.timing(this._angle, {
toValue: 920,
duration: 5000,
}),//.start();
{
iterations: 1
}
).start();
I'm using angle as value. My formula to get the 'toValue' is "targetAngle * 4". This works but I want to decelerate the spinning in its last iterate just like Animated.decay() does. Is there any better idea to resolve this issue?
you can do
const onPress = () => {
Animated.timing(RotateAnimeted, {
toValue: 6,
duration: 1000,
}).start();
};
const Rotate = RotateAnimeted.interpolate({
inputRange: [0, 1, 2, 3, 4, 5, 6],
outputRange: [
"0deg",
"360deg",
"720deg",
"840deg",
"940deg",
"1020deg",
"1080deg",
],
});
You can change the values to get the result you want
I did an example at the expo
Attaches a gif image
I want to create my own loader using animation, my idea is using scale to handle it, so the step should be like:
show an image scale from (n) to 1 for the first time
check if conditional is accepted or not
if conditional accepted, show an image scale from 1 to (n)
I can achieve 1st condition, but when i try 2nd and 3rd condition, the animation start in a blink of eye,
anyone can help me how to fix this?
here's the code i've tried:
//animation function
playAnimation(){
this.setState({onLoad:true})
this._load.setValue(0)
this._scale.setValue(0)
Animated.timing(this._load, {
toValue: 100,
useNativeDriver: true,
duration:1000
}).start(()=>{
setTimeout(() => {
Animated.timing(this._scale, {
toValue: 100,
useNativeDriver: true,
duration:1000
}).start(()=>this.setState({onLoad:false}));
}, 2000);
});
onLoad = this._load.interpolate({
inputRange: [0, 50, 75, 100],
outputRange: [10, 1, 1.4, 1],
})
imageScale = this._scale.interpolate({
inputRange: [20, 35, 70],
outputRange: [1.2, 1, 20],
})
}
//on render
<Animated.Image
style={{
resizeMode:'contain',
position:'absolute',
zIndex:1,
width:width/2,
height:200,
transform:[{scale:this.state.onLoad?onLoad:imageScale}]
}}
source={{uri: "https://www.knittedhome.com/communities/5/004/012/872/235/images/4628207884.jpg"}}
/>
and the result:
How your code works right now is somewhere in your code, you're calling PlayAnimation().
PlayAnimation() will:
start and complete first animation
Wait 2 sec
start and complete second animation
What you're doing in your Animated.Image is setting the transforms to different values. This doesn't start or stop the animation, just tells Animated.Image what value to set transform to.
What you should do
Use one Animated.Value to keep track of the scale. Assign that value to the Animated.Image transform.
Write two Animation functions:
scaleDown, call this where you're currently calling PlayAnimation
scaleUp, use your onLoad conditional to execute this in render or somewhere appropriate.
How to create border in Header? I am using jspdf autotable to create table but cannot find any idea to apply border to header. Is there any hook that can be used to create header border?
You can use the header styles:
doc.autotable(columns, data, {
headerStyles: {
lineWidth: 1,
lineColor: [255, 0, 0]
}
});
As of today (version 3.5.25) the property name is headStyles and still different border widths is not supported.
Example:
autoTable(doc, {
headStyles: {
lineWidth: 0.5, // 1 is too thick for me
lineColor: [255, 0, 0] // Or gray level single value from 0-255
}
})
I use the imported method version (autoTable) in TypeScript.
http://legacy.datatables.net/ref
I am running an older version of DataTables, which so far has proven satisfactory for my needs. I have found the answer I am seeking, but just don't know WHERE?? the file is located within DataTables folder structure ???? - ( I want to make changes to the default # of records shown )
aLengthMenu
`[!$(document).ready( function() {
$('#example').dataTable( {
"aLengthMenu": [[10, 25, 50, -1], [10, 25, 50, "All"]]
} );
} );
// Setting the default display length as well as length menu
// This is likely to be wanted if you remove the '10' option which
// is the iDisplayLength default.
$(document).ready( function() {
$('#example').dataTable( {
"iDisplayLength": 25,
"aLengthMenu": [[25, 50, 100, -1], [25, 50, 100, "All"]]
} );
} );`
Any suggestions as to where this piece of code is located so I can change it?
Thank you in advance
Short answer: don't.
If you change the source code for a plugin, you lock yourself into either changing the source code every time the plugin gets updated or forcing yourself to use an outdated library/plugin.
Like most jquery plugins, you can change the defaults when the page loads before the pluging is used. I actually put all my defaults in a single file that I load after the other files load.
<script src='pathtojquery.js'></script>
<script src='pathtojqueryUI.js></script>
<script src='pathtoDatatables.js></script>
<script src='pathtoMyDefaults.js></script>
in pathtoMyDefaults.js, I have this line, among others:
$.fn.dataTable.defaults.aLengthMenu = [[5, 8, 10, 15, 20, 30, 50, 75, -1], [5, 8, 10, 15, 20, 30, 50, 75, "All"]];
You can examine $.fn.dataTable.defaults with a javascript debugger to see all of the defaults.
then in my code I just have to do this:
$(document).ready(function(){
$("#tblSelector").DataTable({stuff:"stuff",
// if page length is not included, or does not match what is in the array, it defaults to the last one in the array.
pageLength: 8,
moreStuff:"moreStuff"
} )
});
I am interested in making a bar chart that changes over time (ideally bars will move up and down smoothly to show data changes over time). I didn't expect it would be difficult but, maybe due to the way I am searching, I cannot find a pre-built component or library that does this. I have come across other animated graphs that show data changes over time (like https://developers.google.com/chart/interactive/docs/gallery/motionchart and http://www.highcharts.com/demo/dynamic-update) but nothing that does what I describe in a bar chart. It would also work if I could find a line chart or pie chart that smoothly changed over time but I would rather make a bar chart to do this if possible.
Does an application or component or library like this exist (and if so can you point me in the right direction)? If for some reason nothing like this is available, what is the closest thing to it available (what is the path that would require the least amount of effort to produce this chart)?
ZingChart should be able to do this for you, and it's super easy to use. The chart configuration is defined using a JSON object. Inside the plot object, the animation object can hold a number of different animation options, including effect, speed, delay, and sequence. More information on ZingChart's animation effects can be found here. The render method is called to tell ZingChart where to render the chart using a div's unique ID. For this example, I configured a function to be called every 3000 milliseconds, generating a random array of numbers between 0 and 100, using the setseriesvalues method to change the data at plotindex 0.
var oData = {
"type": "bar",
"scaleY": {
"values": "0:100:10"
},
"plot": {
"animation": {
"effect": "ANIMATION_SLIDE_BOTTOM"
}
},
"series": [{
"values": [69, 68, 54, 48, 70, 74, 98, 70, 72, 68, 49, 69]
}]
};
zingchart.render({
id: 'myChartDiv',
width: 600,
height: 400,
data: oData
});
setInterval(function() {
var aValues = [];
for (var n = 0; n < 12; n++) {
var num = Math.random() * (100 - 0) + 0;
aValues.push(num);
}
console.log(aValues);
zingchart.exec('myChartDiv', 'setseriesvalues', {
plotindex: 0,
values: aValues
});
}, 3000);
<script src="http://cdn.zingchart.com/zingchart.min.js"></script>
<div id="myChartDiv"></div>
Full disclaimer: I'm on the ZingChart team, but if there's anything else I can help you with, I'd be happy to help!